77import httpx
88from anyio .abc import TaskStatus
99from anyio .streams .memory import MemoryObjectReceiveStream , MemoryObjectSendStream
10- from exceptiongroup import ExceptionGroup , catch
10+ from exceptiongroup import BaseExceptionGroup , catch
1111from httpx_sse import aconnect_sse
1212
1313import mcp .types as types
@@ -19,13 +19,10 @@ def remove_request_params(url: str) -> str:
1919 return urljoin (url , urlparse (url ).path )
2020
2121
22- def handle_exception (exc : Exception ) -> str :
22+ def handle_exception (exc : BaseExceptionGroup [ Exception ] ) -> str :
2323 """Handle ExceptionGroup and Exceptions for Client transport for SSE"""
24- if isinstance (exc , ExceptionGroup ):
25- messages = "; " .join (str (e ) for e in exc .exceptions )
26- raise Exception (f"TaskGroup failed with: { messages } " ) from None
27- else :
28- raise Exception (f"TaskGroup failed with: { exc } " ) from None
24+ messages = "; " .join (str (e ) for e in exc .exceptions )
25+ raise Exception (f"TaskGroup failed with: { messages } " ) from None
2926
3027@asynccontextmanager
3128async def sse_client (
@@ -50,7 +47,7 @@ async def sse_client(
5047 write_stream , write_stream_reader = anyio .create_memory_object_stream (0 )
5148
5249 with catch ({
53- Exception : handle_exception ,
50+ Exception : handle_exception
5451 }):
5552 async with anyio .create_task_group () as tg :
5653 try :
0 commit comments