fix: disable CRLF translation in stdio_server on Windows#2470
Closed
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
fix: disable CRLF translation in stdio_server on Windows#2470Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add newline="" to both TextIOWrapper calls in stdio_server() to prevent platform-dependent LF→CRLF translation on Windows, ensuring LF-only line endings in the NDJSON wire format on all platforms. Fixes modelcontextprotocol#2433
Author
|
Closing -- duplicate of #2440 which already fixes this. |
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
On Windows,
TextIOWrapperwith the defaultnewline=Nonetranslates\n→\r\non write. This means every JSON-RPC message emitted bystdio_server()gets\r\nline endings, violating the NDJSON wire format.The fix is to pass
newline=""to bothTextIOWrappercalls instdio_server(), which disables the platform-dependent line-ending translation while keeping the stream in text mode.Changes
src/mcp/server/stdio.py: addnewline=""to bothTextIOWrapperconstructors (stdin and stdout)tests/server/test_stdio.py: addtest_stdio_server_uses_lf_newlinesto assert the output contains only LF, not CRLFFixes #2433