Repository navigation
google_genai: accept MCP Python SDK v1 or v2 in the mcp extra - #424
Merged
Merged
Conversation
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
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.
brianstrauch
approved these changes
Nov 10, 2026
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.
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.
What was changed
This PR makes the extra accept both:
mcp>=1.24,<3.pyproject.toml: themcpextra and the dev group now ask formcp>=1.24,<3. The lock stays on mcp 1.30.0, likegoogle_adk. So PR CI tests v1, and the nightly run (uv lock --upgrade) tests v2._temporal_mcp.py: v2 removedmcp.shared.session, so importingTemporalMcpClientSessionfailed withModuleNotFoundError.ProgressFnTnow comes frommcp.shared.dispatcheron v2 and falls back tomcp.shared.sessionon v1.call_tooltakesread_timeout_secondsas afloat(v2) or atimedelta(v1). The shim still ignores it, as before.MCPServeron v2 and falls back toFastMCPon v1, as in Fix Google ADK test servers with MCP 2 #420. The in-memory session usesmcp.Clienton v2 andcreate_connected_server_and_client_sessionon v1.failtool, and theGeminiTestServertest checks that its result reaches the model as an error.test_mcp_replayalso replaystests/histories/mcp_v1_tool_calls.json, recorded onmain(3363a79) with mcp 1.30.0. So the nightly run checks that v2 workers replay v1 histories.Why?
Want to use Gemini with client-side MCP next to our other MCP integrations? Today you can't. The
mcpextra oftemporalio-google-genaineeds MCP Python SDK v1, buttemporalio-openai-agents[mcp],temporalio-mcpandtemporalio-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/inputSchemawhen it converts tools, andis_error/isErrorin automatic function calling. This package already needs 2.21.0 or later. And google-genai's own test requirements still pinmcp<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,cacheScopeandexecution.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:
structuredContentthat is an array or a scalar. v1 only accepts an object there (dict[str, Any] | None).notes.txt, inresource_linkor embeddedresourcecontent. v1 types them asAnyUrl, v2 asstr.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
CallToolResultandListToolsResultbetween 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.txthas 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 getsis_error,structured_contentandresult_typeinstead ofisErrorandstructuredContent. That's the same as using google-genai directly with mcp v2.Checklist
Fixes [Feature Request] google_genai: support MCP SDK v2 in the mcp extra #415
How was this tested:
make test(171 passed),make lint(all steps pass) andscripts/ci/check_conventions.py.make sync-latest: mcp 2.3.0, google-genai 2.33.0, temporalio 1.35.0):make test(171 passed) andmake lint(all steps pass).main, so it also covers upgrading from the current release.ClientSession, on mcp 1.30.0 and 2.3.0.structuredContentlimit: a v2-encodedCallToolResultwithstructuredContent=[1,2]decodes on mcp 2.3.0 and fails validation on mcp 1.30.0 ("Input should be an object").CallToolResultwith aresource_linktonotes.txtdecodes 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.txtdecodes on both.Let me know what you think!