Skip to content

fix: keep stdio client reading after a malformed response - #1158

Open
hpdkhoa wants to merge 1 commit into
modelcontextprotocol:mainfrom
hpdkhoa:fix/stdio-malformed-response-recovery
Open

hpdkhoa wants to merge 1 commit into
modelcontextprotocol:mainfrom
hpdkhoa:fix/stdio-malformed-response-recovery

Conversation

@hpdkhoa

@hpdkhoa hpdkhoa commented Oct 2, 2026

Copy link
Copy Markdown

The stdio client's inbound loop stopped at the first message it could not deserialize. It then marked the transport as closing and completed the inbound stream, so the request answered by that message timed out and so did every later request on the same client, including ping.

A message that fails to deserialize no longer ends the loop. If it is a response with a usable id, the transport emits an error response for that id, so the matching request fails right away with an internal error. A line that is not JSON at all is logged and skipped.

The new test runs a server process that sends a response without jsonrpc, a response with both result and error, a line that is not JSON, and then a valid response, and checks that the two malformed responses fail their requests and the valid one still arrives.

Fixes #1157

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The stdio client's inbound loop stopped at the first message it could not
deserialize. It then marked the transport as closing and completed the
inbound stream, so the request answered by that message timed out and so
did every later request on the same client, including ping.

A message that fails to deserialize no longer ends the loop. If it is a
response with a usable id, the transport emits an error response for that
id, so the matching request fails right away with an internal error. A
line that is not JSON at all is logged and skipped.

The new test runs a server process that sends a response without jsonrpc,
a response with both result and error, a line that is not JSON, and then a
valid response, and checks that the two malformed responses fail their
requests and the valid one still arrives.

Fixes modelcontextprotocol#1157

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.

Stdio client stops processing responses after rejecting a malformed response

1 participant