Skip to content

Commit ea74ee7

Browse files
committed
fix: type check issue for Exception
- changed the handle_exception functions implementation - replaced the Exception parameter with BaseExceptionGroup[Exception]
1 parent c2dc97f commit ea74ee7

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/mcp/client/sse.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import httpx
88
from anyio.abc import TaskStatus
99
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
10-
from exceptiongroup import ExceptionGroup, catch
10+
from exceptiongroup import BaseExceptionGroup, catch
1111
from httpx_sse import aconnect_sse
1212

1313
import 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
3128
async 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

Comments
 (0)