Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/mcp/server/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ async def stdout_writer():
json = session_message.message.model_dump_json(by_alias=True, exclude_unset=True)
await stdout.write(json + "\n")
await stdout.flush()
except anyio.ClosedResourceError: # pragma: no cover
except (anyio.ClosedResourceError, BrokenPipeError, ConnectionResetError): # pragma: no cover
# BrokenPipeError / ConnectionResetError occur when the parent
# process (MCP client) closes the stdout pipe — e.g. during
# restart, kill, or graceful shutdown. This is a graceful
# shutdown signal, not a crash — suppress it so the server
# exits cleanly instead of propagating an ExceptionGroup from
# anyio's TaskGroup.
await anyio.lowlevel.checkpoint()

async with anyio.create_task_group() as tg:
Expand Down
Loading