adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Support mcp 2.x (Python SDK): pin blocks mcp 2.0.0

Open SiAgentBuild opened this issue 4 months ago • 5 comments

Summary

adk-python currently pins the MCP Python SDK to the 1.x line and cannot be installed alongside mcp 2.0.0 (released 2026-07-28). This issue tracks the breaking changes in mcp 2.0 that affect the MCP tooling.

Current constraint

mcp>=1.24,<2 — pyproject.toml:86 (also referenced at :198, :246).

Breaking changes in mcp 2.0 that affect adk-python

In src/google/adk/tools/mcp_tool/, verified against the installed mcp==2.0.0 SDK:

  1. ClientSession(read_timeout_seconds=timedelta(...)) now takes a float.

    • session_context.py:324 and :338 — pass a float of seconds instead of timedelta.
  2. camelCase attribute reads on mcp.types → snake_case.

    • mcp_tool.py:204-205 — ._mcp_tool.inputSchema → input_schema, and .outputSchema → output_schema.
  3. McpError renamed → MCPError.

    • mcp_tool.py:31 — import; mcp_tool.py:378 — except McpError. In 2.0 the name is MCPError (constructor MCPError(code, message, data=None)).
  4. Lowlevel mcp.server.fastmcp server API. _agent_to_mcp.py:26-27 builds a server via the in-SDK mcp.server.fastmcp.FastMCP, whose surface changed in 2.0 — this server-side path should be re-verified.

Notes

  • The streamable-HTTP client is already 2.0-ready: mcp_session_manager.py:66-68, 129-133 uses the new streamable_http_client name with the http_client= kwarg. The blockers are the three items above plus the server-side FastMCP path. A stale docstring reference to the old name at session_context.py:105 is cosmetic.
  • Dependency-floor updates. mcp 2.0 requires pydantic>=2.12, anyio>=4.9, typing-extensions>=4.13, and adds required deps opentelemetry-api and mcp-types (exact-pinned to the SDK version); the SDK's HTTP layer moved from httpx/httpx-sse to httpx2>=2.5.0.

Happy to help with a PR if the maintainers are open to it.

SiAgentBuild avatar Jul 31 '26 02:07 SiAgentBuild

Hi @ProgrammerPlus1998, thank you for the feature request! Since you already have a solution in mind, please feel free to open a PR. Our team would be happy to review it.

sanketpatil06 avatar Jul 31 '26 06:07 sanketpatil06

I'd like to pick this up, and I have a question for maintainers that decides how I should do it.

Context: I filed #6826 (MCP Tasks extension, SEP-2663), which only makes sense on top of the 2.x bump — the extensions / result_claims / notification_bindings seam on ClientSession does not exist in 1.x. So I need this to land, and I'm happy to do the work.

#6537 from @ProgrammerPlus1998 is a good map of the mechanical changes, but it has drifted: its base is ~350 commits behind main, it is CONFLICTING, and two of its hunks have since been superseded upstream — 4e68bad1 already reworked the agent-server connection keying it changes, and 69a3ca5e touched the session_context.py lines carrying the timedelta→float conversion. Rather than rebase it, I'd rather redo it on current main and carry Co-authored-by: for the parts I reuse — with @ProgrammerPlus1998's blessing, of course.

The question

Are mcp==2.0.0, mcp-types==2.0.0 and httpx2 importable into google3 yet?

I ask because it changes what is useful for me to send. If the internal import is still pending, a bump PR from me just sits in the same queue #6537 is in, and it may be better for maintainers to land the bump internally while I contribute only the extension seam and the Tasks work on top. If the packages are available, I'll send the bump PR.

Two things worth knowing before this lands

While verifying against the released 2.0.0 wheels, I hit two items that aren't in #6537's diff and that I think matter for review:

1. mcp 2.0 depends on httpx2, not httpx (Requires-Dist: httpx2>=2.5.0; the 2.0 venv contains no httpx at all). streamable_http_client(http_client=...) expects an httpx2.AsyncClient. That reaches further into ADK than the import renames do — create_mcp_http_client, _DebugHttpxClientFactory, and the mTLS bridge _GoogleAuthAsyncTransport / _SharedAsyncTransport in mcp_session_manager.py all build httpx objects today. Also, opentelemetry-instrumentation-httpx instruments httpx, so MCP HTTP client spans go away until an httpx2 instrumentor exists (_meta trace propagation in mcp_tool.py is unaffected). None of this is hard, but it is the bulk of the real work and it deserves a maintainer opinion on the OTel regression.

