Skip to content

fix: set newline='' on TextIOWrapper in stdio_server to prevent Windows CRLF corruption#2574

Open
EvanYao826 wants to merge 2 commits intomodelcontextprotocol:mainfrom
EvanYao826:fix/windows-crlf-stdio-2433
Open

fix: set newline='' on TextIOWrapper in stdio_server to prevent Windows CRLF corruption#2574
EvanYao826 wants to merge 2 commits intomodelcontextprotocol:mainfrom
EvanYao826:fix/windows-crlf-stdio-2433

Conversation

@EvanYao826
Copy link
Copy Markdown

Fixes #2433

Summary

On Windows, TextIOWrapper defaults to platform-native line endings ( ), which corrupts newline-delimited JSON-RPC messages over stdio. The server-side stdio_server() wraps sys.stdout in a TextIOWrapper without specifying newline=, so any in the JSON payload gets converted to , breaking clients that parse on .

Fix

Add newline= to the TextIOWrapper constructor in stdio_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.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messages

1 participant