You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Server crashes with anyio.ClosedResourceError when receiving raw invalid UTF-8 bytes #2328
MCP 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.
File "...\mcp\server\lowlevel\server.py", line 781, in _handle_request
await message.respond(response)
File "...\mcp\shared\session.py", line 349, in _send_response
await self._write_stream.send(session_message)
File "...\anyio\streams\memory.py", line 218, in send_nowait
raise ClosedResourceError
anyio.ClosedResourceError
Key Observation
String "http://x[0xff][0xfe]" → handled gracefully with validation error ✅
Raw bytes b"http://x\xff\xfe" → server crash ❌
Expected Behavior
The server should return a JSON-RPC error response for malformed input, not crash.
Impact
Denial of Service - Any MCP client can crash any MCP server using the Python SDK with a single malformed request.
I'd like to work on this issue. Could you please assign it to me? I can implement a fix to handle invalid UTF-8 bytes gracefully without crashing the server.
Fixed by #2306 on main and #2334 on v1.x (available since v1.27): the server now catches ClosedResourceError/BrokenResourceError when responding and cancels in-flight handlers when the transport closes, instead of crashing. #2302/#2303 also handle non-UTF-8 stdio input gracefully.
Activity
goingforstudying-ctrl commentedon Mar 22, 2026
I'd like to work on this issue. Could you please assign it to me? I can implement a fix to handle invalid UTF-8 bytes gracefully without crashing the server.
maxisbey commentedon May 18, 2026
Fixed by #2306 on
mainand #2334 onv1.x(available since v1.27): the server now catchesClosedResourceError/BrokenResourceErrorwhen responding and cancels in-flight handlers when the transport closes, instead of crashing. #2302/#2303 also handle non-UTF-8 stdio input gracefully.AI Disclaimer