Class McpAsyncTool

java.lang.Object
com.google.adk.tools.BaseTool
com.google.adk.tools.mcp.McpAsyncTool

public final class McpAsyncTool extends BaseTool
Initializes a MCP tool.

This wraps a MCP Tool interface and an active MCP Session. It invokes the MCP Tool through executing the tool from remote MCP Session.

  • Constructor Details

    • McpAsyncTool

      public McpAsyncTool(io.modelcontextprotocol.spec.McpSchema.Tool mcpTool, io.modelcontextprotocol.client.McpAsyncClient mcpSession, McpSessionManager mcpSessionManager)
      Creates a new McpAsyncTool with the default ObjectMapper.
      Parameters:
      mcpTool - The MCP tool to wrap.
      mcpSession - The MCP session to use to call the tool.
      mcpSessionManager - The MCP session manager to use to create new sessions.
      Throws:
      IllegalArgumentException - If mcpTool or mcpSession are null.
    • McpAsyncTool

      public McpAsyncTool(io.modelcontextprotocol.spec.McpSchema.Tool mcpTool, io.modelcontextprotocol.client.McpAsyncClient mcpSession, McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates a new McpAsyncTool
      Parameters:
      mcpTool - The MCP tool to wrap.
      mcpSession - The MCP session to use to call the tool.
      mcpSessionManager - The MCP session manager to use to create new sessions.
      objectMapper - The ObjectMapper to use to convert JSON schemas.
      Throws:
      IllegalArgumentException - If mcpTool or mcpSession are null.
  • Method Details

    • getMcpSession

      public io.modelcontextprotocol.client.McpAsyncClient getMcpSession()
    • toGeminiSchema

      public com.google.genai.types.Schema toGeminiSchema(io.modelcontextprotocol.spec.McpSchema.JsonSchema openApiSchema)
    • declaration

      public Optional<com.google.genai.types.FunctionDeclaration> declaration()
      Description copied from class: BaseTool
      Gets the FunctionDeclaration representation of this tool.
      Overrides:
      declaration in class BaseTool
    • runAsync

      public io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(Map<String,Object> args, ToolContext toolContext)
      Description copied from class: BaseTool
      Calls a tool.
      Overrides:
      runAsync in class BaseTool