Uh oh!
There was an error while loading. Please reload this page.
fix: default encoding_error_handler to 'replace' in StdioServerParameters - #2495
fix: default encoding_error_handler to 'replace' in StdioServerParameters#2495Christian-Sidak wants to merge 6 commits into
Conversation
…ters Match the server-side behavior from PR modelcontextprotocol#2302: replace invalid UTF-8 bytes with U+FFFD so malformed child output surfaces as a JSON parse error in the read stream instead of crashing the transport task group. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Christian-Sidak
commented
Apr 30, 2026
Friendly bump -- let me know if anything needs changing. |
1 similar comment
Christian-Sidak
commented
May 7, 2026
Friendly bump -- let me know if anything needs changing. |
Christian-Sidak
commented
May 14, 2026
Fixed the CI failures: the new test exercises the |
Remove time.sleep(1) so the child exits immediately after writing, then drop the early-break guard. The loop now terminates by exhaustion rather than break, which covers the previously-missing 532->537 branch and restores 100 % coverage.
Christian-Sidak
commented
May 15, 2026
Fixed the coverage gap: branch |
Christian-Sidak
commented
May 16, 2026
Fixed the ruff PERF401 lint error: replaced the |
maxisbey
commented
May 18, 2026
Closing as a duplicate of #2456, which was opened first with the same change plus broader teardown handling. Appreciated the iteration on CI here — thanks for the contribution. |
Summary
stdio_clientcrashed with anExceptionGroupwhen the child process wrote invalid UTF-8 bytes to stdout becauseStdioServerParameters.encoding_error_handlerdefaulted to"strict".This was already fixed on the server side in PR #2302; this PR applies the same one-line fix to the client side.
Change: default
encoding_error_handlerfrom"strict"to"replace"so malformed bytes are replaced with U+FFFD, which then fails JSON parsing and is delivered as an in-streamException— keeping the transport alive for subsequent valid messages.Test
Added
test_stdio_client_invalid_utf8totests/client/test_stdio.py: spawns a child that writesb"\xff\xfe\n"followed by a valid JSON-RPC line, and asserts the first stream item is anExceptionand the second is aSessionMessage.Fixes#2454