Class SyncStatelessMcpPromptMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
org.springaicommunity.mcp.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 classBuilder for creating SyncStatelessMcpPromptMethodCallback instances.Nested classes/interfaces inherited from class org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
AbstractMcpPromptMethodCallback.AbstractBuilder<B extends AbstractMcpPromptMethodCallback.AbstractBuilder<B,T>, T extends AbstractMcpPromptMethodCallback> -
Field Summary
Fields inherited from class org.springaicommunity.mcp.method.prompt.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 org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
buildArgs, convertArgumentValue, convertToGetPromptResult, validateMethod, validateParametersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.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
- Throws:
McpPromptMethodException- if there is an error invoking the prompt methodIllegalArgumentException- if the request is null
-
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
-