From d3fb6863e88e969f7ca9d08ccfa9cca6e5f12c47 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Tue, 1 Jul 2025 12:09:43 +0100 Subject: [PATCH] Add minimal regression test for issue #552 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/issues/test_552_windows_hang.py | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/issues/test_552_windows_hang.py diff --git a/tests/issues/test_552_windows_hang.py b/tests/issues/test_552_windows_hang.py new file mode 100644 index 000000000..aa0d876d9 --- /dev/null +++ b/tests/issues/test_552_windows_hang.py @@ -0,0 +1,48 @@ +""" +Regression test for issue #552: Windows 11 hanging on MCP client initialization. + +The bug: Windows-specific process creation code in win32.py causes the client +to hang indefinitely during initialization. + +The fix: Use the generic anyio.open_process for all platforms instead of +custom Windows-specific code. +""" + +import sys +import textwrap + +import anyio +import pytest + +from mcp import ClientSession, StdioServerParameters +from mcp.client.stdio import stdio_client + + +@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific regression test") +@pytest.mark.anyio +async def test_issue_552_windows_no_hang(): + """ + Test that stdio_client doesn't hang on Windows during initialization. + + Issue #552: The Windows-specific process creation code caused hanging. + This test verifies that using a Python subprocess completes without hanging. + """ + # Minimal Python script that responds to initialize request + server_script = textwrap.dedent(""" + import sys, json + request = json.loads(sys.stdin.readline()) + if request.get("method") == "initialize": + response = {"jsonrpc": "2.0", "id": request.get("id"), "result": {"protocolVersion": "0.1.0", "capabilities": {}}} + print(json.dumps(response)) + sys.stdout.flush() + """) + + params = StdioServerParameters(command=sys.executable, args=["-c", server_script]) + + # Should complete without hanging (issue #552 would hang here) + with anyio.fail_after(5): + async with stdio_client(params) as (read, write): + async with ClientSession(read, write) as session: + result = await session.initialize() + assert result is not None + assert result.protocolVersion == "0.1.0"