Repository navigation
Conversation
A request line that fails validate_json (e.g. carrying a lone surrogate escape, which pydantic-core rejects) was dropped with no reply, so the client's call hung until its own timeout. Reply -32700 per JSON-RPC 2.0, echoing the request id recovered from the raw line with stdlib json - it tolerates the escapes pydantic-core rejects - or null when the id cannot be recovered. Notification-shaped lines (an object without an id member, the same key-presence rule as the streamable-HTTP entry) are never answered. Fixes modelcontextprotocol#3894
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3894. If a maintainer assigns you to #3894, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
What & why
A stdio server dropped any request line that failed JSON-RPC validation with no reply on the wire and nothing on stderr, so the client's call hung until its own timeout. Reported in #3894: a lone surrogate escape like
\ud83d— whichjson.dumpsemits for text cut mid-emoji — is rejected by pydantic-core even though the line is pure ASCII.The transport now answers such a line with a JSON-RPC Parse error (-32700, per JSON-RPC 2.0):
jsontolerates the escapes pydantic-core rejects, so an SDK client's pending call for that id resolves instead of hanging;"id": nullwhen the id cannot be recovered (e.g. the line is not JSON at all);idmember — the same key-presence rule the streamable-HTTP entry uses) are never answered, per JSON-RPC 2.0 §4.1.The failure is also logged, so it is visible on stderr.
Why at the transport layer
The dispatcher's
on_stream_exceptionpath can't recover the id (validation failed before the id was parsed), and the server never sets an observer, so a dispatcher-level default could only emit"id": null— which an SDK client can't correlate, leaving the hang this issue is about. Only the stdio reader still has the raw line. The SSE transport already answers its own parse failures (HTTP 400) and the streamable-HTTP entries answer theirs; stdio was the only transport that stayed silent.Tests
test_stdio_server_answers_an_invalid_line_with_a_parse_error— parametrised over not-JSON, non-object, and lone-surrogate lines; asserts the reply (recovered id / null) and that serving continues.test_stdio_server_does_not_answer_a_notification_shaped_linetest_stdio_server_drops_the_parse_error_reply_when_the_write_stream_is_closedtest_mcpserver_run_stdio_answers_a_malformed_line_and_keeps_serving— end-to-end throughrun("stdio")with the exact line from the issue.Coverage for
src/mcp/server/stdio.pystays 100%;strict-no-cover, ruff, and pyright (strict) pass.Fixes #3894
Note
AI-assisted: this PR was prepared with the help of an AI coding agent; the change, reasoning, and tests were reviewed and are owned by the author.