From 8dc7653cb29d1c8db0b1b626d83663a7137b64a4 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:08:46 -0400 Subject: [PATCH] Pass float session timeout to sse_client; update timeout-message assertions (SDK v2) --- fastmcp_slim/fastmcp/client/transports/sse.py | 10 +++++----- tests/client/test_sse.py | 6 +++--- tests/client/test_streamable_http.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fastmcp_slim/fastmcp/client/transports/sse.py b/fastmcp_slim/fastmcp/client/transports/sse.py index 8c2d7c167..09e7fff5c 100644 --- a/fastmcp_slim/fastmcp/client/transports/sse.py +++ b/fastmcp_slim/fastmcp/client/transports/sse.py @@ -134,11 +134,11 @@ class SSETransport(ClientTransport): # instead we simply leave the kwarg out if it's not provided if self.sse_read_timeout is not None: client_kwargs["sse_read_timeout"] = self.sse_read_timeout.total_seconds() - if session_kwargs.get("read_timeout_seconds") is not None: - read_timeout_seconds = cast( - datetime.timedelta, session_kwargs.get("read_timeout_seconds") - ) - client_kwargs["timeout"] = read_timeout_seconds.total_seconds() + # SDK v2 session read timeouts are float seconds (see SessionKwargs); + # sse_client's `timeout` param is likewise float seconds. + read_timeout_seconds = session_kwargs.get("read_timeout_seconds") + if read_timeout_seconds is not None: + client_kwargs["timeout"] = read_timeout_seconds if self.httpx_client_factory is not None: client_kwargs["httpx_client_factory"] = self.httpx_client_factory diff --git a/tests/client/test_sse.py b/tests/client/test_sse.py index beb5b857e..eb94faa75 100644 --- a/tests/client/test_sse.py +++ b/tests/client/test_sse.py @@ -162,7 +162,7 @@ class TestTimeout: async def test_timeout(self, sse_server: str): with pytest.raises( MCPError, - match="Timed out while waiting for response to ClientRequest. Waited 0.03 seconds", + match="timed out", ): async with Client( transport=SSETransport(sse_server), @@ -172,7 +172,7 @@ class TestTimeout: async def test_timeout_tool_call(self, sse_server: str): async with Client(transport=SSETransport(sse_server)) as client: - with pytest.raises(MCPError, match="Timed out"): + with pytest.raises(MCPError, match="timed out"): await client.call_tool("sleep", {"seconds": 0.1}, timeout=0.03) async def test_timeout_tool_call_overrides_client_timeout_if_lower( @@ -182,7 +182,7 @@ class TestTimeout: transport=SSETransport(sse_server), timeout=2, ) as client: - with pytest.raises(MCPError, match="Timed out"): + with pytest.raises(MCPError, match="timed out"): await client.call_tool("sleep", {"seconds": 0.1}, timeout=0.03) async def test_timeout_client_timeout_does_not_override_tool_call_timeout_if_lower( diff --git a/tests/client/test_streamable_http.py b/tests/client/test_streamable_http.py index 85594ade9..c802d7929 100644 --- a/tests/client/test_streamable_http.py +++ b/tests/client/test_streamable_http.py @@ -266,7 +266,7 @@ class TestTimeout: async def test_timeout(self, streamable_http_server: str): # note this transport behaves differently than others and raises # MCPError from the *client* context - with pytest.raises(MCPError, match="Timed out"): + with pytest.raises(MCPError, match="timed out"): async with Client( transport=StreamableHttpTransport(streamable_http_server), timeout=0.02,