Skip to content

fix(git): resolve server crash on validation errors#4221

Open
STiFLeR7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
STiFLeR7:feat/git-server-recursion-crash
Open

fix(git): resolve server crash on validation errors#4221
STiFLeR7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
STiFLeR7:feat/git-server-recursion-crash

Conversation

@STiFLeR7
Copy link
Copy Markdown

fix(git): resolve server crash on validation errors

Description

This PR resolves an issue in mcp-server-git where the server process crashes upon encountering input validation errors or malformed JSON-RPC messages (e.g. deeply nested requests that hit Pydantic's core recursion limit) instead of returning a JSON-RPC error response and remaining operational.

Fixes #4213

The Problem

During initialization of mcp-server-git, the stdio server is run with raise_exceptions=True:

await server.run(read_stream, write_stream, options, raise_exceptions=True)

When this option is enabled, any exceptions raised by the stream reader (such as a ValidationError when validating incoming JSON-RPC messages) are re-raised. This causes the internal task group to tear down, resulting in the server process crashing with exit code 1.

Other servers in this repository (e.g. mcp-server-fetch and mcp-server-time) run with the default raise_exceptions=False. Under the default configuration, validation errors on stdin are caught, logged, returned as a JSON-RPC error response where appropriate, and the server process remains active.

The Solution

  1. Modified the server.run(...) call in mcp_server_git/server.py to use raise_exceptions=False to align it with other servers and prevent crashes on invalid/deeply nested JSON-RPC inputs.
  2. Added a unit integration test test_server_handles_invalid_json_rpc_gracefully in src/git/tests/test_server.py that spawns the server, sends a deeply nested JSON-RPC payload triggering a validation error, and asserts that the process exits cleanly (exit code 0) when stdin is closed instead of throwing a traceback and crashing.

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.

[git] raise_exceptions=True

1 participant