Skip to content

Commit c578212

Browse files
authored
Fix hanging on streams when stdio_client exiting (#559)
1 parent 37b54b4 commit c578212

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/mcp/client/stdio/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ async def stdin_writer():
181181
await terminate_windows_process(process)
182182
else:
183183
process.terminate()
184+
await read_stream.aclose()
185+
await write_stream.aclose()
184186

185187

186188
def _get_executable_command(command: str) -> str:

tests/client/test_stdio.py

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
tee: str = shutil.which("tee") # type: ignore
1010

1111

12+
@pytest.mark.anyio
13+
@pytest.mark.skipif(tee is None, reason="could not find tee command")
14+
async def test_stdio_context_manager_exiting():
15+
async with stdio_client(StdioServerParameters(command=tee)) as (_, _):
16+
pass
17+
18+
1219
@pytest.mark.anyio
1320
@pytest.mark.skipif(tee is None, reason="could not find tee command")
1421
async def test_stdio_client():

0 commit comments

Comments
 (0)