Pass float session timeout to sse_client; update timeout-message assertions (SDK v2)

This commit is contained in:
Jeremiah Lowin 2026-07-05 21:08:46 -04:00
commit 8dc7653cb2
No known key found for this signature in database
3 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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(

View file

@ -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,