Skip to content

google_genai: accept MCP Python SDK v1 or v2 in the mcp extra - #424

Merged
campoy merged 6 commits into
mainfrom
fix/google-genai-mcp-v2
Nov 10, 2026
Merged

campoy merged 6 commits into
mainfrom
fix/google-genai-mcp-v2

Conversation

@campoy

@campoy campoy commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

This PR makes the extra accept both: mcp>=1.24,<3.

  • pyproject.toml: the mcp extra and the dev group now ask for mcp>=1.24,<3. The lock stays on mcp 1.30.0, like google_adk. So PR CI tests v1, and the nightly run (uv lock --upgrade) tests v2.
  • _temporal_mcp.py: v2 removed mcp.shared.session, so importing TemporalMcpClientSession failed with ModuleNotFoundError. ProgressFnT now comes from mcp.shared.dispatcher on v2 and falls back to mcp.shared.session on v1. call_tool takes read_timeout_seconds as a float (v2) or a timedelta (v1). The shim still ignores it, as before.
  • Tests: the echo server uses MCPServer on v2 and falls back to FastMCP on v1, as in Fix Google ADK test servers with MCP 2 #420. The in-memory session uses mcp.Client on v2 and create_connected_server_and_client_session on v1.
  • More tests: the echo server also has a fail tool, and the GeminiTestServer test checks that its result reaches the model as an error. test_mcp_replay also replays tests/histories/mcp_v1_tool_calls.json, recorded on main (3363a79) with mcp 1.30.0. So the nightly run checks that v2 workers replay v1 histories.
  • README and docstrings now say "MCP Python SDK v1 or v2". The README also documents the replay limits across majors (more on that below).

Why?

Want to use Gemini with client-side MCP next to our other MCP integrations? Today you can't. The mcp extra of temporalio-google-genai needs MCP Python SDK v1, but temporalio-openai-agents[mcp], temporalio-mcp and temporalio-strands-agents[mcp] need v2. So you have to pick one. (Not a fun choice.)

Why both majors, and not just v2? Because that's what google-genai does. Since 2.18.0, its MCP code reads both the v1 and v2 field names: input_schema / inputSchema when it converts tools, and is_error / isError in automatic function calling. This package already needs 2.21.0 or later. And google-genai's own test requirements still pin mcp<2.

So accepting both keeps v1 users working and lets v2 users install the extra.

Will my running Workflows notice?

Mostly no. This change is Compatible, and v1 users change nothing.

Activity names ({server}-list-tools, {server}-call-tool), the call-tool input and the result payloads stay the same. The Pydantic converter writes MCP results with their camelCase wire names on both majors (inputSchema, isError). v2 only adds fields that v1 keeps as extras: resultType, ttlMs, cacheScope and execution.

You don't trust me? You don't need to. I recorded a run with one tool call and one failing tool call on mcp 1.30.0, and another on mcp 2.3.0. Then I replayed each history on the other major. Both replays pass, and the error flag decodes correctly both ways.

So what breaks?

Two things, both tool results that v2 accepts and v1 rejects:

  • structuredContent that is an array or a scalar. v1 only accepts an object there (dict[str, Any] | None).
  • Resource URIs that aren't full URLs, such as notes.txt, in resource_link or embedded resource content. v1 types them as AnyUrl, v2 as str.

A history that records such a result replays on v2 only. On v1 it fails with "Failed decoding arguments". Tool schemas, object results and full URLs are fine. I compared every field of CallToolResult and ListToolsResult between mcp 1.30.0 and 2.3.0, and these are the only two.

The README says so. If your servers return those results, keep v1 workers off the Task Queue while you upgrade, and don't roll back to v1 while those Workflows are running.

Why not rewrite these results in the plugin? Because that would change what Gemini receives. The plugin would no longer behave like google-genai used directly with mcp v2. (And notes.txt has no correct full URL to rewrite to.)

Why not decode them leniently on v1? That only helps v1 workers that already run this release, not a rollback to 0.1.0. The README rule covers both.

What does the model see?

One change on v2. google-genai puts the MCP tool result into the function response with model_dump(), without aliases. So Gemini gets is_error, structured_content and result_type instead of isError and structuredContent. That's the same as using google-genai directly with mcp v2.

Checklist

  1. Fixes [Feature Request] google_genai: support MCP SDK v2 in the mcp extra #415

  2. How was this tested:

  • Committed lock (mcp 1.30.0, google-genai 2.24.0, temporalio 1.34.0): make test (171 passed), make lint (all steps pass) and scripts/ci/check_conventions.py.
  • Newest allowed dependencies, as in the nightly run (make sync-latest: mcp 2.3.0, google-genai 2.33.0, temporalio 1.35.0): make test (171 passed) and make lint (all steps pass).
  • Oldest allowed v2 (mcp 2.0.0, google-genai 2.21.0): the MCP tests pass.
  • Replay across majors, as above. I recorded the v1 history on main, so it also covers upgrading from the current release.
  • Against google-genai used directly: with a text tool, a failing tool, a dict result and a resource link, the plugin sends Gemini the same tool declarations and function responses as google-genai with a live ClientSession, on mcp 1.30.0 and 2.3.0.
  • The structuredContent limit: a v2-encoded CallToolResult with structuredContent=[1,2] decodes on mcp 2.3.0 and fails validation on mcp 1.30.0 ("Input should be an object").
  • The URI limit: a v2-encoded CallToolResult with a resource_link to notes.txt decodes on mcp 2.3.0 and fails validation on mcp 1.30.0 ("Input should be a valid URL, relative URL without a base"). file:///notes.txt decodes on both.
  1. Any docs updates needed? Done in this PR: the README and docstrings now say "MCP Python SDK v1 or v2", and the README documents the replay limits across majors.

Let me know what you think!

The mcp extra needed mcp<2, so client-side MCP with Gemini could not be
installed next to the other Temporal MCP integrations, which need v2.

MCP v2 removed mcp.shared.session, so importing TemporalMcpClientSession
failed. Import ProgressFnT from mcp.shared.dispatcher and fall back to
mcp.shared.session on v1. google-genai already reads both majors' field
names. Activity names and payloads are unchanged.

The lock stays on mcp 1.30.0; the nightly run tests v2.

Fixes #415
@campoy
campoy marked this pull request as ready for review November 5, 2026 01:36
@campoy
campoy requested a review from a team as a code owner November 5, 2026 01:36
MCP v2 types resource URIs as plain strings, but MCP v1 requires a full
URL. A v2 history with a resource_link URI such as notes.txt fails to
decode on a v1 worker, like non-object structuredContent.
The echo server gets a fail tool. The GeminiTestServer test calls it and
checks that the model gets the result as an error, which depends on
google-genai reading isError (MCP v1) or is_error (MCP v2).

test_mcp_replay also replays a history recorded on 3363a79 (main before
MCP v2 support) with mcp 1.30.0. The nightly run installs MCP v2, so
there it checks that a v2 worker replays a v1 worker's history.
@campoy
campoy merged commit cb2e079 into main Nov 10, 2026
27 checks passed
@campoy
campoy deleted the fix/google-genai-mcp-v2 branch November 10, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] google_genai: support MCP SDK v2 in the mcp extra

2 participants