-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
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: E501
sse.data
)
logger.debug(f"Received server message: {message}")
except Exception as exc:
logger.exception("Error parsing server message")
await read_stream_writer.send(exc)
continue
session_message = SessionMessage(message)
await read_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.
Example Code
When there is `\u2028` in the tool's results.
Python & MCP Python SDK
python3.13.7
MCP Python SDK:1.13.1