2. A silent behavior change in tool results. mcp 1.x models use camelCase field names; 2.x models are snake_case with camelCase aliases. ADK dumps tool results with response.model_dump(exclude_none=True, mode="json") (mcp_tool.py:511, and mcp_toolset.py:597). Verified against 2.0.0:

CallToolResult(content=[...], is_error=True).model_dump(exclude_none=True, mode="json")
# 1.x-equivalent keys: ['content', 'isError']
# 2.x actual keys:     ['content', 'is_error', 'result_type']   # <-- no by_alias
# 2.x with by_alias:   ['content', 'isError', 'resultType']

Without by_alias=True the payload every MCP tool hands back to the model changes shape, and _detect_error_in_response (which reads 'isError', mcp_tool.py:530) silently stops detecting tool errors. So the bump needs by_alias=True at those dump sites. Note that even then, resultType is a new key with no 1.x equivalent — parity is close but not exact, and I think that's worth calling out in the changelog rather than papering over.

Separately, 2.0's call_tool enforces output-schema validation, so servers that declare an output schema and return no structuredContent will newly raise. That's upstream's intended behavior, but it is a user-visible change for ADK.

Happy to go whichever way you prefer — just let me know on the google3 question and I'll start.

zeishr avatar Aug 21 '26 10:08 zeishr

Update: I have the migration working locally — the full unit suite passes against mcp==2.0.0 (11939 passed, 0 failed). But regenerating the constraints turned up a blocker that I don't think a contributor should decide, so here it is before I open anything.

crewai and the mcp pin, corrected

Correction, 2026-08-24. The first version of this comment said the 2.x bump walks crewai back from 1.15.5 to 1.6.1, "eight months of regression". That attribution was wrong, and it made the bump look more expensive than it is. Re-verified below; the original text is in this comment's edit history.

The fact that holds: every published crewai release requires mcp~=1.28.1, up to and including 1.15.17 (2026-08-20). pyproject.toml pulls crewai[tools] for python_version>='3.11' and python_version<'3.12' (the all, extensions and test extras).

So scripts/update_constraints.sh --check does fail on all five files, and on 3.11 the constrained resolution is genuinely unsatisfiable rather than merely stale:

Because crewai==1.15.5 depends on mcp>=1.28.1,<1.29.dev0 and google-adk
depends on crewai{python_full_version < '3.12'}==1.15.5, we can conclude
that google-adk depends on mcp>=1.28.1,<1.29.dev0.
And because google-adk depends on mcp>=2,<3, we can conclude that your
requirements are unsatisfiable.

What I got wrong is what happens next. The script's fallback re-resolves without the stable pinset and lands on crewai==1.6.1 — but that is already where a fresh resolve lands today with the mcp>=1.24,<2 pin untouched. ~=1.28.1 excludes mcp 1.29.0 as well as 2.x, and the resolver prefers the newer mcp:

# unmodified pyproject.toml, mcp>=1.24,<2, no constraint file, 3.11, --all-extras
crewai==1.6.1
mcp==1.29.0

Same result at the constraints' own --exclude-newer 2026-08-09 and at today's date. It is also what #6636 reports independently: a uv sync --all-extras on 3.11, on 2026-08-13, with crewai 1.6.1 installed. The crewai==1.15.5 in constraints-3.11.txt is a leftover from when the trade went the other way, not something the current graph would reproduce.

The real cost of the bump is narrower, and it is an option rather than a version. With mcp 1.x you can still hold crewai high by accepting the older mcp — forcing crewai>=1.15 resolves to crewai==1.15.14 with mcp==1.28.1. With mcp>=2 that combination is unsatisfiable, so the choice disappears.

