Skip to content

Unicode characters cause JSONRPCMessage.model_validate_json validation error #2288

Closed

Description

@vladman-25

Question

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

  1. Does this change address the Unicode validation issue described above?
  2. If so, when is the next release expected that will include this fix?

Thanks in advance!

Additional Context

python==3.11.1
mcp==1.26.0

Activity

  1. maxisbey commented on Mar 12, 2026

    @maxisbey
    Contributor

    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.

    AI Disclaimer

  2. added
    needs confirmationNeeds confirmation that the PR is actually required or needed.
    on Mar 12, 2026
  3. vladman-25 commented on Mar 12, 2026

    @vladman-25
    Author

    Thanks for the clarification!

    Here is the full error message:

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs confirmationNeeds confirmation that the PR is actually required or needed.questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions