Class AbstractMcpPromptMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
- Direct Known Subclasses:
AsyncMcpPromptMethodCallback,AsyncStatelessMcpPromptMethodCallback,SyncMcpPromptMethodCallback,SyncStatelessMcpPromptMethodCallback
Abstract base class for creating callbacks around prompt methods.
This class provides common functionality for both synchronous and asynchronous prompt
method callbacks.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAbstractMcpPromptMethodCallback.AbstractBuilder<B extends AbstractMcpPromptMethodCallback.AbstractBuilder<B,T>, T extends AbstractMcpPromptMethodCallback> Abstract builder for creating prompt method callback instances. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMcpPromptMethodCallback(Method method, Object bean, io.modelcontextprotocol.spec.McpSchema.Prompt prompt) Constructor for AbstractMcpPromptMethodCallback. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ObjectassignExchangeType(Class<?> paramType, Object exchange) protected Object[]buildArgs(Method method, Object exchange, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest request) Builds the arguments array for invoking the method.protected ObjectconvertArgumentValue(Object value, Class<?> targetType) Converts an argument value to the expected parameter type.protected io.modelcontextprotocol.spec.McpSchema.GetPromptResultconvertToGetPromptResult(Object result) Converts a method result to a GetPromptResult.protected abstract booleanisSupportedExchangeOrContextType(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 prompt callback.protected voidvalidateParameters(Method method) Validates method parameters.protected voidvalidateParamType(Class<?> paramType) protected abstract voidvalidateReturnType(Method method) Validates that the method return type is compatible with the prompt callback.
-
Field Details
-
method
-
bean
-
prompt
protected final io.modelcontextprotocol.spec.McpSchema.Prompt prompt
-
-
Constructor Details
-
AbstractMcpPromptMethodCallback
protected AbstractMcpPromptMethodCallback(Method method, Object bean, io.modelcontextprotocol.spec.McpSchema.Prompt prompt) Constructor for AbstractMcpPromptMethodCallback.- Parameters:
method- The method to create a callback forbean- The bean instance that contains the methodprompt- The prompt
-
-
Method Details
-
validateMethod
Validates that the method signature is compatible with the prompt callback.- 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 prompt callback.- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the return type is not compatible
-
isSupportedExchangeOrContextType
Checks if a parameter type is compatible with the exchange type.- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-
validateParamType
-
validateParameters
Validates method parameters.- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the parameters are not compatible
-
assignExchangeType
-
buildArgs
protected Object[] buildArgs(Method method, Object exchange, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest 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, arguments).
- Parameters:
method- The method to build arguments forexchange- The server exchangerequest- The prompt request- Returns:
- An array of arguments for the method invocation
-
convertArgumentValue
Converts an argument value to the expected parameter type.- Parameters:
value- The value to converttargetType- The target type- Returns:
- The converted value
-
convertToGetPromptResult
protected io.modelcontextprotocol.spec.McpSchema.GetPromptResult convertToGetPromptResult(Object result) Converts a method result to a GetPromptResult.- Parameters:
result- The result to convert- Returns:
- The converted GetPromptResult
-