Skip to content

Fix stdio server newline translation on Windows#2757

Open
yyzquwu wants to merge 1 commit into
modelcontextprotocol:mainfrom
yyzquwu:codex/windows-stdio-lf
Open

Fix stdio server newline translation on Windows#2757
yyzquwu wants to merge 1 commit into
modelcontextprotocol:mainfrom
yyzquwu:codex/windows-stdio-lf

Conversation

@yyzquwu
Copy link
Copy Markdown

@yyzquwu yyzquwu commented Jun 1, 2026

Summary

  • Disable Windows CRLF translation in stdio_server() by setting newline="" on the default stdio wrappers.
  • Add a regression test for the default stdout path so JSON-RPC frames stay LF-only.

Fixes #2433.

Verification

Windows 11, Python 3.13.13:

tests/server/test_stdio.py::test_stdio_server PASSED
tests/server/test_stdio.py::test_stdio_server_uses_lf_newlines_with_default_stdout PASSED
tests/server/test_stdio.py::test_stdio_server_invalid_utf8 PASSED
3 passed

b'{"jsonrpc":"2.0","id":3,"method":"ping"}\n'

Branch coverage for tests/server/test_stdio.py: 100.00%.

Codex review passed before commit.

@yyzquwu yyzquwu force-pushed the codex/windows-stdio-lf branch from b8992b8 to 86176c5 Compare June 1, 2026 21:32
Copy link
Copy Markdown

@StantonMatt StantonMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked head 86176c5 on Windows with Python 3.13.13.

Local validation passed:

  • uv run --frozen pytest tests/server/test_stdio.py -q -> 3 passed
  • uv run --frozen ruff check src/mcp/server/stdio.py tests/server/test_stdio.py
  • uv run --frozen pyright src/mcp/server/stdio.py tests/server/test_stdio.py

I also ran a default-stdout byte probe through stdio_server() with a JSONRPCRequest(id=99, method="ping"); the emitted frame ended in 0a and did not contain 0d0a:

7b226a736f6e727063223a22322e30222c226964223a39392c226d6574686f64223a2270696e67227d0a

That covers the Windows newline-translation boundary from #2433 for me.

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

2 participants