Class SyncMcpSamplingMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.sampling.AbstractMcpSamplingMethodCallback
org.springaicommunity.mcp.method.sampling.SyncMcpSamplingMethodCallback
- All Implemented Interfaces:
Function<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,io.modelcontextprotocol.spec.McpSchema.CreateMessageResult>
public final class SyncMcpSamplingMethodCallback
extends AbstractMcpSamplingMethodCallback
implements Function<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,io.modelcontextprotocol.spec.McpSchema.CreateMessageResult>
Class for creating Function callbacks around sampling methods.
This class provides a way to convert methods annotated with
McpSampling into
callback functions that can be used to handle sampling requests. It supports methods
with a single CreateMessageRequest parameter.- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating SyncMcpSamplingMethodCallback instances.Nested classes/interfaces inherited from class org.springaicommunity.mcp.method.sampling.AbstractMcpSamplingMethodCallback
AbstractMcpSamplingMethodCallback.AbstractBuilder<T extends AbstractMcpSamplingMethodCallback.AbstractBuilder<T,R>, R>, AbstractMcpSamplingMethodCallback.McpSamplingMethodException -
Field Summary
Fields inherited from class org.springaicommunity.mcp.method.sampling.AbstractMcpSamplingMethodCallback
bean, method -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.spec.McpSchema.CreateMessageResultapply(io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest request) Apply the callback to the given request.builder()Create a new builder.protected booleanisExchangeType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the sampling callback.Methods inherited from class org.springaicommunity.mcp.method.sampling.AbstractMcpSamplingMethodCallback
buildArgs, validateMethod, validateParameters
-
Method Details
-
apply
public io.modelcontextprotocol.spec.McpSchema.CreateMessageResult apply(io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest request) Apply the callback to the given request.This method builds the arguments for the method call, invokes the method, and returns the result.
- Specified by:
applyin interfaceFunction<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,io.modelcontextprotocol.spec.McpSchema.CreateMessageResult> - Parameters:
request- The sampling request, must not be null- Returns:
- The result of the method invocation
- Throws:
AbstractMcpSamplingMethodCallback.McpSamplingMethodException- if there is an error invoking the sampling methodIllegalArgumentException- if the request is null
-
validateReturnType
Validates that the method return type is compatible with the sampling callback.- Specified by:
validateReturnTypein classAbstractMcpSamplingMethodCallback- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the return type is not compatible
-
isExchangeType
Checks if a parameter type is compatible with the exchange type.- Specified by:
isExchangeTypein classAbstractMcpSamplingMethodCallback- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-
builder
Create a new builder.- Returns:
- A new builder instance
-