Class AsyncMcpToolCallback

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

public class AsyncMcpToolCallback extends Object implements ToolCallback
Adapts MCP tools to Spring AI's ToolCallback interface with asynchronous execution.

Bridges Model Context Protocol (MCP) tools with Spring AI's tool system, enabling seamless integration of MCP tools in Spring AI applications.

Author:
Christian Tzolov, YunKui Lu
  • Constructor Details

    • AsyncMcpToolCallback

      @Deprecated public AsyncMcpToolCallback(io.modelcontextprotocol.client.McpAsyncClient mcpClient, io.modelcontextprotocol.spec.McpSchema.Tool tool)
      Deprecated.
      Creates an AsyncMcpToolCallback with default prefixed tool name.
      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()
    • 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 AsyncMcpToolCallback.Builder builder()
      Creates a builder for constructing AsyncMcpToolCallback instances.
      Returns:
      a new builder