7
7
import httpx
8
8
from anyio .abc import TaskStatus
9
9
from anyio .streams .memory import MemoryObjectReceiveStream , MemoryObjectSendStream
10
- from exceptiongroup import ExceptionGroup , catch
10
+ from exceptiongroup import BaseExceptionGroup , catch
11
11
from httpx_sse import aconnect_sse
12
12
13
13
import mcp .types as types
@@ -19,13 +19,10 @@ def remove_request_params(url: str) -> str:
19
19
return urljoin (url , urlparse (url ).path )
20
20
21
21
22
- def handle_exception (exc : Exception ) -> str :
22
+ def handle_exception (exc : BaseExceptionGroup [ Exception ] ) -> str :
23
23
"""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
29
26
30
27
@asynccontextmanager
31
28
async def sse_client (
@@ -50,7 +47,7 @@ async def sse_client(
50
47
write_stream , write_stream_reader = anyio .create_memory_object_stream (0 )
51
48
52
49
with catch ({
53
- Exception : handle_exception ,
50
+ Exception : handle_exception
54
51
}):
55
52
async with anyio .create_task_group () as tg :
56
53
try :
0 commit comments