Skip to content

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

Merged
olaservo merged 1 commit intomodelcontextprotocol:mainfrom
anshul-garg27:fix/fetch-raise-exceptions
Mar 15, 2026
Merged

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

Conversation

@anshul-garg27
Copy link
Contributor

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
Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-motivated fix. The raise_exceptions=True setting was a debugging aid that causes the server to crash on any malformed JSON-RPC input — the linked issue (#3359) demonstrates 61 out of 65 fuzz test inputs crashing the fetch server.

Changing to raise_exceptions=False (the SDK default) means exceptions are returned as error responses to the client instead of terminating the server process. This is consistent with mcp-server-time, which already uses the default and survives all malformed inputs.

Verified:

  • Fetch server explicitly sets raise_exceptions=True at line 288
  • Time server omits it (uses SDK default False)
  • Git server has the same True setting (good candidate for a follow-up PR)
  • SDK documents this parameter with clear semantics

LGTM — thanks for the contribution @anshul-garg27!


Reviewed with the assistance of Claude Code (claude-opus-4-6). Claims were independently verified against the source code and linked issues.

@olaservo olaservo merged commit 83b2205 into modelcontextprotocol:main Mar 15, 2026
16 of 19 checks passed
nielskaspers pushed a commit to nielskaspers/servers that referenced this pull request Mar 15, 2026
…ocol#3515)

fix(fetch): handle malformed input without crashing

Changes `raise_exceptions=True` to `raise_exceptions=False` in the fetch server's `Server.run()` call, preventing the server from crashing on malformed JSON-RPC input. This aligns with the SDK's intended default behavior and is consistent with other reference servers.

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

2 participants