fix(fetch): handle malformed input without crashing#3515
Open
anshul-garg27 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(fetch): handle malformed input without crashing#3515anshul-garg27 wants to merge 1 commit intomodelcontextprotocol:mainfrom
anshul-garg27 wants to merge 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
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