Skip to content

Commit 8794eb8

Browse files
author
aagarwal25
committed
feat: Streamable HTTP support
1 parent e50bd99 commit 8794eb8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/agents/mcp/server.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ async def connect(self):
106106
"""Connect to the server."""
107107
try:
108108
transport = await self.exit_stack.enter_async_context(self.create_streams())
109-
read, write = transport
109+
# Handle different transport return values
110+
if len(transport) == 3:
111+
# streamablehttp_client returns (read, write, get_session_id)
112+
read, write, _ = transport
113+
else:
114+
# sse_client returns (read, write)
115+
read, write = transport
116+
110117
session = await self.exit_stack.enter_async_context(
111118
ClientSession(
112119
read,
@@ -330,10 +337,10 @@ class MCPServerStreamableHttpParams(TypedDict):
330337
headers: NotRequired[dict[str, str]]
331338
"""The headers to send to the server."""
332339

333-
timeout: NotRequired[float]
340+
timeout: NotRequired[timedelta]
334341
"""The timeout for the HTTP request. Defaults to 5 seconds."""
335342

336-
sse_read_timeout: NotRequired[float]
343+
sse_read_timeout: NotRequired[timedelta]
337344
"""The timeout for the SSE connection, in seconds. Defaults to 5 minutes."""
338345

339346
terminate_on_close: NotRequired[bool]
@@ -389,8 +396,8 @@ def create_streams(
389396
return streamablehttp_client(
390397
url=self.params["url"],
391398
headers=self.params.get("headers", None),
392-
timeout=self.params.get("timeout", 30),
393-
sse_read_timeout=self.params.get("sse_read_timeout", 60 * 5),
399+
timeout=self.params.get("timeout", timedelta(seconds=30)),
400+
sse_read_timeout=self.params.get("sse_read_timeout", timedelta(seconds=60 * 5)),
394401
terminate_on_close=self.params.get("terminate_on_close", True)
395402
)
396403

0 commit comments

Comments
 (0)