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
Unicode characters cause JSONRPCMessage.model_validate_json validation error #2288
Unicode characters cause JSONRPCMessage.model_validate_json validation error
Description
I've encountered an error in the latest version related to handling Unicode characters.
The issue occurs in:
File "mcp/client/streamable_http.py", line 385, in _handle_json_response
message = JSONRPCMessage.model_validate_json(content)
File "pydantic/main.py", line 766, in model_validate_json
return cls.__pydantic_validator__.validate_json(
pydantic_core._pydantic_core.ValidationError: 1 validation error for JSONRPCMessage
This validation step appears to fail when the JSON payload contains certain Unicode characters (for example "ó").
Investigation
Looking at the current codebase, I noticed that this logic has been updated to use:
jsonrpc_message_adapter.validate_json(...)
instead of:
JSONRPCMessage.model_validate_json(...)
Questions
Does this change address the Unicode validation issue described above?
If so, when is the next release expected that will include this fix?
Thanks for the report! A couple of things to untangle here:
On the model_validate_json → validate_json change — that's from #1908, which dropped RootModel from JSONRPCMessage as a refactoring cleanup. Both paths use the same underlying pydantic-core JSON parser, so this change doesn't affect Unicode handling and won't change the behavior you're seeing.
On the error itself — ó in properly UTF-8-encoded JSON parses fine (I tested this directly). The most likely explanation is that your server is sending responses encoded as latin-1/windows-1252 rather than UTF-8. In those encodings, ó is the single byte 0xF3, which isn't a valid UTF-8 lead byte — so pydantic's parser rejects it. Responses containing only ASCII would pass through fine since ASCII bytes are identical across these encodings, which matches the "only fails with Unicode" pattern you're describing.
Note that both RFC 8259 §8.1 and the MCP spec require UTF-8 for JSON-RPC messages, so if this is the cause, the fix belongs server-side.
To confirm: could you share the full ValidationError output? Your traceback is truncated right after 1 validation error for JSONRPCMessage — the next line should say either invalid unicode code point at line 1 column N (which would confirm the encoding mismatch) or something else entirely (which would mean we're looking at a different issue). Also helpful: which server you're connecting to, and whether you're able to capture the raw response bytes.
pydantic_core._pydantic_core.ValidationError: 1 validation error for JSONRPCMessage
Invalid JSON: invalid unicode code point at line 1 column 12945
So it does appear to be the exact error you mentioned.
From your explanation, my understanding is the correct fix would be to update the server to emit properly UTF-8-encoded JSON.
However, in the hypothetical case that changing the server encoding is not possible, would there be any recommended workaround on the client side? For example, would it be possible to introduce a preprocessing step that attempts to re-decode the raw response bytes (e.g., latin-1 -> UTF-8) before passing it to the JSON parser?
LE: This should not be possible, our server responds with � characters by default.
Activity
maxisbey commentedon Mar 12, 2026
Thanks for the report! A couple of things to untangle here:
On the
model_validate_json→validate_jsonchange — that's from #1908, which droppedRootModelfromJSONRPCMessageas a refactoring cleanup. Both paths use the same underlying pydantic-core JSON parser, so this change doesn't affect Unicode handling and won't change the behavior you're seeing.On the error itself —
óin properly UTF-8-encoded JSON parses fine (I tested this directly). The most likely explanation is that your server is sending responses encoded as latin-1/windows-1252 rather than UTF-8. In those encodings,óis the single byte0xF3, which isn't a valid UTF-8 lead byte — so pydantic's parser rejects it. Responses containing only ASCII would pass through fine since ASCII bytes are identical across these encodings, which matches the "only fails with Unicode" pattern you're describing.Note that both RFC 8259 §8.1 and the MCP spec require UTF-8 for JSON-RPC messages, so if this is the cause, the fix belongs server-side.
To confirm: could you share the full
ValidationErroroutput? Your traceback is truncated right after1 validation error for JSONRPCMessage— the next line should say eitherinvalid unicode code point at line 1 column N(which would confirm the encoding mismatch) or something else entirely (which would mean we're looking at a different issue). Also helpful: which server you're connecting to, and whether you're able to capture the raw response bytes.AI Disclaimer
vladman-25 commentedon Mar 12, 2026
Thanks for the clarification!
Here is the full error message:
So it does appear to be the exact error you mentioned.
From your explanation, my understanding is the correct fix would be to update the server to emit properly UTF-8-encoded JSON.
However, in the hypothetical case that changing the server encoding is not possible, would there be any recommended workaround on the client side? For example, would it be possible to introduce a preprocessing step that attempts to re-decode the raw response bytes (e.g., latin-1 -> UTF-8) before passing it to the JSON parser?LE: This should not be possible, our server responds with � characters by default.