fix: set newline='' on TextIOWrapper in stdio_server to prevent Windows CRLF corruption#2574
Open
EvanYao826 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: set newline='' on TextIOWrapper in stdio_server to prevent Windows CRLF corruption#2574EvanYao826 wants to merge 2 commits intomodelcontextprotocol:mainfrom
EvanYao826 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…ws CRLF corruption On Windows, TextIOWrapper defaults to platform-native line endings (\r\n), which corrupts newline-delimited JSON-RPC messages over stdio. Add newline='' to both the stdin and stdout TextIOWrapper constructors in stdio_server(), matching the pattern from PR modelcontextprotocol#2302. Fixes modelcontextprotocol#2433
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.
Fixes #2433
Summary
On Windows,
TextIOWrapperdefaults to platform-native line endings (), which corrupts newline-delimited JSON-RPC messages over stdio. The server-sidestdio_server()wrapssys.stdoutin aTextIOWrapperwithout specifyingnewline=, so anyin the JSON payload gets converted to, breaking clients that parse on.Fix
Add
newline=to theTextIOWrapperconstructor instdio_server(), matching the pattern already used in the server-side fix from PR #2302.Test
Added a test verifying that the TextIOWrapper used in stdio_server has
newline=set, preventing CRLF conversion.