fix(mcp): let streamable HTTP read timeout cover tool_timeout

The streamable HTTP client used httpx.Timeout(30.0, connect=10.0), so the
read timeout was fixed at 30s regardless of tool_timeout. A server that
stays silent until the result is ready (e.g. FastMCP json_response=True)
hit ReadTimeout after 30s; the tool call then hung until tool_timeout
fired and reported "(MCP tool call timed out after Ns)".

Use the MCP SDK's own httpx defaults (30s, read=300s) and raise the read
timeout to tool_timeout when it is larger. Connect stays at 10s.

Fixes #6065
This commit is contained in:
Max Hsu authored and chengyongru committed 2026-10-06 01:41:10 +08:00
1 parent 63bdd40280
commit d9ceae15be
2 files changed
+26 -3

No files matched your search

+15 -2
View File
@@ -1484,9 +1484,18 @@ async def test_connect_mcp_servers_rolls_back_completed_batch_on_cancellation(
@pytest.mark.asyncio
@pytest.mark.parametrize(
("tool_timeout", "expected_read"),
[
(30, 300.0), # default: match the MCP SDK's SSE read timeout
(600, 600.0), # long-running tools: read must not cut the call short
],
)
async def test_connect_mcp_servers_streamable_http_uses_finite_timeout(
fake_mcp_runtime: dict[str, object | None],
monkeypatch: pytest.MonkeyPatch,
tool_timeout: int,
expected_read: float,
) -> None:
fake_mcp_runtime["session"] = _make_fake_session(["demo"])
captured: dict[str, object] = {}
@@ -1517,7 +1526,11 @@ async def test_connect_mcp_servers_streamable_http_uses_finite_timeout(
registry = ToolRegistry()
stacks = await connect_mcp_servers(
{"test": MCPServerConfig(url="https://mcp.example.com/mcp")},
{
"test": MCPServerConfig(
url="https://mcp.example.com/mcp", tool_timeout=tool_timeout
)
},
registry,
)
for stack in stacks.values():
@@ -1525,7 +1538,7 @@ async def test_connect_mcp_servers_streamable_http_uses_finite_timeout(
timeout = captured["timeout"]
assert timeout.connect == 10.0
assert timeout.read == 30.0
assert timeout.read == expected_read
assert timeout.write == 30.0
assert timeout.pool == 30.0