Skip to content

Commit 38229ba

Browse files
committed
add test that checks if stdio connection hangs with bad connection params
1 parent 321498a commit 38229ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: tests/client/test_stdio.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import shutil
22

33
import pytest
4+
from anyio import fail_after
45

56
from mcp.client.stdio import StdioServerParameters, stdio_client
67
from mcp.types import JSONRPCMessage, JSONRPCRequest, JSONRPCResponse
@@ -41,3 +42,18 @@ async def test_stdio_client():
4142
assert read_messages[1] == JSONRPCMessage(
4243
root=JSONRPCResponse(jsonrpc="2.0", id=2, result={})
4344
)
45+
46+
47+
@pytest.mark.anyio
48+
async def test_stdio_client_bad_path():
49+
"""Check that the connection doesn't hang if process errors."""
50+
server_parameters = StdioServerParameters(
51+
command="uv", args=["run", "non-existent-file.py"]
52+
)
53+
54+
try:
55+
with fail_after(1):
56+
async with stdio_client(server_parameters) as (read_stream, write_stream):
57+
pass
58+
except TimeoutError:
59+
pytest.fail("The connection hung.")

0 commit comments

Comments
 (0)