fix(client/stdio): default encoding_error_handler to 'replace' for resilient UTF-8 decoding#2907
Open
sarvesh1327 wants to merge 1 commit into
Open
Conversation
…silient UTF-8 decoding Malformed UTF-8 bytes from a child server stdout previously crashed the client transport because the default handler was 'strict'. Changing the default to 'replace' mirrors the server-side fix from PR modelcontextprotocol#2302 and lets the transport survive single bad lines while surfacing them as parse errors for the session to handle. Fixes modelcontextprotocol#2454
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
encoding_error_handlerinStdioServerParametersfrom"strict"to"replace".UnicodeDecodeError."replace", invalid bytes become U+FFFD and the line fails JSON-RPC validation, which is surfaced as an in-streamExceptionthat the session can handle.Test Plan
\xff\xfe\nfollowed by valid JSON-RPC.ValidationError, second item is the validSessionMessage.test_invalid_utf8_from_the_server_surfaces_as_an_in_stream_exception.tests/client/test_stdio.pysuite passes (34 passed, 1 skipped).Notes