Class AbstractMcpCompleteMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
- Direct Known Subclasses:
AsyncMcpCompleteMethodCallback,AsyncStatelessMcpCompleteMethodCallback,SyncMcpCompleteMethodCallback,SyncStatelessMcpCompleteMethodCallback
Abstract base class for creating callbacks around complete methods.
This class provides common functionality for both synchronous and asynchronous complete
method callbacks. It contains shared logic for method validation, argument building,
and other common operations.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAbstractMcpCompleteMethodCallback.AbstractBuilder<T extends AbstractMcpCompleteMethodCallback.AbstractBuilder<T,R>, R> Abstract builder for creating McpCompleteMethodCallback instances.static classException thrown when there is an error invoking a complete method. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMcpCompleteMethodCallback(Method method, Object bean, String prompt, String uri, io.modelcontextprotocol.util.McpUriTemplateManagerFactory uriTemplateManagerFactory) Constructor for AbstractMcpCompleteMethodCallback. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object[]buildArgs(Method method, Object exchange, io.modelcontextprotocol.spec.McpSchema.CompleteRequest request) Builds the arguments array for invoking the method.protected abstract booleanisExchangeType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.protected voidvalidateMethod(Method method) Validates that the method signature is compatible with the complete callback.protected voidvalidateParameters(Method method) Validates method parameters.protected abstract voidvalidateReturnType(Method method) Validates that the method return type is compatible with the complete callback.
-
Field Details
-
method
-
bean
-
prompt
-
uri
-
completeReference
protected final io.modelcontextprotocol.spec.McpSchema.CompleteReference completeReference -
uriVariables
-
uriTemplateManager
protected final io.modelcontextprotocol.util.McpUriTemplateManager uriTemplateManager
-
-
Constructor Details
-
AbstractMcpCompleteMethodCallback
protected AbstractMcpCompleteMethodCallback(Method method, Object bean, String prompt, String uri, io.modelcontextprotocol.util.McpUriTemplateManagerFactory uriTemplateManagerFactory) Constructor for AbstractMcpCompleteMethodCallback.- Parameters:
method- The method to create a callback forbean- The bean instance that contains the methodprompt- The prompt referenceuri- The URI referenceuriTemplateManagerFactory- The URI template manager factory
-
-
Method Details
-
validateMethod
Validates that the method signature is compatible with the complete callback.This method checks that the return type is valid and that the parameters match the expected pattern.
- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the method signature is not compatible
-
validateReturnType
Validates that the method return type is compatible with the complete callback. This method should be implemented by subclasses to handle specific return type validation.- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the return type is not compatible
-
validateParameters
Validates method parameters. This method provides common validation logic and delegates exchange type checking to subclasses.- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the parameters are not compatible
-
buildArgs
protected Object[] buildArgs(Method method, Object exchange, io.modelcontextprotocol.spec.McpSchema.CompleteRequest request) Builds the arguments array for invoking the method.This method constructs an array of arguments based on the method's parameter types and the available values (exchange, request, argument).
- Parameters:
method- The method to build arguments forexchange- The server exchangerequest- The complete request- Returns:
- An array of arguments for the method invocation
-
isExchangeType
Checks if a parameter type is compatible with the exchange type. This method should be implemented by subclasses to handle specific exchange type checking.- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-