fix(git): handle JSON-RPC errors gracefully instead of crashing#4462
Open
epolat wants to merge 1 commit into
Open
fix(git): handle JSON-RPC errors gracefully instead of crashing#4462epolat wants to merge 1 commit into
epolat wants to merge 1 commit into
Conversation
mcp-server-git passed raise_exceptions=True to server.run(), so a malformed or deeply-nested JSON-RPC message (e.g. params nested past pydantic-core's recursion limit) crashed the process with exit code 1 instead of returning a JSON-RPC error and continuing to serve. Set raise_exceptions=False to match the SDK default and the other reference servers (fetch, time, sqlite). This is the identical fix already merged for mcp-server-fetch in modelcontextprotocol#3515. Fixes modelcontextprotocol#4213. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
mcp-server-gitpassesraise_exceptions=Truetoserver.run(). A malformed or deeply-nested JSON-RPC message (e.g.paramsnested past pydantic-core's recursion limit) crashes the server process with exit code 1 instead of returning a JSON-RPC error and continuing to serve.Fixes #4213.
Root cause
With
raise_exceptions=True, the low-level SDK server re-raises exceptions from message handling instead of logging them and keeping the stream alive.gitis the only reference server that sets this flag —fetch,time, andsqliteall useraise_exceptions=False(the SDK default).Implementation
Flip the single flag in
src/git/src/mcp_server_git/server.pytoFalse. This is the identical fix already merged formcp-server-fetchin #3515.Tests
Existing
tests/test_server.pysuite passes (the git helper-function unit tests do not exerciseserver.run, so they are unaffected).Behavioral reproduction, mirroring #3515's manual test plan — a JSON-RPC request with
paramsnested 300 levels deep sent to the server over stdio:raise_exceptions=True(before)1json_invalidtracebackraise_exceptions=False(after)0Received exception from stream: ...); server keeps serving and shuts down cleanlyEdge cases
Any malformed / oversized / deeply-nested payload now yields a graceful, logged error instead of terminating the process. Well-formed requests are unaffected.
Backward compatibility
Fully backward compatible. No API, tool, or output changes — only the failure mode for invalid input changes (crash → graceful error), which is strictly an improvement and brings
gitin line with the other reference servers.