Class SyncStatelessMcpPromptMethodCallback
java.lang.Object
org.springframework.ai.mcp.annotation.method.prompt.AbstractMcpPromptMethodCallback
org.springframework.ai.mcp.annotation.method.prompt.SyncStatelessMcpPromptMethodCallback
- All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest, io.modelcontextprotocol.spec.McpSchema.GetPromptResult>
public final class SyncStatelessMcpPromptMethodCallback
extends AbstractMcpPromptMethodCallback
implements BiFunction<io.modelcontextprotocol.common.McpTransportContext, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest, io.modelcontextprotocol.spec.McpSchema.GetPromptResult>
Class for creating BiFunction callbacks around prompt methods for stateless contexts.
This class provides a way to convert methods annotated with
McpPrompt into
callback functions that can be used to handle prompt requests in stateless
environments. It supports various method signatures and return types.- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creating SyncStatelessMcpPromptMethodCallback instances.Nested classes/interfaces inherited from class AbstractMcpPromptMethodCallback
AbstractMcpPromptMethodCallback.AbstractBuilder<B,T> -
Field Summary
Fields inherited from class AbstractMcpPromptMethodCallback
bean, method, prompt -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.spec.McpSchema.GetPromptResultapply(io.modelcontextprotocol.common.McpTransportContext context, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest request) Apply the callback to the given context and request.protected ObjectassignExchangeType(Class<?> paramType, Object exchange) builder()Create a new builder.protected booleanisSupportedExchangeOrContextType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.protected voidvalidateParamType(Class<?> paramType) protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the prompt callback.Methods inherited from class AbstractMcpPromptMethodCallback
buildArgs, convertArgumentValue, convertToGetPromptResult, validateMethod, validateParametersMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThen
-
Method Details
-
validateParamType
- Overrides:
validateParamTypein classAbstractMcpPromptMethodCallback
-
assignExchangeType
- Specified by:
assignExchangeTypein classAbstractMcpPromptMethodCallback
-
apply
public io.modelcontextprotocol.spec.McpSchema.GetPromptResult apply(io.modelcontextprotocol.common.McpTransportContext context, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest request) Apply the callback to the given context and request.This method builds the arguments for the method call, invokes the method, and converts the result to a GetPromptResult.
- Specified by:
applyin interfaceBiFunction<io.modelcontextprotocol.common.McpTransportContext, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest, io.modelcontextprotocol.spec.McpSchema.GetPromptResult>- Parameters:
context- The transport context, may be null if the method doesn't require itrequest- The prompt request, must not be null- Returns:
- The prompt result
-
isSupportedExchangeOrContextType
Description copied from class:AbstractMcpPromptMethodCallbackChecks if a parameter type is compatible with the exchange type.- Specified by:
isSupportedExchangeOrContextTypein classAbstractMcpPromptMethodCallback- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-
validateReturnType
Description copied from class:AbstractMcpPromptMethodCallbackValidates that the method return type is compatible with the prompt callback.- Specified by:
validateReturnTypein classAbstractMcpPromptMethodCallback- Parameters:
method- The method to validate
-
builder
Create a new builder.- Returns:
- A new builder instance
-