René's URL Explorer Experiment


Title: Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messages · Issue #2433 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messages · Issue #2433 · modelcontextprotocol/python-sdk

X Title: Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messages · Issue #2433 · modelcontextprotocol/python-sdk

Description: Summary mcp/server/stdio.py creates TextIOWrapper(sys.stdout.buffer, encoding="utf-8") without specifying newline="". On Windows, the default newline=None causes \n → \r\n translation, so every JSON-RPC message written to stdout ends wit...

Open Graph Description: Summary mcp/server/stdio.py creates TextIOWrapper(sys.stdout.buffer, encoding="utf-8") without specifying newline="". On Windows, the default newline=None causes \n → \r\n translation, so every JSO...

X Description: Summary mcp/server/stdio.py creates TextIOWrapper(sys.stdout.buffer, encoding="utf-8") without specifying newline="". On Windows, the default newline=None causes \n → \r\n trans...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2433

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messages","articleBody":"## Summary\n\n`mcp/server/stdio.py` creates `TextIOWrapper(sys.stdout.buffer, encoding=\"utf-8\")` without specifying `newline=\"\"`. On Windows, the default `newline=None` causes `\\n` → `\\r\\n` translation, so every JSON-RPC message written to stdout ends with `\\r\\n` instead of `\\n`.\n\nThe MCP spec uses newline-delimited JSON with `\\n` as the delimiter. Emitting `\\r\\n` is a protocol-level impurity.\n\n## Affected file\n\n[`mcp/server/stdio.py` lines 46–49](https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/stdio.py)\n\n```python\n# Current (buggy on Windows)\nif not stdin:\n    stdin = anyio.wrap_file(TextIOWrapper(sys.stdin.buffer, encoding=\"utf-8\"))\nif not stdout:\n    stdout = anyio.wrap_file(TextIOWrapper(sys.stdout.buffer, encoding=\"utf-8\"))\n```\n\n## Reproduction\n\nOn Windows, spawn a Python subprocess that uses this code and read the raw bytes:\n\n```python\nimport subprocess, sys\n\nscript = r'''\nimport sys\nfrom io import TextIOWrapper\nstdout = TextIOWrapper(sys.stdout.buffer, encoding=\"utf-8\")\nstdout.write('{\"jsonrpc\":\"2.0\",\"result\":\"ok\"}\\n')\nstdout.flush()\n'''\n\nproc = subprocess.Popen([sys.executable, \"-c\", script], stdout=subprocess.PIPE)\nout, _ = proc.communicate(timeout=5)\nprint(repr(out))\n# Output on Windows: b'{\"jsonrpc\":\"2.0\",\"result\":\"ok\"}\\r\\n'\n# Output on Linux:   b'{\"jsonrpc\":\"2.0\",\"result\":\"ok\"}\\n'\n```\n\nVerified on:\n- **OS:** Windows 11 Pro (10.0.26200)\n- **Python:** 3.11\n- **mcp:** 1.26.0\n\n## Why this matters\n\nWhile the current JS MCP SDK client (`StdioClientTransport`) strips trailing `\\r` via `.replace(/\\r$/, \"\")` before parsing, this is a server-side bug that:\n\n1. Violates the NDJSON wire format (which specifies LF-only line endings)\n2. Creates an asymmetry: the Python `stdio_client` sends bare `\\n`, but the Python `stdio_server` responds with `\\r\\n`\n3. Could break any MCP client that does a strict `split(\"\\n\")` and then fails to `JSON.parse` the line with a trailing `\\r`\n\nThe comment on line 43 even acknowledges: *\"Encoding of stdin/stdout as text streams on python is platform-dependent (Windows is particularly problematic)\"* — but the fix applied (`re-wrap to ensure UTF-8`) doesn't also fix the newline translation mode.\n\n## Fix\n\nAdd `newline=\"\"` to both `TextIOWrapper` calls. `newline=\"\"` disables translation while still operating in text mode:\n\n```python\nif not stdin:\n    stdin = anyio.wrap_file(TextIOWrapper(sys.stdin.buffer, encoding=\"utf-8\", newline=\"\"))\nif not stdout:\n    stdout = anyio.wrap_file(TextIOWrapper(sys.stdout.buffer, encoding=\"utf-8\", newline=\"\"))\n```\n\nWith this fix:\n```python\n# newline=\"\" result:\nbuf = io.BytesIO()\nwrapper = TextIOWrapper(buf, encoding=\"utf-8\", newline=\"\")\nwrapper.write('{\"jsonrpc\":\"2.0\",\"result\":\"ok\"}\\n')\nwrapper.flush()\nrepr(buf.getvalue())\n# b'{\"jsonrpc\":\"2.0\",\"result\":\"ok\"}\\n'  ← correct on all platforms\n```\n\nThe same fix should be applied to the `stdin` wrapper so that incoming messages with bare `\\n` are not translated either (avoiding any future issues if a client sends strict LF).\n\n## Context\n\nThis was discovered while debugging Windows MCP tool timeouts with `mem0-mcp-selfhosted`. The eager-init approach fixed the actual timeout, but this CRLF emission was identified as a secondary protocol-level issue during investigation.","author":{"url":"https://github.com/DonovanDeHart","@type":"Person","name":"DonovanDeHart"},"datePublished":"2026-04-13T12:50:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/2433/python-sdk/issues/2433"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:1e5da2f9-babe-d83e-02a8-cf33d2847fe2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAA1A:3BC6BD:ABE7F5:F61517:6A5E2351
html-safe-nonce089fb2b331545857244f37a3b0ae3e21136ffc9148364fedabab5c7ae3cd7de1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTFBOjNCQzZCRDpBQkU3RjU6RjYxNTE3OjZBNUUyMzUxIiwidmlzaXRvcl9pZCI6IjQ3ODU3MTA2Nzc2MzczNDIwMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacab7ae677a28cd0ddb8990dafca371ba9f89c4d0ce22bf27c61f6ccf82d2b23a3
hovercard-subject-tagissue:4254758384
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2433/issue_layout
twitter:imagehttps://opengraph.githubassets.com/01e961f8490cf5f15ba4d69cc1562f64a6ec6758520bdae9696412bfa5453d77/modelcontextprotocol/python-sdk/issues/2433
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/01e961f8490cf5f15ba4d69cc1562f64a6ec6758520bdae9696412bfa5453d77/modelcontextprotocol/python-sdk/issues/2433
og:image:altSummary mcp/server/stdio.py creates TextIOWrapper(sys.stdout.buffer, encoding="utf-8") without specifying newline="". On Windows, the default newline=None causes \n → \r\n translation, so every JSO...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDonovanDeHart
hostnamegithub.com
expected-hostnamegithub.com
Nonee5010f4d2748a3cbef86e1580413ff14701bd99f255268dfb4a2857c77e2cc7c
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7d23604c4a8ce0274b4c71bb2adbe6e1c9d5904f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/2433#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2433
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2433
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2433
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2433
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2433
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/2433
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 263 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 309 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
#3132https://github.com/modelcontextprotocol/python-sdk/pull/3132
#2552https://github.com/modelcontextprotocol/python-sdk/pull/2552
Windows: TextIOWrapper in stdio_server() emits CRLF instead of LF, corrupting newline-delimited JSON messageshttps://github.com/modelcontextprotocol/python-sdk/issues/2433#top
#3132https://github.com/modelcontextprotocol/python-sdk/pull/3132
#2552https://github.com/modelcontextprotocol/python-sdk/pull/2552
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
fix proposedBot has a verified fix diff in the commenthttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22fix%20proposed%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
https://github.com/DonovanDeHart
DonovanDeHarthttps://github.com/DonovanDeHart
on Apr 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2433#issue-4254758384
mcp/server/stdio.py lines 46–49https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/stdio.py
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
fix proposedBot has a verified fix diff in the commenthttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22fix%20proposed%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.