fix(fetch): handle malformed input without crashing#3515
Merged
olaservo merged 1 commit intomodelcontextprotocol:mainfrom Mar 15, 2026
Merged
fix(fetch): handle malformed input without crashing#3515olaservo merged 1 commit intomodelcontextprotocol:mainfrom
olaservo merged 1 commit intomodelcontextprotocol:mainfrom
Conversation
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
olaservo
approved these changes
Mar 15, 2026
Member
olaservo
left a comment
There was a problem hiding this comment.
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=Trueat line 288 - Time server omits it (uses SDK default
False) - Git server has the same
Truesetting (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.
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
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.
Summary
Change
raise_exceptions=Truetoraise_exceptions=Falseinmcp-server-fetch/server.pyto prevent the server from crashing on malformed JSON-RPC input.Fixes #3359
Problem
mcp-server-fetchterminates on any malformed JSON-RPC message becauseserver.run()is called withraise_exceptions=True(line 288). A single invalid byte on stdin kills the server process via unhandledExceptionGroup.Fuzz testing from the issue showed:
raise_exceptions=True)raise_exceptions=False)Fix
One-line change:
raise_exceptions=True→raise_exceptions=False, consistent with all other reference servers exceptgit(which also has this issue).Test plan
echo "NOT VALID JSON" | mcp-server-fetchshould no longer crash