π The fast, Pythonic way to build MCP servers and clients.
Fall back to the client timeout when resolving claimed results (#5190)
Marcin Belczewski5b2dd6de6d4c
diff --git a/fastmcp_slim/fastmcp/client/client.py b/fastmcp_slim/fastmcp/client/client.pyindex 49318f87b..daf905d4e 100644--- a/fastmcp_slim/fastmcp/client/client.py+++ b/fastmcp_slim/fastmcp/client/client.py@@ -1382,7 +1382,12 @@ class Client(through the session β and returns the ordinary `CallToolResult` itproduces. Mirrors the SDK Client's resolution path, including theoutput-schema revalidation the direct path performs.++ A `None` per-call timeout falls back to the client timeout, as+ `ClientSession.send_request` does; resolvers read `None` as unbounded."""+ if read_timeout_seconds is None:+ read_timeout_seconds = self._session_kwargs.get("read_timeout_seconds")claim = self._claim_by_model[type(result)]final = await claim.resolve(result,diff --git a/tests/client/test_client_extensions.py b/tests/client/test_client_extensions.pyindex 1a054ae83..6c1fd8ffa 100644--- a/tests/client/test_client_extensions.py+++ b/tests/client/test_client_extensions.py@@ -294,3 +294,38 @@ class TestClaimedResultResolution:block = resolved.content[0]assert isinstance(block, TextContent)assert block.text == "resolved:from-server"+++class TestClaimContextTimeout:+ @pytest.mark.parametrize(+ ("client_timeout", "call_timeout", "expected"),+ [(None, None, None), (7, None, 7.0), (7, 3, 3.0), (None, 3, 3.0)],+ )+ async def test_resolver_receives_effective_timeout(+ self, client_timeout, call_timeout, expected+ ):+ """A `None` per-call timeout falls back to the client timeout."""+ seen: list[float | None] = []++ async def _record(result: ClaimedResult, ctx: ClaimContext) -> CallToolResult:+ seen.append(ctx.read_timeout_seconds)+ return CallToolResult(content=[])++ class _Recording(_DemoExtension):+ def claims(self):+ return (+ ResultClaim(+ result_type=CLAIMED_TYPE, model=ClaimedResult, resolve=_record+ ),+ )++ client = Client(+ _claiming_server(),+ extensions=[_Recording()],+ mode=LATEST_MODERN_VERSION,+ timeout=client_timeout,+ )+ async with client:+ await client.call_tool_mcp("claimed_tool", {}, timeout=call_timeout)++ assert seen == [expected]diff --git a/tests/tasks/client/test_transparent_tasks.py b/tests/tasks/client/test_transparent_tasks.pyindex 0c7dd046b..cf644e23e 100644--- a/tests/tasks/client/test_transparent_tasks.py+++ b/tests/tasks/client/test_transparent_tasks.py@@ -56,6 +56,20 @@ async def test_call_tool_timeout_bounds_total_task_drive(task_server: FastMCP):await client.call_tool("slow", {}, timeout=0.3)+async def test_client_timeout_bounds_total_task_drive(task_server: FastMCP):+ """Without a per-call timeout, the client timeout bounds the tasked drive."""+ async with Client(task_server, mode="auto", timeout=0.3) as client:+ with pytest.raises((TimeoutError, MCPError)):+ await client.call_tool("slow", {})+++async def test_per_call_timeout_overrides_client_timeout(task_server: FastMCP):+ async with Client(task_server, mode="auto", timeout=0.1) as client:+ result = await client.call_tool("multiply", {"a": 6, "b": 7}, timeout=5)++ assert result.data == 42++async def test_call_tool_transparently_completes_a_task(task_server: FastMCP):"""call_tool returns the tool's real result; the caller never sees a task."""async with Client(task_server, mode="auto") as client: