1010from anyio .streams .memory import MemoryObjectReceiveStream , MemoryObjectSendStream
1111from mcp import ClientSession , StdioServerParameters , Tool as MCPTool , stdio_client
1212from mcp .client .sse import sse_client
13- from mcp .client .streamable_http import streamablehttp_client
14- from mcp .types import CallToolResult , JSONRPCMessage
13+ from mcp .client .streamable_http import GetSessionIdCallback , streamablehttp_client
14+ from mcp .shared .message import SessionMessage
15+ from mcp .types import CallToolResult
1516from typing_extensions import NotRequired , TypedDict
1617
1718from ..exceptions import UserError
@@ -84,8 +85,9 @@ def create_streams(
8485 self ,
8586 ) -> AbstractAsyncContextManager [
8687 tuple [
87- MemoryObjectReceiveStream [JSONRPCMessage | Exception ],
88- MemoryObjectSendStream [JSONRPCMessage ],
88+ MemoryObjectReceiveStream [SessionMessage | Exception ],
89+ MemoryObjectSendStream [SessionMessage ],
90+ GetSessionIdCallback | None
8991 ]
9092 ]:
9193 """Create the streams for the server."""
@@ -110,7 +112,7 @@ async def connect(self):
110112 # sse_client returns (read, write)
111113
112114 read , write , * _ = transport
113-
115+
114116 session = await self .exit_stack .enter_async_context (
115117 ClientSession (
116118 read ,
@@ -237,8 +239,9 @@ def create_streams(
237239 self ,
238240 ) -> AbstractAsyncContextManager [
239241 tuple [
240- MemoryObjectReceiveStream [JSONRPCMessage | Exception ],
241- MemoryObjectSendStream [JSONRPCMessage ],
242+ MemoryObjectReceiveStream [SessionMessage | Exception ],
243+ MemoryObjectSendStream [SessionMessage ],
244+ GetSessionIdCallback | None
242245 ]
243246 ]:
244247 """Create the streams for the server."""
@@ -307,8 +310,9 @@ def create_streams(
307310 self ,
308311 ) -> AbstractAsyncContextManager [
309312 tuple [
310- MemoryObjectReceiveStream [JSONRPCMessage | Exception ],
311- MemoryObjectSendStream [JSONRPCMessage ],
313+ MemoryObjectReceiveStream [SessionMessage | Exception ],
314+ MemoryObjectSendStream [SessionMessage ],
315+ GetSessionIdCallback | None
312316 ]
313317 ]:
314318 """Create the streams for the server."""
@@ -362,7 +366,8 @@ def __init__(
362366 Args:
363367 params: The params that configure the server. This includes the URL of the server,
364368 the headers to send to the server, the timeout for the HTTP request, and the
365- timeout for the Streamable HTTP connection and whether we need to terminate on close.
369+ timeout for the Streamable HTTP connection and whether we need to
370+ terminate on close.
366371
367372 cache_tools_list: Whether to cache the tools list. If `True`, the tools list will be
368373 cached and only fetched from the server once. If `False`, the tools list will be
@@ -385,8 +390,9 @@ def create_streams(
385390 self ,
386391 ) -> AbstractAsyncContextManager [
387392 tuple [
388- MemoryObjectReceiveStream [JSONRPCMessage | Exception ],
389- MemoryObjectSendStream [JSONRPCMessage ],
393+ MemoryObjectReceiveStream [SessionMessage | Exception ],
394+ MemoryObjectSendStream [SessionMessage ],
395+ GetSessionIdCallback | None
390396 ]
391397 ]:
392398 """Create the streams for the server."""
0 commit comments