From 3e0ab1e7ee77c65fee8dc06bfd4e0d2bd7eb8b31 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 11 Mar 2025 14:17:15 +0100 Subject: [PATCH] Drop AbstractAsyncContextManager for proper type hints (#257) --- src/mcp/shared/session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mcp/shared/session.py b/src/mcp/shared/session.py index 3d3988c..da826d6 100644 --- a/src/mcp/shared/session.py +++ b/src/mcp/shared/session.py @@ -8,6 +8,7 @@ import anyio.lowlevel import httpx from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream from pydantic import BaseModel +from typing_extensions import Self from mcp.shared.exceptions import McpError from mcp.types import ( @@ -60,7 +61,7 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]): request_id: RequestId, request_meta: RequestParams.Meta | None, request: ReceiveRequestT, - session: "BaseSession", + session: "BaseSession[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT]", on_complete: Callable[["RequestResponder[ReceiveRequestT, SendResultT]"], Any], ) -> None: self.request_id = request_id @@ -134,7 +135,6 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]): class BaseSession( - AbstractAsyncContextManager, Generic[ SendRequestT, SendNotificationT, @@ -183,7 +183,7 @@ class BaseSession( ]() ) - async def __aenter__(self): + async def __aenter__(self) -> Self: self._task_group = anyio.create_task_group() await self._task_group.__aenter__() self._task_group.start_soon(self._receive_loop)