Repository navigation
fix(py/mcp): allow mcp 2.x - #164
Closed
huangjeff5 wants to merge 1 commit into
Closed
huangjeff5 wants to merge 1 commit into
huangjeff5 wants to merge 1 commit into
Conversation
Widen genkit-mcp to mcp>=1.26.0,<3. mcp 2 renames McpError to MCPError, moves protocol fields to snake_case, replaces get_server_capabilities() with a property, takes float-second timeouts, and reports request timeouts as -32001 instead of 408. genkit_mcp._compat detects each from the installed SDK, so the plugin runs unchanged on 1.x and 2.x. mcp 2 also reports a dead transport to the request instead of raising it out of stdio_client, so the connection now logs the failure it recorded when the owner unwinds without an exception of its own. The test server registers handlers through either SDK's API, and the malformed-reply case writes raw JSON-RPC since mcp 2 validates handler results. mcp-hello moves to MCPServer and mcp>=2,<3.
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.
genkit-mcp capped
mcp<2, but mcp 2.0 shipped 2026-07-28 (latest 2.3.0). Anyone already on mcp 2.x couldn't install genkit-mcp. This widens the range tomcp>=1.26.0,<3; the plugin works on both majors.Main Changes
_compat.py, detected from the SDK, not its version: mcp 2 renamedMcpErrortoMCPError, moved the timeout error code from 408 to -32001, takes float seconds instead oftimedelta, replacedget_server_capabilities()with a property, and reads protocol fields in snake_case. Each one is looked up withgetattr/hasattr, so the rest of the plugin doesn't branch on versions and the module type-checks against either.model_validate({'isError': True}): On mcp 1.x, passingis_error=Trueas a keyword is silently kept as an unknown extra, so the result would not read as an error. Validating the wire-shaped dict sets the right field on both majors.CONNECTION_CLOSEDinstead of raisingBrokenResourceErrorout ofstdio_client, so the owner task exits without an exception and the end-of-connection log never fired. It now logs on theelse:path too; theexceptandelsepaths are exclusive, so 1.x doesn't log twice.samples/mcp-hellomoves to mcp 2: The workspace locks a single mcp version, and mcp 2 removedmcp.server.fastmcp, so the sample usesmcp.server.mcpserver.MCPServerand requiresmcp>=2,<3.Verification
pytest packages/genkit-mcp: 256 passed at mcp 1.26.0 (floor) and 1.29.1 (latest 1.x); 254 passed, 2 skipped at 2.3.0 (lock).samples/mcp-hello: 7 passed against a realMCPServerchild.check_consistency.pyanduv lock --checkclean.Open questions
traceparentto each request from the current context. Our requests run in the connection's owner task, which copied the first caller's context, so with genkit-google-cloud telemetry enabled, later MCP requests could parent to the wrong trace. Dev UI isn't affected. Fix would be running each request under the caller'scontextvars.copy_context(). Not done here; flagging it as new 2.x behavior, not a regression._CLOSE_GRACE_SECONDScan't cut it short. Test bound is <3.5s on 2.x vs <1.5s on 1.x.