Skip to content

fix: prevent CRLF translation in stdio_server on Windows#2743

Open
Epochex wants to merge 2 commits into
modelcontextprotocol:mainfrom
Epochex:fix/2433-stdio-lf
Open

fix: prevent CRLF translation in stdio_server on Windows#2743
Epochex wants to merge 2 commits into
modelcontextprotocol:mainfrom
Epochex:fix/2433-stdio-lf

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented May 31, 2026

Fixes #2433.

On Windows, TextIOWrapper defaults to newline=None and translates \n -> \r\n on output. stdio_server wraps sys.stdout.buffer with TextIOWrapper, so every JSON-RPC message was emitted with CRLF line endings.

This sets newline= on the stdio stdin/stdout wrappers to disable platform newline translation and keep LF-delimited NDJSON.

Tests:

  • uv run --frozen pytest tests/server/test_stdio.py

@yyzquwu
Copy link
Copy Markdown

yyzquwu commented Jun 1, 2026

I ran an independent Windows-focused repro packet from Agent Windows Lab and it supports the direction of this PR.

Environment/evidence:

  • Windows 11 10.0.26200, Python 3.13.13
  • stdio_newline_framing: Python text-mode stdout emitted CRLF (0d0a) while binary stdout emitted LF (0a)
  • mcp_stdio_jsonrpc_probe: binary stdio round-tripped an MCP-style JSON-RPC initialize message with LF framing
  • The generated report was redacted and passed the redaction verifier

Command used:

python .\scripts\run_agent_windows_lab.py --out .\artifacts\issue-packet --case mcp --issue-target modelcontextprotocol-python-sdk
python .\scripts\verify_redacted_report.py .\artifacts\issue-packet\agent-windows-lab-report.json

Public harness commit: yyzquwu/agent-windows-lab@ab5e714
Windows proof run: https://github.com/yyzquwu/agent-windows-lab/actions/runs/26735979548

This gives independent Windows evidence for treating stdio framing as byte-level transport behavior and preventing text-mode newline translation from leaking into JSON-RPC framing.

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