fix: catch and rethrow SSEError during SSE connection establishment (#975)

Co-authored-by: zhangchuanhui <zhangchal@digitalchina.com>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
This commit is contained in:
ZhangChuanhui 2025-09-30 22:52:32 +08:00 • committed by GitHub
commit f676f6c0f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)