Skip to content

Commit 08247c4

Browse files
committed
update to use time delta in client
1 parent e087283 commit 08247c4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/mcp/client/streamable_http.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import logging
1010
from contextlib import asynccontextmanager
11+
from datetime import timedelta
1112
from typing import Any
1213

1314
import anyio
@@ -37,8 +38,8 @@
3738
async def streamablehttp_client(
3839
url: str,
3940
headers: dict[str, Any] | None = None,
40-
timeout: float = 30,
41-
sse_read_timeout: float = 60 * 5,
41+
timeout: timedelta = timedelta(seconds=30),
42+
sse_read_timeout: timedelta = timedelta(seconds=60 * 5),
4243
):
4344
"""
4445
Client transport for StreamableHTTP.
@@ -71,7 +72,9 @@ async def streamablehttp_client(
7172
session_id: str | None = None
7273

7374
async with httpx.AsyncClient(
74-
headers=request_headers, timeout=timeout, follow_redirects=True
75+
headers=request_headers,
76+
timeout=httpx.Timeout(timeout.seconds, read=sse_read_timeout.seconds),
77+
follow_redirects=True,
7578
) as client:
7679

7780
async def post_writer():
@@ -225,7 +228,9 @@ async def get_stream():
225228
"GET",
226229
url,
227230
headers=get_headers,
228-
timeout=httpx.Timeout(timeout, read=sse_read_timeout),
231+
timeout=httpx.Timeout(
232+
timeout.seconds, read=sse_read_timeout.seconds
233+
),
229234
) as event_source:
230235
event_source.response.raise_for_status()
231236
logger.debug("GET SSE connection established")

0 commit comments

Comments
 (0)