Skip to content

fix: prevent CRLF translation in stdio_server on Windows#2743

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

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

@Epochex Epochex commented May 31, 2026

Copy link
Copy Markdown

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

yyzquwu commented Jun 1, 2026

Copy link
Copy Markdown

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.

@Kludex

Kludex commented Jun 25, 2026

Copy link
Copy Markdown
Member

You've opened a duplicated pull request, please search opened PRs before creating new ones. Duplicated from #2552.

@Kludex Kludex closed this Jun 25, 2026
@modelcontextprotocol modelcontextprotocol locked as resolved and limited conversation to collaborators Jun 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

3 participants