Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Keep the client timeout from capping the HTTP read timeout (#5690)

Asem ahmedbf95d12dfbe0
diff --git a/fastmcp_slim/fastmcp/client/transports/http.py b/fastmcp_slim/fastmcp/client/transports/http.py
index 50b03b3b9..c4e7e5346 100644
--- a/fastmcp_slim/fastmcp/client/transports/http.py
+++ b/fastmcp_slim/fastmcp/client/transports/http.py
@@ -183,10 +183,13 @@ class StreamableHttpTransport(ClientTransport):
# Configure timeout if provided, preserving MCP's 30s connect default.
# SDK v2 session read timeouts are float seconds (see SessionKwargs).
+ # The session enforces request timeouts itself, and a call may carry its
+ # own, longer timeout, so the HTTP read timeout may only extend MCP's
+ # 300s default; a shorter client timeout must not cut such a call short.
timeout: httpx2.Timeout | None = None
read_timeout_seconds = session_kwargs.get("read_timeout_seconds")
if read_timeout_seconds is not None:
- timeout = httpx2.Timeout(30.0, read=read_timeout_seconds)
+ timeout = httpx2.Timeout(30.0, read=max(300.0, read_timeout_seconds))
# Create httpx client from factory or use default with MCP-appropriate
# timeouts. Note: create_mcp_http_client enables follow_redirects, but
diff --git a/tests/integration_tests/test_timeout_fix.py b/tests/integration_tests/test_timeout_fix.py
index 27776c1ba..05eb36193 100644
--- a/tests/integration_tests/test_timeout_fix.py
+++ b/tests/integration_tests/test_timeout_fix.py
@@ -49,3 +49,14 @@ async def test_slow_tool_with_http_transport(streamable_http_server: str):
# This should NOT timeout since we fixed the default timeout
result = await client.call_tool("slow_tool", {"duration": 6})
assert result.data == "Completed in 6 seconds"
+
+
+async def test_tool_call_timeout_may_exceed_client_timeout(streamable_http_server: str):
+ """A per-call timeout longer than the client's is not cut short by the HTTP read timeout."""
+ async with Client(
+ transport=StreamableHttpTransport(streamable_http_server), timeout=0.5
+ ) as client:
+ result = await client.call_tool("slow_tool", {"duration": 1}, timeout=10)
+ assert result.data == "Completed in 1 seconds"