Class SyncMcpToolCallback

java.lang.Object
org.springframework.ai.mcp.SyncMcpToolCallback
All Implemented Interfaces:
ToolCallback

public class SyncMcpToolCallback extends Object implements ToolCallback
Synchronous adapter bridging MCP tools to Spring AI's ToolCallback interface. Handles tool execution and data conversion between MCP and Spring AI.
Since:
1.0.0
Author:
Christian Tzolov, YunKui Lu
  • Constructor Details

    • SyncMcpToolCallback

      @Deprecated public SyncMcpToolCallback(io.modelcontextprotocol.client.McpSyncClient mcpClient, io.modelcontextprotocol.spec.McpSchema.Tool tool)
      Deprecated.
      use builder() instead
      Creates a callback with default settings.
      Parameters:
      mcpClient - the MCP client for tool execution
      tool - the MCP tool to adapt
  • Method Details

    • getToolDefinition

      public ToolDefinition getToolDefinition()
      Description copied from interface: ToolCallback
      Definition used by the AI model to determine when and how to call the tool.
      Specified by:
      getToolDefinition in interface ToolCallback
    • getOriginalToolName

      public String getOriginalToolName()
      Returns the original MCP tool name without prefixing.
      Returns:
      the original tool name
    • call

      public String call(String toolCallInput)
      Description copied from interface: ToolCallback
      Execute tool with the given input and return the result to send back to the AI model.
      Specified by:
      call in interface ToolCallback
    • call

      public String call(String toolCallInput, @Nullable ToolContext toolContext)
      Description copied from interface: ToolCallback
      Execute tool with the given input and context, and return the result to send back to the AI model.
      Specified by:
      call in interface ToolCallback
    • builder

      public static SyncMcpToolCallback.Builder builder()
      Creates a builder for constructing SyncMcpToolCallback instances.
      Returns:
      a new builder