From 14e0e3db7bc5b328630474cd8e0557e054eec28c Mon Sep 17 00:00:00 2001 From: adk-bot Date: Wed, 22 Oct 2025 21:06:31 +0000 Subject: [PATCH 1/2] docs: Add documentation for McpToolset header_provider --- docs/tools/mcp-tools.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/tools/mcp-tools.md b/docs/tools/mcp-tools.md index ceb33136d6..4de2ab19ae 100644 --- a/docs/tools/mcp-tools.md +++ b/docs/tools/mcp-tools.md @@ -42,6 +42,32 @@ The `MCPToolset` class is ADK's primary mechanism for integrating tools from an 4. **Proxying Tool Calls:** When your `LlmAgent` decides to use one of these tools, `MCPToolset` transparently proxies the call (using the `call_tool` MCP method) to the MCP server, sends the necessary arguments, and returns the server's response back to the agent. 5. **Filtering (Optional):** You can use the `tool_filter` parameter when creating an `MCPToolset` to select a specific subset of tools from the MCP server, rather than exposing all of them to your agent. +### Dynamic Headers with `header_provider` + +You can provide a `header_provider` to the `McpToolset` to dynamically generate headers for each request. This is useful for multi-tenancy or other scenarios where headers need to change based on the context. + +**Example:** +```python +from google.adk.tools.mcp_tool.mcp_toolset import McpToolset +from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams + +root_agent = LlmAgent( + model='gemini-2.0-flash', + name='tenant_agent', + instruction="...", + tools=[ + McpToolset( + connection_params=StreamableHTTPConnectionParams( + url='http://localhost:3000/mcp', + ), + tool_filter=['get_tenant_data'], + header_provider=lambda ctx: {'X-Tenant-ID': 'tenant1'}, + ) + ], +) +``` +For a complete example, see the [mcp_dynamic_header_agent sample](https://github.com/google/adk-python/tree/main/contributing/samples/mcp_dynamic_header_agent). + The following examples demonstrate how to use `MCPToolset` within the `adk web` development environment. For scenarios where you need more fine-grained control over the MCP connection lifecycle or are not using `adk web`, refer to the "Using MCP Tools in your own Agent out of `adk web`" section later in this page. ### Example 1: File System MCP Server @@ -781,7 +807,6 @@ if __name__ == '__main__': asyncio.run(async_main()) except Exception as e: print(f"An error occurred: {e}") -``` ## Key considerations From 266e383705d2bd7ae1d1c03adc0f67f427a78a5a Mon Sep 17 00:00:00 2001 From: Juan Carlos Gonzalez Resendiz Date: Mon, 29 Jun 2026 14:35:11 -0600 Subject: [PATCH 2/2] Update link to mcp_dynamic_header_agent sample --- docs/tools/mcp-tools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tools/mcp-tools.md b/docs/tools/mcp-tools.md index 4de2ab19ae..671cd723bf 100644 --- a/docs/tools/mcp-tools.md +++ b/docs/tools/mcp-tools.md @@ -66,7 +66,7 @@ root_agent = LlmAgent( ], ) ``` -For a complete example, see the [mcp_dynamic_header_agent sample](https://github.com/google/adk-python/tree/main/contributing/samples/mcp_dynamic_header_agent). +For a complete example, see the [mcp_dynamic_header_agent sample](https://github.com/google/adk-python/tree/main/contributing/samples/mcp/mcp_dynamic_header_agent). The following examples demonstrate how to use `MCPToolset` within the `adk web` development environment. For scenarios where you need more fine-grained control over the MCP connection lifecycle or are not using `adk web`, refer to the "Using MCP Tools in your own Agent out of `adk web`" section later in this page. @@ -1216,4 +1216,4 @@ MCPToolset( * [Model Context Protocol Documentation](https://modelcontextprotocol.io/ ) * [MCP Specification](https://modelcontextprotocol.io/specification/) -* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/) \ No newline at end of file +* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/)