ci: add stdio smoke test to verify LF-only wire format on all platforms#15
Merged
shigechika merged 3 commits intomainfrom May 1, 2026
Merged
ci: add stdio smoke test to verify LF-only wire format on all platforms#15shigechika merged 3 commits intomainfrom
shigechika merged 3 commits intomainfrom
Conversation
The Windows CI job previously ran only pytest unit tests, which exercise pure-Python logic and never spawn the MCP server. This meant the CRLF regression (modelcontextprotocol/python-sdk#2433) would not be caught. Add tests/test_stdio_smoke.py: spawns keycloak-mcp as a subprocess, sends a JSON-RPC initialize request, and asserts the response line is terminated with LF (\n) not CRLF (\r\n). Runs on every matrix entry (ubuntu-latest × 3.10/3.12/3.13 + windows-latest × 3.12) via the existing `uv run pytest -v` step — no CI workflow changes required. Closes #3 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…tion On Windows, sys.stdout defaults to text mode which translates \n to \r\n, corrupting the NDJSON wire format (modelcontextprotocol/python-sdk#2433). Use msvcrt.setmode to force binary mode on the underlying file descriptors before mcp.run() so the MCP SDK's writes pass through unchanged. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
msvcrt.setmode() cannot prevent the \n -> \r\n translation because it happens in Python's TextIOWrapper layer before reaching the OS fd level. The MCP SDK creates TextIOWrapper(sys.stdout.buffer, encoding="utf-8") with the default newline=None, which on Windows translates \n to \r\n. Work around this by rebuilding sys.stdout around a _CRStripper RawIOBase that strips \r\n -> \n before each os.write(), so the SDK's subsequent TextIOWrapper.write() calls are corrected at the raw I/O level. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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
tests/test_stdio_smoke.py: spawnskeycloak-mcpas a subprocess, sends a JSON-RPCinitializerequest, and asserts the response line is terminated with\nnot\r\n.uv run pytest -vstep picks up the new file automatically, so it runs on every matrix entry (ubuntu-latest × 3.10/3.12/3.13 + windows-latest × 3.12).initializeis handled entirely by the MCP framework before any tool dispatch.What this guards against
modelcontextprotocol/python-sdk#2433 —
stdio_server()on Windows emitted\r\ninstead of\n, corrupting the NDJSON wire format. The previous Windows CI job only ran unit tests and would not have caught this regression.Test plan
uv run pytest tests/test_stdio_smoke.py -v— passes locally (macOS)Closes #3
🤖 Generated with Claude Code