Skip to content

fix: disable CRLF translation in stdio_server on Windows#2470

Closed
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-2433
Closed

fix: disable CRLF translation in stdio_server on Windows#2470
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-2433

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

On Windows, TextIOWrapper with the default newline=None translates \n\r\n on write. This means every JSON-RPC message emitted by stdio_server() gets \r\n line endings, violating the NDJSON wire format.

The fix is to pass newline="" to both TextIOWrapper calls in stdio_server(), which disables the platform-dependent line-ending translation while keeping the stream in text mode.

Changes

  • src/mcp/server/stdio.py: add newline="" to both TextIOWrapper constructors (stdin and stdout)
  • tests/server/test_stdio.py: add test_stdio_server_uses_lf_newlines to assert the output contains only LF, not CRLF

Fixes #2433

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
@Christian-Sidak
Copy link
Copy Markdown
Author

Closing -- duplicate of #2440 which already fixes this.

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