# Class McpToolset

java.lang.Object
com.google.adk.tools.mcp.McpToolset

All Implemented Interfaces:
  `BaseToolset, AutoCloseable`

public class McpToolset extends Object implements BaseToolset
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`.
- `session`: The MCP session being initialized with the connection.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `McpToolset.McpToolsetConfig`
  Configuration class for MCPToolset.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final Class<? extends McpToolset.McpToolsetConfig>`
  `CONFIG_TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper)`
  Initializes the McpToolset with an McpSessionManager and no tool filter.
  `McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)`
  Initializes the McpToolset with an McpSessionManager.
  `McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)`
  Initializes the McpToolset with an McpSessionManager.
  `McpToolset(SseServerParameters connectionParams)`
  Initializes the McpToolset with SSE server parameters, using the ObjectMapper used across the ADK and no tool filter.
  `McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)`
  Initializes the McpToolset with SSE server parameters and no tool filter.
  `McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)`
  Initializes the McpToolset with SSE server parameters.
  `McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)`
  Initializes the McpToolset with SSE server parameters.
  `McpToolset(StreamableHttpServerParameters connectionParams)`
  Initializes the McpToolset with Streamable HTTP server parameters, using the ObjectMapper used across the ADK and no tool filter.
  `McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)`
  Initializes the McpToolset with Streamable HTTP server parameters and no tool filter.
  `McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)`
  Initializes the McpToolset with Streamable HTTP server parameters.
  `McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)`
  Initializes the McpToolset with Streamable HTTP server parameters.
  `McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams)`
  Initializes the McpToolset with local server parameters, using the ObjectMapper used across the ADK and no tool filter.
  `McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)`
  Initializes the McpToolset with local server parameters and no tool filter.
  `McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)`
  Initializes the McpToolset with local server parameters.
  `McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)`
  Initializes the McpToolset with local server parameters.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Performs cleanup and releases resources held by the toolset.
  `static McpToolset`
  `fromConfig(BaseTool.ToolConfig config, String configAbsPath)`
  Creates a McpToolset instance from a config.
  `io.reactivex.rxjava3.core.Flowable<BaseTool>`
  `getTools(ReadonlyContext readonlyContext)`
  Return all tools in the toolset based on the provided context.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface BaseToolset

  `isToolSelected`
  Modifier and Type
  Method
  Description
  `default boolean`
  `isToolSelected(BaseTool tool, @Nullable Object toolFilter, @Nullable ReadonlyContext readonlyContext)`
  Checks if a tool should be selected based on a filter.

- ## Field Details

  - ### CONFIG_TYPE

    protected static final Class<? extends McpToolset.McpToolsetConfig> CONFIG_TYPE

- ## Constructor Details

  - ### McpToolset

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

  - ### McpToolset

    public McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)
    Initializes the McpToolset with SSE server parameters.
    Parameters:
      `connectionParams` - The SSE connection parameters to the MCP server.
      `objectMapper` - An ObjectMapper instance for parsing schemas.
      `toolNames` - A list of tool names

  - ### McpToolset

    public McpToolset(SseServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Initializes the McpToolset with SSE server parameters and no tool filter.
    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, ToolPredicate toolPredicate)
    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.
      `toolPredicate` - A `ToolPredicate`

  - ### McpToolset

    public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)
    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.
      `toolNames` - A list of tool names

  - ### McpToolset

    public McpToolset(io.modelcontextprotocol.client.transport.ServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Initializes the McpToolset with local server parameters and no tool filter.
    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 and no tool filter.
    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 and no tool filter.
    Parameters:
      `connectionParams` - The local server connection parameters to the MCP server.

  - ### McpToolset

    public McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)
    Initializes the McpToolset with an McpSessionManager.
    Parameters:
      `mcpSessionManager` - A McpSessionManager instance for testing.
      `objectMapper` - An ObjectMapper instance for parsing schemas.
      `toolPredicate` - A `ToolPredicate`

  - ### McpToolset

    public McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)
    Initializes the McpToolset with an McpSessionManager.
    Parameters:
      `mcpSessionManager` - A McpSessionManager instance for testing.
      `objectMapper` - An ObjectMapper instance for parsing schemas.
      `toolNames` - A list of tool names

  - ### McpToolset

    public McpToolset(McpSessionManager mcpSessionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Initializes the McpToolset with an McpSessionManager and no tool filter.
    Parameters:
      `mcpSessionManager` - A McpSessionManager instance for testing.
      `objectMapper` - An ObjectMapper instance for parsing schemas.

  - ### McpToolset

    public McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ToolPredicate toolPredicate)
    Initializes the McpToolset with Streamable HTTP server parameters.
    Parameters:
      `connectionParams` - The Streamable HTTP connection parameters to the MCP server.
      `objectMapper` - An ObjectMapper instance for parsing schemas.
      `toolPredicate` - A `ToolPredicate`

  - ### McpToolset

    public McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<String> toolNames)
    Initializes the McpToolset with Streamable HTTP server parameters.
    Parameters:
      `connectionParams` - The Streamable HTTP connection parameters to the MCP server.
      `objectMapper` - An ObjectMapper instance for parsing schemas.
      `toolNames` - A list of tool names

  - ### McpToolset

    public McpToolset(StreamableHttpServerParameters connectionParams, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Initializes the McpToolset with Streamable HTTP server parameters and no tool filter.
    Parameters:
      `connectionParams` - The Streamable HTTP connection parameters to the MCP server.
      `objectMapper` - An ObjectMapper instance for parsing schemas.

  - ### McpToolset

    public McpToolset(StreamableHttpServerParameters connectionParams)
    Initializes the McpToolset with Streamable HTTP server parameters, using the ObjectMapper used across the ADK and no tool filter.
    Parameters:
      `connectionParams` - The Streamable HTTP connection parameters to the MCP server.

- ## Method Details

  - ### getTools

    public io.reactivex.rxjava3.core.Flowable<BaseTool> getTools(ReadonlyContext readonlyContext)
    Description copied from interface: `BaseToolset`
    Return all tools in the toolset based on the provided context.
    Specified by:
      `getTools` in interface `BaseToolset`
    Parameters:
      `readonlyContext` - Context used to filter tools available to the agent.
    Returns:
      A Single emitting a list of tools available under the specified context.

  - ### close

    public void close()
    Description copied from interface: `BaseToolset`
    Performs cleanup and releases resources held by the toolset.

    NOTE: This method is invoked, for example, at the end of an agent server's lifecycle or when the toolset is no longer needed. Implementations should ensure that any open connections, files, or other managed resources are properly released to prevent leaks.

    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `BaseToolset`

  - ### fromConfig

    public static McpToolset fromConfig(BaseTool.ToolConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException
    Creates a McpToolset instance from a config.
    Parameters:
      `config` - The config for the McpToolset.
      `configAbsPath` - The absolute path to the config file that contains the McpToolset config.
    Returns:
      The McpToolset instance.
    Throws:
      `ConfigAgentUtils.ConfigurationException` - if the McpToolset cannot be created from the config.