ADK for TypeScript: API Reference
    Preparing search index...

    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.

    It can also be configured with a prefix. If provided, all tools discovered from the MCP server will have their names prefixed with ${prefix}_. When the LLM invokes the prefixed tool, this toolset transparently strips the prefix before sending the request to the underlying 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)

    Constructors

    Properties

    "[BASE_TOOLSET_SIGNATURE_SYMBOL]": true
    prefix?: string
    toolFilter: string[] | ToolPredicate

    Methods

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

    • Returns metadata for the resource whose name matches name.

      Parameters

      • name: string

        The advertised name of the resource.

      Returns Promise<{}>

      The matching MCP Resource.

      If no resource with the given name is advertised by the server.

    • Lists the names of the resources advertised by the MCP server.

      Returns Promise<string[]>

      The resource names available on the server.

    • 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>

    • Reads the contents of the named resource from the MCP server.

      The resource name is resolved to a URI via getResourceInfo before reading. Binary contents are returned base64-encoded, exactly as provided by the server (never decoded and re-encoded).

      Parameters

      • name: string

        The advertised name of the resource to read.

      Returns Promise<({} | {})[]>

      The resource contents (text and/or base64-encoded binary).

      If the resource is unknown or has no URI.