Class AsyncStatelessMcpToolMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback<T,RC>
org.springaicommunity.mcp.method.tool.AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpAsyncRequestContext>
org.springaicommunity.mcp.method.tool.AsyncStatelessMcpToolMethodCallback
- All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest, reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>>
public final class AsyncStatelessMcpToolMethodCallback
extends AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpAsyncRequestContext>
implements BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>>
Class for creating Function callbacks around async stateless tool methods.
This class provides a way to convert methods annotated with
McpTool into
callback functions that can be used to handle tool requests asynchronously in a
stateless manner using McpTransportContext.- Author:
- Christian Tzolov
-
Field Summary
Fields inherited from class org.springaicommunity.mcp.method.tool.AbstractAsyncMcpToolMethodCallback
toolCallExceptionClassFields inherited from class org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback
returnMode, toolMethod, toolObject -
Constructor Summary
ConstructorsConstructorDescriptionAsyncStatelessMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject) AsyncStatelessMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, Class<? extends Throwable> toolCallExceptionClass) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>apply(io.modelcontextprotocol.common.McpTransportContext mcpTransportContext, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) Apply the callback to the given request.protected McpAsyncRequestContextcreateRequestContext(io.modelcontextprotocol.common.McpTransportContext exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) protected booleanisExchangeOrContextType(Class<?> paramType) Determines if the given parameter type is an exchange or context type that should be injected.Methods inherited from class org.springaicommunity.mcp.method.tool.AbstractAsyncMcpToolMethodCallback
convertToCallToolResult, createAsyncErrorResult, mapValueToCallToolResult, validateRequestMethods inherited from class org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback
buildMethodArguments, buildTypedArgument, callMethod, convertValueToCallToolResult, createErrorMessage, findCauseUsingPlainJavaMethods 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
-
Constructor Details
-
AsyncStatelessMcpToolMethodCallback
public AsyncStatelessMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject) -
AsyncStatelessMcpToolMethodCallback
public AsyncStatelessMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, Class<? extends Throwable> toolCallExceptionClass)
-
-
Method Details
-
isExchangeOrContextType
Description copied from class:AbstractAsyncMcpToolMethodCallbackDetermines if the given parameter type is an exchange or context type that should be injected. Subclasses must implement this method to specify which types are considered exchange or context types.- Specified by:
isExchangeOrContextTypein classAbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpAsyncRequestContext> - Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is an exchange or context type, false otherwise
-
createRequestContext
protected McpAsyncRequestContext createRequestContext(io.modelcontextprotocol.common.McpTransportContext exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) - Specified by:
createRequestContextin classAbstractMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpAsyncRequestContext>
-
apply
public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> apply(io.modelcontextprotocol.common.McpTransportContext mcpTransportContext, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) Apply the callback to the given request.This method builds the arguments for the method call, invokes the method, and returns the result asynchronously.
- Specified by:
applyin interfaceBiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest, reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>> - Parameters:
mcpTransportContext- The transport contextrequest- The tool call request, must not be null- Returns:
- A Mono containing the result of the method invocation
-