# Class MCPToolset

A toolset that dynamically discovers and provides tools from a Model Context Protocol (MCP) server.

This class connects to an MCP server, retrieves the list of available tools, and wraps each of them in an MCPTool instance. This allows the agent to seamlessly use tools from an external MCP-compliant service.

The toolset can be configured with a filter to selectively expose a subset of the tools provided by the MCP server.

Usage: import { MCPToolset } from '@google/adk'; import { StreamableHTTPConnectionParamsSchema } from '@google/adk';

const connectionParams = StreamableHTTPConnectionParamsSchema.parse({ type: "StreamableHTTPConnectionParams", url: "http://localhost:8788/mcp" });

const mcpToolset = new MCPToolset(connectionParams); const tools = await mcpToolset.getTools();

#### Hierarchy (View Summary)

- BaseToolset
  - MCPToolset

- Defined in tools/mcp/mcp_toolset.ts:40

## Constructors

### constructor

- new MCPToolset(
  connectionParams: MCPConnectionParams,
  toolFilter?: string[] | ToolPredicate,
  prefix?: string,
  ): MCPToolset

  #### Parameters

  - connectionParams: MCPConnectionParams
  - toolFilter: string[] | ToolPredicate = []
  - `Optional` prefix: string

  #### Returns MCPToolset

  Overrides BaseToolset.constructor

  - Defined in tools/mcp/mcp_toolset.ts:43

## Properties

### `Readonly`[BASE_TOOLSET_SIGNATURE_SYMBOL]

"[BASE_TOOLSET_SIGNATURE_SYMBOL]": true

Inherited from BaseToolset.[BASE_TOOLSET_SIGNATURE_SYMBOL]

- Defined in tools/base_toolset.ts:44

### `Optional` `Readonly` prefix

prefix?: string

Inherited from BaseToolset.prefix

- Defined in tools/base_toolset.ts:48

### `Readonly` toolFilter

toolFilter: string[] | ToolPredicate

Inherited from BaseToolset.toolFilter

- Defined in tools/base_toolset.ts:47

## Methods

### close

- close(): Promise<void>

  Closes 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.

  #### Returns Promise<void>

  A Promise that resolves when the toolset is closed.

  Overrides BaseToolset.close

  - Defined in tools/mcp/mcp_toolset.ts:72

### getTools

- getTools(): Promise<BaseTool[]>

  Returns the tools that should be exposed to LLM.

  #### Returns Promise<BaseTool[]>

  A Promise that resolves to the list of tools.

  Overrides BaseToolset.getTools

  - Defined in tools/mcp/mcp_toolset.ts:52

### `Protected` isToolSelected

- isToolSelected(tool: BaseTool, context: ReadonlyContext): boolean

  Returns whether the tool should be exposed to LLM.

  #### Parameters

  - tool: BaseTool

    The tool to check.

  - context: ReadonlyContext

    Context used to filter tools available to the agent.

  #### Returns boolean

  Whether the tool should be exposed to LLM.

  Inherited from BaseToolset.isToolSelected

  - Defined in tools/base_toolset.ts:79

### processLlmRequest

- processLlmRequest(toolContext: Context, llmRequest: LlmRequest): Promise<void>

  Processes the outgoing LLM request for this toolset. This method will be called before each tool processes the llm request.

  Use cases:

  - Instead of let each tool process the llm request, we can let the toolset process the llm request. e.g. ComputerUseToolset can add computer use tool to the llm request.

  #### Parameters

  - toolContext: Context

    The context of the tool.

  - llmRequest: LlmRequest

    The outgoing LLM request, mutable this method.

  #### Returns Promise<void>

  Inherited from BaseToolset.processLlmRequest

  - Defined in tools/base_toolset.ts:107