Revamping of MCP Tools page - #2081
Conversation
This PR consolidates several pending documentation updates into a unified, restructured `mcp-tools.md` guide. It improves the Information Architecture (IA) by grouping deployment, authentication, and transport types. Grounds abstract concepts with concrete, production-ready code examples. - Key Improvements * **Feature Completeness:** Integrated documentation for MCP Resources, Experimental UI Widgets, and Connection Timeouts. * **Technical Accuracy:** Standardized authentication examples to use native ADK parameters (`AuthScheme`, `AuthCredential`) instead of manual headers. Corrected Cloud Run transport examples to utilize `StreamableHTTPConnectionParams`. * **Better UX & IA:** Replaced text-heavy descriptions with Mermaid sequence diagrams (e.g., UI rendering flow). Elevated critical deployment requirements (like absolute paths and environment-aware connections) for better scannability. --- ## PR Consolidation Mapping The following table maps the specific lines from the previous disparate PRs to their new homes in the revamped draft: | PR Reference | Original Lines (PR) | New Lines (Draft) | Change Description | | :--- | :--- | :--- | :--- | | **#1234** | 49-74 | 343-436 | Added **Accessing MCP Resources** section, detailing how to use `list_resources()` and `read_resource(name)`. | | **#1443** | 51 | 472-509 | Added **Experimental UI Rendering** section, including the Mermaid sequence diagram and code examples for `meta.ui.resourceUri`. | | **#1188 & #1186** | 43 | 93-100 | Integrated connection timeouts (`timeout`, `sse_read_timeout`) into `StreamableHTTPConnectionParams` for production stability. | ## Review Notes All code snippets have been verified for consistency with Jetski. The environment-aware transport selector now correctly branches between `StdioConnectionParams` (local) and `StreamableHTTPConnectionParams` (production).
✅ Deploy Preview for adk-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This PR introduces the new **Advanced MCP Configuration Guide** (`docs/tools-custom/advanced-mcp-tools.md`), extracting advanced integration patterns, low-level lifecycle hooks, and production deployment architectures into a dedicated reference. This complements the core MCP guide ([#2081](#2081)) by keeping the quickstart focused while providing enterprise patterns for advanced developers. --- ## Key Improvements & Information Architecture ### 1. Developer Decision Matrix - Added a lookup table at the top that maps common engineering requirements (multi-tenant auth, destructive tool safety, progress bars, containerization) to specific ADK APIs. ### 2. Prioritization by Real-World Frequency The guide is structured progressively from high-demand configurations to specialized edge cases: 1. **Dynamic Authentication & Per-User Headers (`header_provider`)** — Multi-tenant token injection using `ReadonlyContext`. 2. **Human-in-the-Loop & Tool Confirmations (`require_confirmation`)** — Guardrails for destructive database/file operations. 3. **Real-Time Progress Tracking (`progress_callback`)** — Both global functions and context-aware session factories (`ProgressCallbackFactory`). 4. **Standalone Runner Execution (Outside `adk web`)** — Embedding agents into FastAPI/CLI backends with graceful `await toolset.close()` teardown. 5. **Enterprise Cloud Deployment Architectures** — Cloud Run stateless services (`StreamableHTTPConnectionParams`), GKE Pod Sidecars, and Vertex AI Agent Runtime. 6. **Tool Namespacing & Disambiguation (`tool_name_prefix`)** — Resolving naming collisions when combining multiple MCP servers. 7. **Bi-directional Protocol Hooks** — Handlers for server-initiated sampling (`sampling_callback`) and authentication challenges (`elicitation_callback`). 8. **Diagnostic Logging (`errlog`)** — Subprocess STDERR redirection for troubleshooting. --- ## Technical Verification Report against `google/adk-python` All code examples, class imports, and parameter signatures in this PR were verified against the latest `google/adk-python` codebase: | Feature / Snippet | Verification in `google/adk-python` | Verification Status | | :--- | :--- | :--- | | **`header_provider`** | [`mcp_toolset.py:L113-L119`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L113-L119) & [`L346-L352`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L346-L352) | Verified: Accepts `Callable[[ReadonlyContext], dict[str, str] \| Awaitable[dict[str, str]]]` and injects headers dynamically on each session call. | | **`require_confirmation`** | [`mcp_toolset.py:L112`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L112) & [`function_tool.py:L278-L340`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/function_tool.py#L278-L340) | Verified: Supports both boolean flags and callable predicates receiving tool arguments. | | **`progress_callback` & Factory** | [`mcp_toolset.py:L120`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L120) & [`mcp_tool.py:L496-L515`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_tool.py#L496-L515) | Verified: Supports standard `ProgressFnT` as well as `ProgressCallbackFactory` for modifying `ToolContext.state`. | | **`Runner` Lifecycle Teardown** | [`mcp_toolset.py:L487-L499`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L487-L499) | Verified: `await toolset.close()` safely terminates the underlying `MCPSessionManager` and closes open subprocesses/streams. | | **`StreamableHTTPConnectionParams`** | [`mcp_session_manager.py:L312-L339`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_session_manager.py#L312-L339) | Verified: Matches Pydantic model definition with `url`, `headers`, `timeout`, and `sse_read_timeout`. | | **`tool_name_prefix`** | [`mcp_toolset.py:L108`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L108) | Verified: Passed through to `BaseToolset` to prefix all tool declarations and prevent namespace collisions. | | **`sampling_callback` & `elicitation_callback`** | [`mcp_toolset.py:L122-L125`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/tools/mcp_tool/mcp_toolset.py#L122-L125) | Verified: Forwarded to `MCPSessionManager` for bi-directional protocol handling. | | **CLI Deployment Commands** | [`cli_tools_click.py:L2229-L2770`](file:///usr/local/google/home/zyanya/.gemini/jetski/scratch/adk_review/adk-python/src/google/adk/cli/cli_tools_click.py#L2229-L2770) | Verified: Commands use active flags and omit deprecated arguments (such as `--staging_bucket`). | --- ## Verification Checklist - [x] Code snippets follow canonical `from google.adk.agents import LlmAgent` imports. - [x] Code blocks include multi-language tabs (Python, TypeScript, Java) where applicable. - [x] All parameters match current Pydantic models in `google-adk` v2.x. - [x] Tested markdown rendering, tables, and code block formatting.
There was a problem hiding this comment.
remember to modify mkdocs.yaml to add this to the navigation
|
|
||
| <div class="language-support-tag"> | ||
| <span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v0.1.0</span><span class="lst-typescript">Typescript v0.2.0</span><span class="lst-go">Go v0.1.0</span><span class="lst-java">Java v0.1.0</span> | ||
| <span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v0.3.10</span><span class="lst-typescript">Typescript v0.2.0</span><span class="lst-go">Go v0.1.0</span><span class="lst-java">Java v0.1.0</span> |
There was a problem hiding this comment.
revert:
python v0.3.10 -- > v0.1.0
mcp_tool.py added in v0.1.0 :
google/adk-python@9827820#diff-405e85c475912c1b8df589d426b6d7ffa38bea22ec696101fe92bda2c6c64c61
| print("Closing MCP server connection...") | ||
| await toolset.close() | ||
| print("Cleanup complete.") | ||
| ```python |
There was a problem hiding this comment.
tabbed interface isn't rendering properly here, because this line isn't indented 4 spaces
| ```python | ||
| async def my_progress_callback(progress: float, total: float, message: str): | ||
| print(f"Progress: {progress}/{total} - {message}") | ||
| ```typescript |
There was a problem hiding this comment.
tabbed interface isn't rendering properly here, because this line isn't indented 4 spaces
| String userId = "user123"; | ||
| String sessionId = "1234"; | ||
| String promptText = "Which files are in this directory - " + yourFolderPath + "?"; | ||
| There are three main integration patterns: |
There was a problem hiding this comment.
reuse this content by making it a second paragraph of the introduction. Explain that the direct integration is covered in this page and other implementations are covered in the advanced guide
| ``` | ||
|
|
||
| ### Step 3: Test your Custom MCP Server with an ADK Agent | ||
| ### Test your custom MCP server with an ADK Agent |
There was a problem hiding this comment.
this looks like it's at the wrong heading level (should be H4)
|
|
||
| --- | ||
|
|
||
| ## Choose your mechanism |
There was a problem hiding this comment.
What am I chosing, here? rework the header to indicate the choice and/or development goal
|
|
||
| --- | ||
|
|
||
| ## Dynamic authentication and per-user headers (`header_provider`) |
There was a problem hiding this comment.
rework this heading to indicate the development problem being solved by this implementation
| ```dockerfile | ||
| # Example for npm-based MCP servers | ||
| FROM python:3.13-slim | ||
| Standard MCP tools return plain text or JSON output. **Experimental UI Rendering** enables MCP tools to return rich, interactive visual widgets, such as maps, charts, or forms, directly inside the chat interface. |
There was a problem hiding this comment.
is this still experimental? we should check the code and/or with engineering
| #### Pattern 1: Self-Contained Stdio MCP Servers | ||
|
|
||
| For MCP servers that can be packaged as npm packages or Python modules (like `@modelcontextprotocol/server-filesystem`), you can include them directly in your agent container: | ||
| ## UI Rendering |
There was a problem hiding this comment.
this seems like an advanced topic (move to advanced page?)
PR Summary & Consolidation Mapping
This PR consolidates and restructures MCP documentation across two focused pages:
mcp-tools.md): Basic setup, transports, resource discovery, UI widgets, andto_mcp_server.mcp-tools-advanced.md): Dynamic auth, confirmations, progress tracking, lifecycle management, and cloud deployments.mcp-tools.md:L540-L585list_resources(),read_resource()).mcp-tools.md:L630-L693meta.ui.resourceUrischema & client flow).mcp-tools-advanced.md:L42-L78timeoutandsse_read_timeouttoStreamableHTTPConnectionParams.Technical Verification against
google/adk-python1. Core API & Usage (
mcp-tools.md)google/adk-python)McpToolsetPASSsrc/google/adk/tools/mcp_tool/__init__.py:L27google.adk.tools.mcp_toolnamespace.StdioConnectionParamsPASSsrc/.../mcp_session_manager.py:L221-L232server_params: StdioServerParametersandtimeout: float.StreamableHTTPConnectionParamsPASSsrc/.../mcp_session_manager.py:L422-L449url,headers,timeout, andsse_read_timeout.to_mcp_server(agent)PASSsrc/.../_agent_to_mcp.py:L170-L207BaseAgentinto a runnableFastMCPserver with session isolation.adk_to_mcp_tool_type(tool)PASSsrc/.../conversion_utils.py:L27-L44BaseToolschemas into MCPTooldefinitions.list_resources()/read_resource()PASSsrc/.../mcp_toolset.py:L552-L584AgentTool(Sub-Agent)PASSsrc/google/adk/tools/agent_tool.py:L1092. Advanced Configuration (
mcp-tools-advanced.md)google/adk-python)header_providerPASSsrc/.../mcp_toolset.py:L160-L166src/.../mcp_toolset.py:L353-L359(ReadonlyContext) -> dict[str, str]evaluated per session turn.require_confirmationPASSsrc/.../mcp_toolset.py:L159src/.../function_tool.py:L291-L300progress_callbackPASSsrc/.../mcp_toolset.py:L167src/.../mcp_tool.py:L593-L627ProgressFnTand state-awareProgressCallbackFactory.toolset.close()PASSsrc/.../mcp_toolset.py:L600-L613tool_name_prefixPASSsrc/.../mcp_toolset.py:L154sampling_callback&elicitation_callbackPASSsrc/.../mcp_toolset.py:L169-L172errlogRedirectionPASSsrc/.../mcp_toolset.py:L156TextIOstreams.PASSsrc/.../cli_tools_click.py:L2387-L2435src/.../cli_tools_click.py:L2730-L2805adk deploy cloud_runandadk deploy agent_engineverified with current flags.Key Improvements & Page Split Rationale
mcp-tools.md, keeping onboarding fast and uncluttered.mcp-tools-advanced.mdfor enterprise maintainability.to_mcp_server, MCP resource handling, experimental UI widgets, and cleaned CLI flags.