diff --git a/tests/tools/test_mcp_tool.py b/tests/tools/test_mcp_tool.py index 949f4eec..7cf64060 100644 --- a/tests/tools/test_mcp_tool.py +++ b/tests/tools/test_mcp_tool.py @@ -645,6 +645,44 @@ async def test_connect_mcp_servers_one_failure_does_not_block_others( assert set(stacks) == {"good"} +@pytest.mark.asyncio +async def test_connect_mcp_servers_streamable_http_uses_finite_timeout( + fake_mcp_runtime: dict[str, object | None], + monkeypatch: pytest.MonkeyPatch, +) -> None: + fake_mcp_runtime["session"] = _make_fake_session(["demo"]) + captured: dict[str, object] = {} + + async def _reachable(_url: str) -> bool: + return True + + @asynccontextmanager + async def _capturing_streamable_http_client(_url: str, http_client=None): + captured["timeout"] = http_client.timeout + yield object(), object(), object() + + monkeypatch.setattr(mcp_mod, "_probe_http_url", _reachable) + monkeypatch.setattr( + sys.modules["mcp.client.streamable_http"], + "streamable_http_client", + _capturing_streamable_http_client, + ) + + registry = ToolRegistry() + stacks = await connect_mcp_servers( + {"test": MCPServerConfig(url="http://127.0.0.1:4001/mcp")}, + registry, + ) + for stack in stacks.values(): + await stack.aclose() + + timeout = captured["timeout"] + assert timeout.connect == 10.0 + assert timeout.read == 30.0 + assert timeout.write == 30.0 + assert timeout.pool == 30.0 + + @pytest.mark.asyncio async def test_connect_mcp_servers_wraps_windows_stdio_launchers( fake_mcp_runtime: dict[str, object | None],