Skip to content

Commit 04324e9

Browse files
authored
Merge pull request #23 from sacha-development-stuff/codex/fix-connectionreseterror-in-stdio_client-test
Handle closed stdin in stdio client
2 parents 84860f8 + 3e0c70c commit 04324e9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ async def stdout_reader():
162162
await read_stream_writer.send(session_message)
163163
except anyio.ClosedResourceError:
164164
await anyio.lowlevel.checkpoint()
165+
except (BrokenPipeError, ConnectionResetError):
166+
# The server process exited and closed its stdin. Treat this as a normal
167+
# shutdown so the caller sees the connection close rather than an
168+
# unhandled exception from the background task.
169+
await anyio.lowlevel.checkpoint()
165170

166171
async def stdin_writer():
167172
assert process.stdin, "Opened process is missing stdin"

0 commit comments

Comments
 (0)