Class 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
  • Constructor Details

    • SyncModernMcpToolMethodCallback

      public SyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject)
    • SyncModernMcpToolMethodCallback

      public SyncModernMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, @Nullable io.modelcontextprotocol.json.McpJsonMapper jsonMapper)
      Parameters:
      jsonMapper - the mapper that McpModernSyncRequestContext.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,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:
      createRequestContext in class AbstractMcpToolMethodCallback<io.modelcontextprotocol.modern.server.McpRequestContext,McpSyncRequestContext>
    • 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,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:
      call in interface io.modelcontextprotocol.modern.server.feature.McpSyncTool.Handler