Skip to content

Fix STDIO server recovery after malformed JSON - #1173

Open
liyifan9642-creator wants to merge 1 commit into
modelcontextprotocol:mainfrom
liyifan9642-creator:fix/1172-stdio-server-json-recovery
Open

liyifan9642-creator wants to merge 1 commit into
modelcontextprotocol:mainfrom
liyifan9642-creator:fix/1172-stdio-server-json-recovery

Conversation

@liyifan9642-creator

Copy link
Copy Markdown

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

  • Jackson 3: 306 selected tests passed; no failures, errors, or skipped tests.
  • Jackson 2: 306 selected tests passed; no failures, errors, or skipped tests.
  • Formatting validation and git diff --check passed.
  • The full Docker-dependent integration suite was not run.

AI assistance

The implementation was assisted by AI and reviewed by me before submission.

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

No deployments
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.

StdioServerTransportProvider stops reading after malformed JSON

1 participant