Class AsyncModernMcpToolMethodCallback
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpAsyncTool.Handler
SyncModernMcpToolMethodCallback: serves a
tools/call of a 2026-07-28 ("modern") MCP server by invoking a method annotated
with @McpTool.
A method may declare McpModernRequestContext, the SDK
McpRequestContext, McpAsyncNotifier or the modern
McpSchema.CallToolRequest (which carries the MRTR fields). A method that declares the
notifier is served as a streaming response so that progress notifications can be pushed
before the result; the context alone leaves the response a plain result.
The method may return a Mono, a CompletionStage or a Publisher
of a modern McpSchema.CallToolOutcome or of any legacy return type, which is converted. A
declared Flux is rejected at startup, and a publisher that emits more than one
element fails the call; see ModernReactiveSupport. A plain, blocking return
value is accepted too: the method then runs through
McpModernAsyncUtils.fromBlocking(io.modelcontextprotocol.modern.server.McpRequestContext, java.util.concurrent.Callable<T>), on the calling thread when the request is
served blocking and on boundedElastic otherwise.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.ai.mcp.annotation.method.tool.AbstractAsyncMcpToolMethodCallback
toolCallExceptionClassFields inherited from class org.springframework.ai.mcp.annotation.method.tool.AbstractMcpToolMethodCallback
returnMode, toolMethod, toolObject -
Constructor Summary
ConstructorsConstructorDescriptionAsyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject) AsyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, @Nullable io.modelcontextprotocol.json.McpJsonMapper jsonMapper) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.McpAsyncResponse<io.modelcontextprotocol.modern.McpSchema.CallToolOutcome>>call(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.CallToolRequest request) protected McpAsyncRequestContextcreateRequestContext(io.modelcontextprotocol.modern.server.McpRequestContext 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.static booleanisModernInfrastructureParameter(Class<?> parameterType) Whether a parameter of this type is injected by the modern callback rather than bound from the tool arguments.booleanstatic booleanisStreamingParameter(Class<?> parameterType) Whether a parameter of this type makes the call a streaming response.protected io.modelcontextprotocol.common.McpTransportContextresolveTransportContext(io.modelcontextprotocol.modern.server.McpRequestContext context) Resolves theMcpTransportContextfrom the exchange or context object.Methods inherited from class org.springframework.ai.mcp.annotation.method.tool.AbstractAsyncMcpToolMethodCallback
convertToCallToolResult, createAsyncErrorResult, mapValueToCallToolResult, validateRequestMethods inherited from class org.springframework.ai.mcp.annotation.method.tool.AbstractMcpToolMethodCallback
buildMethodArguments, buildTypedArgument, callMethod, convertValueToCallToolResult, createErrorMessage, findCauseUsingPlainJava
-
Constructor Details
-
AsyncModernMcpToolMethodCallback
public AsyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject) -
AsyncModernMcpToolMethodCallback
public AsyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, @Nullable io.modelcontextprotocol.json.McpJsonMapper jsonMapper) - Parameters:
jsonMapper- the mapper thatMcpModernRequestContext.inputResponseconverts with, normally the server's, or null for the SDK default
-
-
Method Details
-
isStreamingParameter
Whether a parameter of this type makes the call a streaming response. -
isModernInfrastructureParameter
Whether a parameter of this type is injected by the modern callback rather than bound from the tool arguments. -
isStreaming
public boolean isStreaming() -
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.modern.server.McpRequestContext,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.modern.server.McpRequestContext exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) - Specified by:
createRequestContextin classAbstractMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpAsyncRequestContext>
-
resolveTransportContext
protected io.modelcontextprotocol.common.McpTransportContext resolveTransportContext(io.modelcontextprotocol.modern.server.McpRequestContext context) Description copied from class:AbstractMcpToolMethodCallbackResolves theMcpTransportContextfrom the exchange or context object. Subclasses must implement this method to extract or return the transport context appropriately based on the type of the exchange parameter.- Specified by:
resolveTransportContextin classAbstractMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpAsyncRequestContext> - Parameters:
context- The exchange or context object- Returns:
- The resolved McpTransportContext
-
call
public reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.McpAsyncResponse<io.modelcontextprotocol.modern.McpSchema.CallToolOutcome>> call(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.CallToolRequest request) - Specified by:
callin interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncTool.Handler
-