Class SyncStatelessMcpToolMethodCallback

java.lang.Object
org.springframework.ai.mcp.annotation.method.tool.AbstractMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpSyncRequestContext>
org.springframework.ai.mcp.annotation.method.tool.AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpSyncRequestContext>
org.springframework.ai.mcp.annotation.method.tool.AbstractSyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpSyncRequestContext>
org.springframework.ai.mcp.annotation.method.tool.SyncStatelessMcpToolMethodCallback
All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,io.modelcontextprotocol.spec.McpSchema.CallToolResult>

public final class SyncStatelessMcpToolMethodCallback extends AbstractSyncMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpSyncRequestContext> implements BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,io.modelcontextprotocol.spec.McpSchema.CallToolResult>
Class for creating Function callbacks around tool methods. This class provides a way to convert methods annotated with McpTool into callback functions that can be used to handle tool requests.
Author:
James Ward, Christian Tzolov
  • Constructor Details

    • SyncStatelessMcpToolMethodCallback

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

      public SyncStatelessMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, Class<? extends Throwable> toolCallExceptionClass)
  • Method Details

    • 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.common.McpTransportContext,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.common.McpTransportContext exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Specified by:
      createRequestContext in class AbstractMcpToolMethodCallback<io.modelcontextprotocol.common.McpTransportContext,McpSyncRequestContext>
    • resolveTransportContext

      protected io.modelcontextprotocol.common.McpTransportContext resolveTransportContext(io.modelcontextprotocol.common.McpTransportContext 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.common.McpTransportContext,McpSyncRequestContext>
      Parameters:
      context - The exchange or context object
      Returns:
      The resolved McpTransportContext
    • apply

      public io.modelcontextprotocol.spec.McpSchema.CallToolResult apply(io.modelcontextprotocol.common.McpTransportContext mcpTransportContext, io.modelcontextprotocol.spec.McpSchema.CallToolRequest callToolRequest)
      Specified by:
      apply in interface BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,io.modelcontextprotocol.spec.McpSchema.CallToolResult>