fix(git): migrate to MCP Python SDK v2 constructor-based API - #4606
Open
droidada wants to merge 1 commit into
Open
fix(git): migrate to MCP Python SDK v2 constructor-based API#4606droidada wants to merge 1 commit into
droidada wants to merge 1 commit into
Conversation
Fixes modelcontextprotocol#4580. The v1 decorator based handlers (@server.list_tools, @server.call_tool) no longer exist in v2; the low-level Server now takes handlers as on_* constructor arguments. Also pins mcp>=2,<3 in pyproject.toml, the missing upper bound was the actual root cause: an unconstrained mcp>=1.0.0 let a fresh install silently resolve to the incompatible v2 SDK. Also removes the unused list_repos()/by_roots() helper, confirmed dead via grep, which relied on the now-removed ambient server.request_context property.
droidada
force-pushed
the
fix/4580-mcp-v2-migration
branch
from
August 3, 2026 15:42
aa56a79 to
985bfce
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.
Fixes #4580. The v1 decorator based handlers (@server.list_tools, @server.call_tool) no longer exist in v2; the low-level Server now takes handlers as on_* constructor arguments. Also pins mcp>=2,<3 in pyproject.toml, the missing upper bound was the actual root cause: an unconstrained mcp>=1.0.0 let a fresh install silently resolve to the incompatible v2 SDK.
Also removes the unused list_repos()/by_roots() helper, confirmed dead via grep, which relied on the now-removed ambient server.request_context property.
Description
Migrates mcp-server-git from the MCP Python SDK v1 decorator API to the v2 constructor-based API, and fixes the dependency constraint that let this break in the first place.
Server Details
Motivation and Context
mcp-server-git fails to start after a fresh install with
AttributeError: 'Server' object has no attribute 'list_tools'. Root cause:pyproject.tomldeclaredmcp>=1.0.0with no upper bound, so a fresh install now resolves the v2 SDK, which removed the decorator-based handler API entirely.While migrating, I also found and fixed a real regression: v2 removed automatic exception wrapping in the lowlevel Server (handler exceptions no longer become
CallToolResult(isError=True)automatically). I confirmed this directly, callinggit_diffwith an invalid target correctly raisedBadNameinside the validation logic, but the exception propagated as an unhandled crash instead of a clean error response.handle_call_toolnow wraps its body in try/except and returnsCallToolResult(is_error=True, ...)explicitly, restoring v1's behavior. Without this fix, every one of this server's existing defense-in-depth validation checks (ingit_diff,git_create_branch,git_checkout,git_show, andgit_branch) would silently crash the request instead of returning a usable error.How Has This Been Tested?
Tested with the MCP Inspector CLI against a real client, not just the existing test suite:
mcp==2.0.0actually installed (uv pip show mcp), not assumedtools/listreturns all twelve tools with correct schemas and correct camelCase wire formattools/callforgit_logreturns real commit history end to endgit_diffwithtarget=-xnow returns a cleanisError: trueresult with a readable message, instead of the unhandled crash it produced before the fixBreaking Changes
None for end users of the published server. Internal handler registration changed from decorators to constructor arguments, which only affects contributors to this file directly.
Types of changes
Checklist
Additional context
None of the underlying git validation logic changed,
BadNamechecks, flag-injection defense in depth, and repo path validation are all unchanged. Only the SDK integration layer and error handling shape changed.