The blast radius, unchanged from what I said before — this is a --all-extras problem, not an install problem:

  • core install: fine, mcp isn't a core dependency
  • --extra mcp on 3.11: resolves to mcp==2.0.0, mcp-types==2.0.0, httpx2 cleanly
  • --extra test on 3.11: also resolves, at crewai==1.6.1
  • --all-extras (what generates the constraints): the failure above
  • Python 3.10, 3.12, 3.13, 3.14: unaffected, since the crewai marker is 3.11-only

So the question I should have asked is narrower than the one I did: regenerating the constraints will move constraints-3.11.txt to crewai==1.6.1 whether or not this bump lands, and the bump additionally forecloses pinning mcp back to 1.28.1 to avoid that. Are you content to let 3.11 --all-extras sit at crewai==1.6.1, or would you rather crewai[tools] come out of the 3.11 extras (it is already fenced to one version because "chromadb/pypika fail on 3.12+")? Either way I would rather have your answer than guess.

What I have ready either way

The source migration is done and green, independent of how the constraints question lands:

  • the renames and moves (MCPError and its new (code, message) constructor, ProgressFnT → mcp.shared.dispatcher, FastMCP → mcp.server.mcpserver.MCPServer, read_timeout_seconds timedelta → float, snake_case model fields, local restatement of the now-private McpHttpClientFactory protocol)
  • the httpx → httpx2 move across the session manager's client factory, debug hooks and google-auth mTLS bridge
  • by_alias=True at the result dump sites, plus the mcp telemetry golden regenerated through python -m tests.unittests.telemetry.regenerate — the diff there is exactly two added "resultType": "complete" keys with isError preserved, which is the clean demonstration that the parity fix works and that resultType is the one unavoidable delta
  • the in-memory test helper rebuilt on create_client_server_memory_streams, since create_connected_server_and_client_session is gone
  • httpx2 added to the entry-point import allowlist, for the same reason httpx was already on it

Two latent bugs fell out of it, both the same shape — reading a camelCase field that no longer exists:

  1. load_mcp_resource_tool.py read content.mimeType, so every binary MCP resource silently became [Binary content for … could not be decoded].
  2. _experimental_semconv.py looked up model_dump.get('parameters') or model_dump.get('inputSchema'), so experimental telemetry recorded parameters: null for MCP tools.

Both are fixed. Say the word on crewai and I'll open the PR.

zeishr avatar Aug 21 '26 10:08 zeishr

The bump landed. 856acf21 on main (2026-09-03) widens the pin to mcp>=1.24,<3 and makes the MCP tooling run on either major: the moved names are resolved once in src/google/adk/dependencies/_mcp.py behind an IS_MCP_SDK_V2 flag, httpx/httpx2 is paired to the installed SDK in the new dependencies/_httpx.py, and a unit-test-mcp-v2 CI job reinstalls 2.x and re-runs the MCP tests on five interpreters.

That answers the question I asked here on 21 August. It came in through Copybara (PiperOrigin-RevId: 975915236), so the internal import is evidently no longer the obstacle, and the bump was never mine to send — I'm withdrawing that offer, there is nothing left for me to contribute on this issue.

One note for anyone arriving from the constraints angle: supporting both majors sidesteps the trade I flagged on 24 August entirely. That problem came from crewai[tools] requiring mcp~=1.28.1 on 3.11 while ADK demanded mcp>=2, which made the constrained resolution unsatisfiable. With <3, and the lock still resolving 1.x, the conflict does not arise, and 2.x gets covered by the dedicated job instead. Better outcome than what I had proposed.

@ProgrammerPlus1998 — #6537 is superseded by 856acf21, and its cla/google check passes now, in case that was what held it up. Thanks for the mapping; my offer to redo it carrying your attribution is moot.

Could a maintainer close this issue and #6537? The pin is on main, and leaving this open under needs review points people at a dead PR. The remaining piece is #6826, the client extension seam, which 856acf21 does not touch. I'll follow up there rather than here.

zeishr avatar Sep 09 '26 10:09 zeishr

the pin is mcp>=1.24,<3 on main in 856acf21 and the tooling runs on either major, shipping in the next release. #6537 is superseded, since main kept 1.x working. on otel, the instrumentor is built against httpx 1.x, so under 2.x mcp calls go untraced rather than breaking. the client extension seam stays open as #6826. open a new issue if you see anything like this again.

GWeale avatar Sep 11 '26 21:09 GWeale