|
18 | 18 | from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
19 | 19 | from httpx_sse import EventSource, ServerSentEvent, aconnect_sse
|
20 | 20 |
|
| 21 | +from mcp.client.sse import compliant_aiter_sse |
21 | 22 | from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client
|
22 | 23 | from mcp.shared.message import ClientMessageMetadata, SessionMessage
|
23 | 24 | from mcp.types import (
|
@@ -211,7 +212,8 @@ async def handle_get_stream(
|
211 | 212 | event_source.response.raise_for_status()
|
212 | 213 | logger.debug("GET SSE connection established")
|
213 | 214 |
|
214 |
| - async for sse in event_source.aiter_sse(): |
| 215 | + # Use compliant SSE iterator to handle Unicode correctly (issue #1356) |
| 216 | + async for sse in compliant_aiter_sse(event_source): |
215 | 217 | await self._handle_sse_event(sse, read_stream_writer)
|
216 | 218 |
|
217 | 219 | except Exception as exc:
|
@@ -240,7 +242,8 @@ async def _handle_resumption_request(self, ctx: RequestContext) -> None:
|
240 | 242 | event_source.response.raise_for_status()
|
241 | 243 | logger.debug("Resumption GET SSE connection established")
|
242 | 244 |
|
243 |
| - async for sse in event_source.aiter_sse(): |
| 245 | + # Use compliant SSE iterator to handle Unicode correctly (issue #1356) |
| 246 | + async for sse in compliant_aiter_sse(event_source): |
244 | 247 | is_complete = await self._handle_sse_event(
|
245 | 248 | sse,
|
246 | 249 | ctx.read_stream_writer,
|
@@ -323,7 +326,8 @@ async def _handle_sse_response(
|
323 | 326 | """Handle SSE response from the server."""
|
324 | 327 | try:
|
325 | 328 | event_source = EventSource(response)
|
326 |
| - async for sse in event_source.aiter_sse(): |
| 329 | + # Use compliant SSE iterator to handle Unicode correctly (issue #1356) |
| 330 | + async for sse in compliant_aiter_sse(event_source): |
327 | 331 | is_complete = await self._handle_sse_event(
|
328 | 332 | sse,
|
329 | 333 | ctx.read_stream_writer,
|
|
0 commit comments