Class AsyncModernMcpToolMethodCallback

java.lang.Object
org.springframework.ai.mcp.annotation.method.tool.AbstractMcpToolMethodCallback<T,RC>
org.springframework.ai.mcp.annotation.method.tool.AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpAsyncRequestContext>
org.springframework.ai.mcp.annotation.method.tool.AsyncModernMcpToolMethodCallback
All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpAsyncTool.Handler

public final class AsyncModernMcpToolMethodCallback extends AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpAsyncRequestContext> implements io.modelcontextprotocol.modern.server.feature.McpAsyncTool.Handler
The asynchronous twin of 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
  • 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 that McpModernRequestContext.inputResponse converts with, normally the server's, or null for the SDK default
  • Method Details

    • isStreamingParameter

      public static boolean isStreamingParameter(Class<?> parameterType)
      Whether a parameter of this type makes the call a streaming response.
    • isModernInfrastructureParameter

      public static boolean isModernInfrastructureParameter(Class<?> parameterType)
      Whether a parameter of this type is injected by the modern callback rather than bound from the tool arguments.
    • isStreaming

      public boolean isStreaming()
    • isExchangeOrContextType

      protected boolean isExchangeOrContextType(Class<?> paramType)
      Description copied from class: AbstractAsyncMcpToolMethodCallback
      Determines 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:
      isExchangeOrContextType in class AbstractAsyncMcpToolMethodCallback<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:
      createRequestContext in class AbstractMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpAsyncRequestContext>
    • resolveTransportContext

      protected io.modelcontextprotocol.common.McpTransportContext resolveTransportContext(io.modelcontextprotocol.modern.server.McpRequestContext context)
      Description copied from class: AbstractMcpToolMethodCallback
      Resolves the McpTransportContext from 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:
      resolveTransportContext in class AbstractMcpToolMethodCallback<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:
      call in interface io.modelcontextprotocol.modern.server.feature.McpAsyncTool.Handler