Skip to content

Commit d3fb686

Browse files
Add minimal regression test for issue #552
This commit adds a minimal test for the Windows hanging issue (#552) where MCP client initialization would hang indefinitely on Windows 11. The test verifies that a simple Python subprocess can initialize without hanging, which would fail with the buggy Windows-specific process creation code but succeeds with the generic anyio.open_process implementation. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6f43d1f commit d3fb686

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Regression test for issue #552: Windows 11 hanging on MCP client initialization.
3+
4+
The bug: Windows-specific process creation code in win32.py causes the client
5+
to hang indefinitely during initialization.
6+
7+
The fix: Use the generic anyio.open_process for all platforms instead of
8+
custom Windows-specific code.
9+
"""
10+
11+
import sys
12+
import textwrap
13+
14+
import anyio
15+
import pytest
16+
17+
from mcp import ClientSession, StdioServerParameters
18+
from mcp.client.stdio import stdio_client
19+
20+
21+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific regression test")
22+
@pytest.mark.anyio
23+
async def test_issue_552_windows_no_hang():
24+
"""
25+
Test that stdio_client doesn't hang on Windows during initialization.
26+
27+
Issue #552: The Windows-specific process creation code caused hanging.
28+
This test verifies that using a Python subprocess completes without hanging.
29+
"""
30+
# Minimal Python script that responds to initialize request
31+
server_script = textwrap.dedent("""
32+
import sys, json
33+
request = json.loads(sys.stdin.readline())
34+
if request.get("method") == "initialize":
35+
response = {"jsonrpc": "2.0", "id": request.get("id"), "result": {"protocolVersion": "0.1.0", "capabilities": {}}}
36+
print(json.dumps(response))
37+
sys.stdout.flush()
38+
""")
39+
40+
params = StdioServerParameters(command=sys.executable, args=["-c", server_script])
41+
42+
# Should complete without hanging (issue #552 would hang here)
43+
with anyio.fail_after(5):
44+
async with stdio_client(params) as (read, write):
45+
async with ClientSession(read, write) as session:
46+
result = await session.initialize()
47+
assert result is not None
48+
assert result.protocolVersion == "0.1.0"

0 commit comments

Comments
 (0)