Class McpToolset

java.lang.Object
com.google.adk.tools.mcp.McpToolset
All Implemented Interfaces:
AutoCloseable

public class McpToolset extends Object implements AutoCloseable
Connects to a MCP Server, and retrieves MCP Tools into ADK Tools.

Attributes:

  • connectionParams: The connection parameters to the MCP server. Can be either ServerParameters or SseServerParameters.
  • exit_stack: (Python concept) The async exit stack to manage the connection to the MCP server. In Java, this is implicitly handled by McpToolset implementing AutoCloseable.
  • session: The MCP session being initialized with the connection.
  • Constructor Details

    • McpToolset

      public McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Initializes the McpToolset with SSE server parameters.
      Parameters:
      connectionParams - The SSE connection parameters to the MCP server.
      objectMapper - An ObjectMapper instance for parsing schemas.
    • McpToolset

      public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Initializes the McpToolset with local server parameters.
      Parameters:
      connectionParams - The local server connection parameters to the MCP server.
      objectMapper - An ObjectMapper instance for parsing schemas.
    • McpToolset

      public McpToolset(SseServerParameters connectionParams)
      Initializes the McpToolset with SSE server parameters, using the ObjectMapper used across the ADK.
      Parameters:
      connectionParams - The SSE connection parameters to the MCP server.
    • McpToolset

      public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams)
      Initializes the McpToolset with local server parameters, using the ObjectMapper used across the ADK.
      Parameters:
      connectionParams - The local server connection parameters to the MCP server.
  • Method Details

    • fromServer

      public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Retrieve all tools from the MCP connection using SSE server parameters.
      Parameters:
      connectionParams - The SSE connection parameters to the MCP server.
      objectMapper - An ObjectMapper instance for parsing schemas.
      Returns:
      A CompletableFuture of McpToolsAndToolsetResult.
    • fromServer

      public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Retrieve all tools from the MCP connection using local server parameters.
      Parameters:
      connectionParams - The local server connection parameters to the MCP server.
      objectMapper - An ObjectMapper instance for parsing schemas.
      Returns:
      A CompletableFuture of McpToolsAndToolsetResult.
    • fromServer

      public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(SseServerParameters connectionParams)
      Retrieve all tools from the MCP connection using SSE server parameters and the ObjectMapper used across the ADK.
      Parameters:
      connectionParams - The SSE connection parameters to the MCP server.
      Returns:
      A CompletableFuture of McpToolsAndToolsetResult.
    • fromServer

      public static CompletableFuture<McpToolset.McpToolsAndToolsetResult> fromServer(io.modelcontextprotocol.client.transport.ServerParameters connectionParams)
      Retrieve all tools from the MCP connection using local server parameters and the ObjectMapper used across the ADK.
      Parameters:
      connectionParams - The local server connection parameters to the MCP server.
      Returns:
      A CompletableFuture of McpToolsAndToolsetResult.
    • loadTools

      public CompletableFuture<List<McpTool>> loadTools()
      Loads all tools from the MCP Server. This method includes retry logic in case of transient session issues.
      Returns:
      A CompletableFuture that completes with a list of McpTools imported from the MCP Server.
    • close

      public void close()
      Closes the connection to MCP Server. This method is part of the AutoCloseable interface, allowing McpToolset to be used in a try-with-resources statement for automatic resource management.
      Specified by:
      close in interface AutoCloseable