Skip to content
Closed
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
17 changes: 14 additions & 3 deletions src/mcp/server/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,27 @@ async def stdin_reader():
continue

await read_stream_writer.send(message)
except anyio.BrokenResourceError as ex:
print(f"BrokenResourceError(reader): {ex}")
pass
except anyio.ClosedResourceError:
await anyio.lowlevel.checkpoint()
except Exception as ex:
print(f"read error: {ex}")

async def stdout_writer():
try:
async with write_stream_reader:
async for message in write_stream_reader:
json = message.model_dump_json(by_alias=True, exclude_none=True)
await stdout.write(json + "\n")
await stdout.flush()
try:
json = message.model_dump_json(by_alias=True, exclude_none=True)
await stdout.write(json + "\n")
await stdout.flush()
except Exception as ex:
print(f"problem with writer: {ex}")
except anyio.BrokenResourceError as ex:
print(f"BrokenResourceError(writer): {ex}")
pass
except anyio.ClosedResourceError:
await anyio.lowlevel.checkpoint()

Expand Down