Connects to a MCP Server, and retrieves MCP Tools into ADK Tools. This toolset manages the connection to an MCP server and provides tools that can be used by an agent. It properly implements the BaseToolset interface for easy integration with the agent framework. Usage:: toolset = Mcp
| 63 | |
| 64 | |
| 65 | class McpToolset(BaseToolset): |
| 66 | """Connects to a MCP Server, and retrieves MCP Tools into ADK Tools. |
| 67 | |
| 68 | This toolset manages the connection to an MCP server and provides tools |
| 69 | that can be used by an agent. It properly implements the BaseToolset |
| 70 | interface for easy integration with the agent framework. |
| 71 | |
| 72 | Usage:: |
| 73 | |
| 74 | toolset = McpToolset( |
| 75 | connection_params=StdioServerParameters( |
| 76 | command='npx', |
| 77 | args=["-y", "@modelcontextprotocol/server-filesystem"], |
| 78 | ), |
| 79 | tool_filter=['read_file', 'list_directory'] # Optional: filter specific |
| 80 | tools |
| 81 | ) |
| 82 | |
| 83 | # Use in an agent |
| 84 | agent = LlmAgent( |
| 85 | name='enterprise_assistant', |
| 86 | instruction='Help user accessing their file systems', |
| 87 | tools=[toolset], |
| 88 | ) |
| 89 | |
| 90 | # Cleanup is handled automatically by the agent framework |
| 91 | # But you can also manually close if needed: |
| 92 | # await toolset.close() |
| 93 | """ |
| 94 | |
| 95 | def __init__( |
| 96 | self, |
| 97 | *, |
| 98 | connection_params: Union[ |
| 99 | StdioServerParameters, |
| 100 | StdioConnectionParams, |
| 101 | SseConnectionParams, |
| 102 | StreamableHTTPConnectionParams, |
| 103 | ], |
| 104 | tool_filter: Optional[Union[ToolPredicate, List[str]]] = None, |
| 105 | tool_name_prefix: Optional[str] = None, |
| 106 | errlog: TextIO = sys.stderr, |
| 107 | auth_scheme: Optional[AuthScheme] = None, |
| 108 | auth_credential: Optional[AuthCredential] = None, |
| 109 | require_confirmation: Union[bool, Callable[..., bool]] = False, |
| 110 | header_provider: Optional[ |
| 111 | Callable[[ReadonlyContext], Dict[str, str]] |
| 112 | ] = None, |
| 113 | progress_callback: Optional[ |
| 114 | Union[ProgressFnT, ProgressCallbackFactory] |
| 115 | ] = None, |
| 116 | use_mcp_resources: Optional[bool] = False, |
| 117 | sampling_callback: Optional[SamplingFnT] = None, |
| 118 | sampling_capabilities: Optional[SamplingCapability] = None, |
| 119 | credential_key: str | None = None, |
| 120 | ): |
| 121 | """Initializes the McpToolset. |
| 122 |
no outgoing calls