From f676f6c0f0a19c0d3f652a59b6eb668cfbfa025f Mon Sep 17 00:00:00 2001 From: ZhangChuanhui <57099533+zhangch-ss@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:52:32 +0800 Subject: [PATCH] fix: catch and rethrow SSEError during SSE connection establishment (#975) Co-authored-by: zhangchuanhui Co-authored-by: Felix Weinberger --- src/mcp/client/sse.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mcp/client/sse.py b/src/mcp/client/sse.py index 7ca8d19a..791c602c 100644 --- a/src/mcp/client/sse.py +++ b/src/mcp/client/sse.py @@ -8,6 +8,7 @@ import httpx from anyio.abc import TaskStatus from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream from httpx_sse import aconnect_sse +from httpx_sse._exceptions import SSEError import mcp.types as types from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client @@ -105,6 +106,9 @@ async def sse_client( await read_stream_writer.send(session_message) case _: logger.warning(f"Unknown SSE event: {sse.event}") + except SSEError as sse_exc: + logger.exception("Encountered SSE exception") + raise sse_exc except Exception as exc: logger.exception("Error in sse_reader") await read_stream_writer.send(exc)