Repository navigation
Fix STDIO server recovery after malformed JSON - #1173
Open
liyifan9642-creator wants to merge 1 commit into
Open
liyifan9642-creator wants to merge 1 commit into
liyifan9642-creator wants to merge 1 commit into
Conversation
Return JSON-RPC errors for malformed input and continue processing valid requests through the existing outbound queue. Add wire-level regression coverage for recovery and fatal transport errors. Fixes modelcontextprotocol#1172
This branch has not been deployed
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
Fixes #1172.
Malformed JSON currently terminates the STDIO server's inbound loop and closes the session, preventing subsequent valid requests from being handled.
This change returns -32700 with an explicit id: null for malformed JSON, distinguishes invalid envelopes using -32600, and continues reading subsequent messages. Error responses use the existing outbound queue. Oversized input and I/O failures remain connection-fatal. Public JSONRPCResponse validation remains unchanged; extra parsing only occurs on failed messages.
Regression coverage
Adds 16 cases covering malformed JSON, invalid envelopes and IDs, consecutive bad lines, subsequent valid requests, outbound serialization, oversized input, and I/O failures.
Before the fix, all three malformed-JSON recovery cases failed.
Verification
AI assistance
The implementation was assisted by AI and reviewed by me before submission.