| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…F-8 resilience The stdio_client transport previously defaulted to encoding_error_handler= strict, causing the transport to crash when the child process emits invalid UTF-8 bytes. This is asymmetric with the server-side fix in PR modelcontextprotocol#2302, which already uses errors=replace for stdio_server. Changes: - Default StdioServerParameters.encoding_error_handler to replace - Invalid bytes are now substituted with U+FFFD and the resulting line fails JSON validation, surfacing as an in-stream Exception - The transport stays alive for subsequent valid messages - Changed logger.exception to logger.warning for parse failures (avoids noisy tracebacks for expected validation errors) - Removed pragma: no cover from the now-reachable exception handling path Add regression test that spawns a child emitting invalid UTF-8 followed by a valid JSON-RPC message, asserting both are delivered correctly. Fixes modelcontextprotocol#2454
|
Closing as a duplicate of #2456. This PR also changes logger.exception() to logger.warning(), which goes against the project's exception-handling guidelines in AGENTS.md. Thanks for the contribution. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #2454
Summary
The stdio_client transport crashes when the spawned child process writes invalid UTF-8 bytes to stdout. The transport decodes child stdout with encoding_error_handler="strict" by default, so malformed bytes raise during TextReceiveStream iteration. That exception escapes the decoding loop and brings down the transport task group instead of surfacing the bad line as an in-stream parse error.
Asymmetry with server side
The SDK already hardened the server side for the analogous case in PR #2302 (fix: handle non-UTF-8 bytes in stdio server stdin). That change explicitly preferred:
The client side was still using "strict", creating an inconsistency.
Changes
src/mcp/client/stdio.py
tests/client/test_stdio.py
Backward compatibility