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.
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.
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.
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();