Optionalprefix: stringReadonly[Optional ReadonlyprefixReadonlytoolCloses 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.
A Promise that resolves when the toolset is closed.
Returns the tools that should be exposed to LLM.
Optionalcontext: ReadonlyContextContext used to filter tools available to the agent. If not defined, all tools in the toolset are returned.
A Promise that resolves to the list of tools.
ProtectedisReturns whether the tool should be exposed to LLM.
The tool to check.
Context used to filter tools available to the agent.
Whether the tool should be exposed to LLM.
Lists the names of the resources advertised by the MCP server.
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:
The context of the tool.
The outgoing LLM request, mutable this method.
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).
The advertised name of the resource to read.
The resource contents (text and/or base64-encoded binary).
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();