Google ADK MCP in 2026: McpToolset, Headers and Cleanup
Connect Google ADK MCP tools to a remote server: McpToolset with StreamableHTTPConnectionParams, a bearer key, tool_filter, closing it and real X output.
Tarun Khatri
Published · Updated · 6 min read
Google ADK MCP support is the McpToolset class: give it StreamableHTTPConnectionParams with a URL and headers, and add it to an agent's tools.
This guide connects a Python ADK agent to Weir's remote MCP server for public X (Twitter) data, with an API key. It covers the renamed classes, the 5-second timeout, closing the toolset and a real call. We run Weir.
import os
from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool import McpToolset, StreamableHTTPConnectionParams
weir = McpToolset(connection_params=StreamableHTTPConnectionParams(
url="https://api.weirapp.io/mcp", timeout=30,
headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
), tool_filter=["search_x", "get_x_post"])
root_agent = LlmAgent(model="gemini-flash-latest", name="x_researcher", tools=[weir],
instruction="Search X with limit 5 or less. Link every post you cite.")
How to connect Google ADK to a remote MCP server
Weir takes an API key in the Authorization header, so there's no browser sign-in.
- Installpip install "google-adk[mcp]" in a Python 3.11 or later virtual environment.
- Get a Weir keyCreate one under API keys in your Weir dashboard. Keep it in WEIR_API_KEY.
- Set a model keyGemini models read GOOGLE_API_KEY, per ADK's quickstart.
- Run the agentRun adk create my_agent, paste the box into my_agent/agent.py, then run adk web.
As of 24 October 2026, PyPI lists google-adk 2.13.0, released on 23 October. It needs Python 3.11 or later, though ADK's quickstart still says 3.10. Expect a big install, with FastAPI and OpenTelemetry.
Why the extra? In 2.13.0, the mcp SDK is optional. Without it, google.adk.tools.mcp_tool loads empty and the import fails.
On TypeScript? npm lists @google/adk 2.3.0. Its MCPToolset takes type: "StreamableHTTPConnectionParams" and the header under transportOptions.requestInit.headers.
Google ADK MCP tutorial: run the agent from a script
adk web loads root_agent from agent.py and, per ADK's docs, closes the toolset for you. In your own app, a Runner does that work:
import asyncio
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
from my_agent.agent import root_agent
async def main(question: str) -> None:
async with Runner(app_name="x_research", agent=root_agent, auto_create_session=True,
session_service=InMemorySessionService()) as runner:
message = types.Content(role="user", parts=[types.Part(text=question)])
async for event in runner.run_async(user_id="me", session_id="s1", new_message=message):
if event.is_final_response() and event.content:
print(event.content.parts[0].text)
asyncio.run(main("What have @googledevs and @llama_index posted about MCP?"))
Here's what ADK 2.13.0 does with it, per its source:
- The
async withblock closes the toolset. On exit, the runner closes every toolset in the agent tree, waiting up to 10 seconds each. auto_create_session=Truesaves a step. Without it, a newsession_idraisesSessionNotFoundError.- The toolset is built at import time. ADK's docs say deployed agents must define
McpToolsetthis way, not in an async function.
What does the agent get back?
To answer, Gemini calls search_x with both handles. We made that call through Weir's MCP server on 24 October 2026:
→ search_x {"fromUsers": ["llama_index", "googledevs"], "query": "MCP -filter:nativeretweets",
"onlyOriginal": true, "limit": 3}
← 3 posts · 4 credits · nextCursor set
2026-10-16 890 likes @googledevs "Reconstructing ancient ruins in 3D with Gemini 4 Argon"
2026-10-07 560 likes @googledevs Antigravity with the Stitch MCP and the Android CLI
2026-07-30 65 likes @llama_index "Parse Gateway", "also available as an MCP server"
ADK hands the model the whole MCP result. That's content, with the JSON and a line like "Charged 4 credits; 609 credits left.", plus the same JSON as structuredContent.
Each post has its url, so the agent can link it. The result also carries meta.next, the follow-up call with the new cursor.
Weir bills 1 credit per call plus 1 per X post, and failed calls are free. Packs start at $5 for 25,000 credits, as of October 2026. See our pricing page.
Which Google ADK MCP tools does the agent see?
A default Weir key lists more than 40 tools, Reddit included, and each one adds its description to the prompt. These settings trim the list:
| Setting | What it does |
|---|---|
tool_filter=[...] |
Keeps only the names you list |
tool_filter=fn |
Keeps tools where fn returns True |
tool_name_prefix="weir" |
Renames search_x to weir_search_x |
tool_list_cache_ttl_seconds |
Reuses the tool list between runs |
Filters match Weir's own names, before any prefix. ADK adds the underscore itself, so the docs' "pg_" example gives pg__query.
Without the cache, ADK lists the tools again on every run. Set tool_list_cache_ttl_seconds=300 to reuse the list for 5 minutes.
Old tutorials: MCPToolset.from_server is gone
Guides from 2025, Google Cloud's own among them, call await MCPToolset.from_server(...) and get back an exit_stack. In 2.13.0 that method doesn't exist, so the line raises AttributeError.
| Old code | ADK 2.13.0 |
|---|---|
MCPToolset |
McpToolset (the old name warns) |
MCPToolset.from_server(...) |
McpToolset(...) in tools=[...] |
await exit_stack.aclose() |
await toolset.close() |
SseServerParams |
StreamableHTTPConnectionParams |
The last row matters for Weir, which doesn't serve the older SSE transport.
If it doesn't work
This is what Weir sent our request with no key, on 24 October 2026:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.weirapp.io/.well-known/
oauth-protected-resource/mcp", scope="read:social usage:read monitors:read"
{"error":"unauthorized","error_description":"Authorization is required."}
The challenge is for apps that sign in through a browser. In ADK's source, any failed connect, this one included, raises "ConnectionError: Failed to create MCP session". Check the key with Weir's free GET /v1/whoami. Other errors:
- "Failed to get tools from MCP server" after 5 seconds. The default
timeoutran out. Settimeout=30. cannot import name 'McpToolset'. Installgoogle-adk[mcp].- "MCPToolset class is deprecated". Rename it to
McpToolset. Nothing else changes. - A tool returns
402. Your Weir credits ran out. The model gets the error, and retrying won't help.
When not to use Weir
- Your agent has to post or DM on X. Weir is read-only.
- You want private data. Weir reads public posts, not bookmarks, DMs or home timelines.
- Price per post matters most. TwitterAPI.io lists $0.15 per 1,000 tweets as of October 2026, less than our $5 pack.
- You need a guarantee. Weir isn't licensed by X or affiliated with it, so access can change.
FAQ
Does Google ADK support MCP?
Yes. ADK's docs mark MCP tools as supported in Python, TypeScript, Go, Java and Kotlin. In Python, McpToolset connects over stdio, SSE or Streamable HTTP and adapts the server's tools for an LlmAgent.
What is McpToolset in Google ADK?
It's ADK's toolset for one MCP server. It opens the session, lists and filters the tools, and wraps each one as an ADK tool. MCPToolset is the old name, which still works but warns.
How do I pass an API key to an MCP server in ADK?
Put it in headers on the connection params, as above. For a key per user, pass header_provider: a function that builds the headers from the run's context.
Can a Google ADK agent be an MCP server?
Yes. ADK's docs show to_mcp_server(agent) from google.adk.tools.mcp_tool, which wraps an LlmAgent as a FastMCP server. Clients such as Claude Code can then call it.
Sources
All checked on 24 October 2026.
- ADK docs, Model Context Protocol tools (adk-docs commit 2f3c2c0, 22 October 2026): https://adk.dev/tools-custom/mcp-tools/
- ADK docs, advanced MCP configuration: https://adk.dev/tools-custom/mcp-tools/advanced/
- ADK docs, ADK agents as MCP servers: https://adk.dev/tools-custom/mcp-tools/agent-as-server/
- ADK docs, Python quickstart: https://adk.dev/get-started/python/
- google-adk on PyPI, version 2.13.0: https://pypi.org/project/google-adk/
- adk-python v2.13.0 source, MCP tools: https://github.com/google/adk-python/tree/v2.13.0/src/google/adk/tools/mcp_tool
- adk-python v2.13.0 source,
Runner: https://github.com/google/adk-python/blob/v2.13.0/src/google/adk/runners.py - @google/adk on the npm registry, version 2.3.0: https://registry.npmjs.org/@google/adk
- Google Cloud blog, "A guide to Google ADK and MCP integration with an external server" (May 2025): https://cloud.google.com/blog/topics/developers-practitioners/use-google-adk-and-mcp-with-an-external-server
- TwitterAPI.io pricing: https://twitterapi.io/pricing
- Weir docs, MCP: https://docs.weirapp.io/mcp
- Weir billing: https://docs.weirapp.io/billing
- Weir search_x call (request 2b5bc145-b55b-4b40-b2c5-e9455a6b41d6) and no-key request (request ae39d2b7-620b-403e-a316-d158b291cadb)