feat: migrate MCP tooling to mcp 2.x - #6537
Open
ProgrammerPlus1998 wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
I've signed the CLA. Could a maintainer please re-trigger the CLA check? |
Bump the mcp dependency to >=2.0.0,<3 and adapt the MCP tool integration to the 2.0 SDK surface: - McpError -> MCPError; ProgressFnT now lives in mcp.shared.dispatcher (mcp.shared.session was removed). - Read snake_case model attributes (input_schema, output_schema, is_error, mime_type) instead of the removed camelCase aliases. - ClientSession read_timeout_seconds now takes float seconds, not a timedelta. - streamable_http_client / streamable-http layer: the public McpHttpClientFactory moved to a private module, so declare the equivalent factory Protocol locally. - to_mcp_server: mcp.server.fastmcp was removed; build the server with mcp.server.mcpserver.MCPServer instead. In mcp 2.0 the server-side Context.session is a fresh ServerSession per request rather than per connection, so key the per-connection ADK session map on the shared underlying Connection object (with a fallback to the session) to keep one conversation per MCP connection. Refs google#6532
ProgrammerPlus1998
force-pushed
the
feat/mcp-2x-migration
branch
from
July 31, 2026 10:11
589910f to
5e2057d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
adk-pythonpins the MCP Python SDK below 2.0 (mcp>=1.24,<2), which blocksinstalling alongside
mcp2.0.0. The 2.0 release makes several breaking changesto the SDK surface that the MCP tool integration relies on.
Solution:
Bump the dependency to
mcp>=2.0.0,<3and adapt to the 2.0 API:McpError→MCPError;ProgressFnTnow lives inmcp.shared.dispatcher(
mcp.shared.sessionwas removed).input_schema,output_schema,is_error,mime_type) instead of the removed camelCase aliases.ClientSession(read_timeout_seconds=...)now takes float seconds rather thana
timedelta.McpHttpClientFactorymoved to a private module, so declare theequivalent factory
Protocollocally instead of importing it.to_mcp_server:mcp.server.fastmcpwas removed; build the server withmcp.server.mcpserver.MCPServerinstead.Behavior change worth a closer look (review requested):
In mcp 2.0 the server-side
Context.sessionis a freshServerSessionperrequest rather than one stable object per connection. The agent-as-MCP-server
feature kept one ADK session per MCP connection keyed on
ctx.session, which nolonger works.
_connection_keynow keys that map on the underlying sharedConnectionobject (read viactx.session._connection, falling back to thesession itself).
Connectionis shared by every request on a connection and isweak-referenceable, so
WeakKeyDictionarycleanup still works. This touches aprivate SDK attribute because
mcp.server.mcpserver.Contextexposes no publicper-connection identifier — happy to switch to a public hook if the maintainers
can point me at one.
Testing Plan
Unit Tests:
Updated the MCP tool unit tests to the 2.0 surface (snake_case attributes,
MCPError(code=..., message=...), float timeouts, and an in-memoryclient/server helper replacing the removed
create_connected_server_and_client_session).(run against an environment with
mcp==2.0.0installed)Manual End-to-End (E2E) Tests:
Verified
_connection_keyagainst the real mcp 2.0 SDK: twoServerSessionobjects built on one shared
Connectionresolve to the same key, distinct fromeither per-request session, and a session object without
_connectionfallsback to itself.
To exercise the agent-as-server path manually:
then call the exposed tool twice over one MCP connection and confirm the second
call continues the same ADK conversation.
Checklist
Additional context
The dependency-floor changes in
mcp2.0 (pydantic>=2.12,anyio>=4.9,typing-extensions>=4.13, plus new requiredopentelemetry-apiandmcp-types) are satisfied by ADK's existing constraints.