Class SyncModernMcpToolMethodCallback
java.lang.Object
org.springframework.ai.mcp.annotation.method.tool.AbstractMcpToolMethodCallback<T,RC>
org.springframework.ai.mcp.annotation.method.tool.AbstractAsyncMcpToolMethodCallback<T,RC>
org.springframework.ai.mcp.annotation.method.tool.AbstractSyncMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpSyncRequestContext>
org.springframework.ai.mcp.annotation.method.tool.SyncModernMcpToolMethodCallback
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpSyncTool.Handler
public final class SyncModernMcpToolMethodCallback
extends AbstractSyncMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpSyncRequestContext>
implements io.modelcontextprotocol.modern.server.feature.McpSyncTool.Handler
Serves a
tools/call of a 2026-07-28 ("modern") MCP server by invoking a method
annotated with @McpTool.
Beyond the parameters the legacy callbacks support, a method may declare
McpModernSyncRequestContext, the SDK McpRequestContext,
McpSyncNotifier 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 modern McpSchema.CallToolOutcome (a CallToolResult or an
InputRequiredResult) or any of the legacy return types, which are converted.
- 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
ConstructorsConstructorDescriptionSyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject) SyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, @Nullable io.modelcontextprotocol.json.McpJsonMapper jsonMapper) -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.modern.server.McpSyncResponse<io.modelcontextprotocol.modern.McpSchema.CallToolOutcome>call(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.CallToolRequest request) protected McpSyncRequestContextcreateRequestContext(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.AbstractSyncMcpToolMethodCallback
createSyncErrorResult, processResult, validateSyncRequestMethods 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
-
SyncModernMcpToolMethodCallback
-
SyncModernMcpToolMethodCallback
public SyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, @Nullable io.modelcontextprotocol.json.McpJsonMapper jsonMapper) - Parameters:
jsonMapper- the mapper thatMcpModernSyncRequestContext.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,McpSyncRequestContext> - Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is an exchange or context type, false otherwise
-
createRequestContext
protected McpSyncRequestContext createRequestContext(io.modelcontextprotocol.modern.server.McpRequestContext exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) - Specified by:
createRequestContextin classAbstractMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpSyncRequestContext>
-
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,McpSyncRequestContext> - Parameters:
context- The exchange or context object- Returns:
- The resolved McpTransportContext
-
call
public io.modelcontextprotocol.modern.server.McpSyncResponse<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.McpSyncTool.Handler
-