You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON Parsing Fails & Client Gets Stuck in Waiting When Tool Returns Results with Special Unicode Characters #1356
P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workEnough information for someone to start working on
During my usage, I noticed that if the tool's returned results contain special Unicode characters, it will cause JSON parsing to abort. What's more critical is that when a JSON parsing error occurs on the client side, the parsing function sends the exception directly to the tool-invoking function without wrapping the exception in the format agreed upon by both parties. This prevents the tool-invoking function from properly capturing the exception, leading it to get stuck in a state of continuous waiting.
In mcp.client.sse:
case"message":
try:
message=types.JSONRPCMessage.model_validate_json( # noqa: E501sse.data
)
logger.debug(f"Received server message: {message}")
exceptExceptionasexc:
logger.exception("Error parsing server message")
awaitread_stream_writer.send(exc)
continuesession_message=SessionMessage(message)
awaitread_stream_writer.send(session_message)
Should the exc be encapsulated before executing await read_stream_writer.send(exc)?
Currently, it seems that when an exception is sent, the message cannot be received at line 272 in mcp.shared.session, getting stuck in a wait state.
This is where SSE parsing happens, it uses aiter_lines to iterate the stream, which internally uses LineDecoder with a set of line separators that doesn't match what SSE specifies.
P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workEnough information for someone to start working on
Activity
pja-ant commentedon Sep 10, 2025
Thanks for reporting, I can reproduce this.
From my investigation so far, it looks like the httpx parser is incorrectly treating \u2028 as a line separator, which goes against what the SSE spec mandates: https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream
This is where SSE parsing happens, it uses
aiter_linesto iterate the stream, which internally usesLineDecoderwith a set of line separators that doesn't match what SSE specifies.pja-ant commentedon Sep 10, 2025
And yeah, the exception handling here is bad also for the reasons mentioned.
pja-ant commentedon Sep 10, 2025
Reported issue to httpx-sse: florimondmanca/httpx-sse#34
Revert SSE parsing workaround - fixed in httpx-sse 0.4.2
pja-ant commentedon Oct 8, 2025
The fix in httpx-sse is now landed and released in 0.4.2. Update your dependencies to that version if you need this fix critically.
fix(deps): pin `httpx-sse>=0.4.2` to fix SSE line splitting on U+2028…
fix(server): escape U+2028 / U+2029 in SSE data lines
fix(sse): escape U+2028 / U+2029 in SSE data lines
fix(deps): pin `httpx-sse>=0.4.2` to fix SSE line splitting on U+2028…