Skip to content

fix(fetch): handle malformed input without crashing#3515

Open
anshul-garg27 wants to merge 1 commit intomodelcontextprotocol:mainfrom
anshul-garg27:fix/fetch-raise-exceptions
Open

fix(fetch): handle malformed input without crashing#3515
anshul-garg27 wants to merge 1 commit intomodelcontextprotocol:mainfrom
anshul-garg27:fix/fetch-raise-exceptions

Conversation

@anshul-garg27
Copy link

Summary

Change raise_exceptions=True to raise_exceptions=False in mcp-server-fetch/server.py to prevent the server from crashing on malformed JSON-RPC input.

Fixes #3359

Problem

mcp-server-fetch terminates on any malformed JSON-RPC message because server.run() is called with raise_exceptions=True (line 288). A single invalid byte on stdin kills the server process via unhandled ExceptionGroup.

Fuzz testing from the issue showed:

Server Crashes Survives
mcp-server-fetch (raise_exceptions=True) 61/65 4/65
mcp-server-sqlite (raise_exceptions=False) 0/65 65/65

Fix

One-line change: raise_exceptions=Trueraise_exceptions=False, consistent with all other reference servers except git (which also has this issue).

Test plan

  • echo "NOT VALID JSON" | mcp-server-fetch should no longer crash
  • Normal JSON-RPC requests should continue to work
  • Verify behavior matches mcp-server-sqlite and mcp-server-time

mcp-server-fetch crashes on any malformed JSON-RPC input because
server.run() is called with raise_exceptions=True. A single invalid
byte on stdin terminates the server process via unhandled
ExceptionGroup.

Change to raise_exceptions=False to match the behavior of other
reference servers (e.g., mcp-server-time, mcp-server-sqlite) which
handle parse errors gracefully and continue serving.

Fuzz testing showed fetch crashed on 61/65 test cases while other
servers using raise_exceptions=False survived all 65.

Fixes modelcontextprotocol#3359
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.

mcp-server-fetch: Server crashes on any malformed input due to raise_exceptions=True

1 participant