11import logging
2- from typing import Protocol , runtime_checkable , Callable , Awaitable
3- from uuid import UUID
2+ from collections .abc import Awaitable , Callable
43from contextlib import asynccontextmanager
4+ from typing import Protocol , runtime_checkable
5+ from uuid import UUID
56
67import mcp .types as types
78
@@ -35,7 +36,7 @@ async def publish_message(
3536 @asynccontextmanager
3637 async def active_for_request (self , session_id : UUID , callback : MessageCallback ):
3738 """Request-scoped context manager that ensures the listener is active.
38-
39+
3940 Args:
4041 session_id: The UUID of the session to activate
4142 callback: Async callback function to handle messages for this session
@@ -57,7 +58,8 @@ async def session_exists(self, session_id: UUID) -> bool:
5758class InMemoryMessageQueue :
5859 """Default in-memory implementation of the MessageQueue interface.
5960
60- This implementation immediately calls registered callbacks when messages are received.
61+ This implementation immediately calls registered callbacks when messages
62+ are received.
6163 """
6264
6365 def __init__ (self ) -> None :
@@ -78,7 +80,7 @@ async def publish_message(
7880 logger .debug (f"Called callback for session { session_id } " )
7981 else :
8082 logger .warning (f"No callback registered for session { session_id } " )
81-
83+
8284 return True
8385
8486 @asynccontextmanager
@@ -87,7 +89,7 @@ async def active_for_request(self, session_id: UUID, callback: MessageCallback):
8789 self ._active_sessions .add (session_id )
8890 self ._callbacks [session_id ] = callback
8991 logger .debug (f"Registered session { session_id } with callback" )
90-
92+
9193 try :
9294 yield
9395 finally :
0 commit comments