fix: default encoding_error_handler to 'replace' in StdioServerParameters#2495
fix: default encoding_error_handler to 'replace' in StdioServerParameters#2495Christian-Sidak wants to merge 5 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>
|
Friendly bump -- let me know if anything needs changing. |
1 similar comment
|
Friendly bump -- let me know if anything needs changing. |
|
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.
|
Fixed the coverage gap: branch |
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