From 8b3aa87ee649221db3fa6b12a13e68ecfbe32292 Mon Sep 17 00:00:00 2001 From: adk-bot Date: Thu, 5 Feb 2026 18:56:43 +0000 Subject: [PATCH] docs: Add section on Accessing MCP Resources --- docs/tools-custom/mcp-tools.md | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/tools-custom/mcp-tools.md b/docs/tools-custom/mcp-tools.md index b939bf1d8d..26e25b54e6 100644 --- a/docs/tools-custom/mcp-tools.md +++ b/docs/tools-custom/mcp-tools.md @@ -46,6 +46,34 @@ 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. +### Authentication for Remote MCP Servers + +When connecting to a remote MCP server that requires authentication, you can +provide authentication details to the `McpToolset`. This is particularly useful +when using `SseConnectionParams` to connect to a secure server. + +The `McpToolset` constructor accepts two parameters for this purpose: + +* `auth_scheme`: An `AuthScheme` object that defines the authentication method + (e.g., Bearer, Basic, API Key). +* `auth_credential`: An `AuthCredential` object that holds the credentials + (e.g., token, username/password). + +These parameters are used to generate the necessary `Authorization` header for +the MCP connection. The ADK will handle the authentication flow, including +any necessary OAuth 2.0 token exchanges, and inject the correct header into +the requests sent to the MCP server. + +### Accessing MCP Resources + +Besides tools, MCP servers can also expose Resources, which are data blobs that can be accessed by the agent. The `McpToolset` provides two methods to interact with these resources: + +* `list_resources()`: This method returns a list of the names of all available resources on the MCP server. + +* `read_resource(name)`: This method reads the content of a specific resource, identified by its `name`. The content is returned as a list of content blocks. + +These methods allow your agent to discover and consume data provided by the MCP server, in addition to the available tools. + 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 @@ -741,7 +769,7 @@ from . import agent python3 /path/to/your/my_adk_mcp_server.py ``` It will print "Launching MCP Server..." and wait. The ADK agent (run via `adk web`) will then connect to this process if the `command` in `StdioConnectionParams` is set up to execute it. - *(Alternatively, `McpToolset` will start this server script as a subprocess automatically when the agent initializes).* + *(Alternatively, `McpToolset` will start this server script as a subprocess automatically when the agent initializes).)* 2. **Run `adk web` for the client agent:** Navigate to the parent directory of `mcp_client_agent` (e.g., `adk_agent_samples`) and run: @@ -870,7 +898,6 @@ if __name__ == '__main__': asyncio.run(async_main()) except Exception as e: print(f"An error occurred: {e}") -``` ## Key considerations @@ -1063,7 +1090,7 @@ def create_mcp_server(): return app -def main(port: int = 8080, json_response: bool = False): +def main(port: int = 8080, json_response: bool = false): """Main server function.""" logging.basicConfig(level=logging.INFO) @@ -1279,4 +1306,4 @@ McpToolset( * [Model Context Protocol Documentation](https://modelcontextprotocol.io/ ) * [MCP Specification](https://modelcontextprotocol.io/specification/) -* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/) +* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/mcp-python)