CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
fix(mcp): pass timedelta to streamablehttp_client for old-SDK compat (codex P2)
xf gong99cb44278a8c
diff --git a/cubepi/mcp/http_loader.py b/cubepi/mcp/http_loader.pyindex de0d162..188ec49 100644--- a/cubepi/mcp/http_loader.py+++ b/cubepi/mcp/http_loader.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport asynciofrom collections.abc import AsyncIteratorfrom contextlib import asynccontextmanager+from datetime import timedeltafrom typing import Any, Literalfrom cubepi.agent.types import AgentTool@@ -34,11 +35,17 @@ async def _open_session(if transport == "streamable_http":from mcp.client.streamable_http import streamablehttp_client+ # streamablehttp_client's timeout signature drifted across mcp SDK+ # versions: 1.8/1.9-era releases required ``timedelta`` and called+ # ``.total_seconds()`` internally, while ~1.10+ accepts ``float |+ # timedelta``. Passing a ``timedelta`` works on every version we+ # declare in our ``mcp>=1.0`` floor, so we always convert here.+ timeout_td = timedelta(seconds=timeout)async with streamablehttp_client(server_url,headers=headers,- timeout=timeout,- sse_read_timeout=timeout,+ timeout=timeout_td,+ sse_read_timeout=timeout_td,) as (read_stream, write_stream, _get_session_id):async with ClientSession(read_stream, write_stream) as session:yield sessiondiff --git a/tests/mcp/test_http_loader.py b/tests/mcp/test_http_loader.pyindex c71c69a..fd3fa85 100644--- a/tests/mcp/test_http_loader.py+++ b/tests/mcp/test_http_loader.py@@ -280,11 +280,17 @@ async def test_load_mcp_tools_http_streamable_transport(monkeypatch) -> None:# Discovery used streamable_http (sse must not be touched).assert sse_calls == []+ # streamablehttp_client expects ``timedelta`` on older mcp SDKs (1.8/1.9+ # era) and ``float | timedelta`` on newer ones; we always pass a+ # ``timedelta`` so the loader works on every release in our ``mcp>=1.0``+ # dependency range.+ from datetime import timedelta+assert sh_calls[0] == {"url": "https://mcp.example/mcp","headers": {"authorization": "Bearer x"},- "timeout": 7.5,- "sse_read_timeout": 7.5,+ "timeout": timedelta(seconds=7.5),+ "sse_read_timeout": timedelta(seconds=7.5),}assert len(sessions) == 1