Skip to content

Send MCP request text as UTF-8 so documented notes fit the request limit - #82

Open
hamzatlh wants to merge 2 commits into
prooflinedev:mainfrom
hamzatlh:fix/mcp-utf8-request-size
Open

hamzatlh wants to merge 2 commits into
prooflinedev:mainfrom
hamzatlh:fix/mcp-utf8-request-size

Conversation

@hamzatlh

@hamzatlh hamzatlh commented Nov 22, 2026 •

Copy link
Copy Markdown

Problem

request_reverification documents a note of 1 to 2,000 characters, but a note within that limit is refused before it is sent when it is not ASCII.

_mcp._body serializes every MCP request with json.dumps' default ensure_ascii=True, which escapes each non-ASCII character as \uXXXX (6 bytes, 12 for characters outside the BMP), and only then checks the 8,192-byte request limit. The MCP bridge (prooflinedev/mcp) enforces the same 8,192-byte limit on the UTF-8 JSON that JSON.stringify produces, so the same note works through the bridge and fails in the Python SDK.

2,000-character note Before After
English 2,292 bytes, sent 2,292 bytes, sent
Arabic or accented Latin 12,292 bytes, ValueError 4,292 bytes, sent
Chinese or ✅ 12,292 bytes, ValueError 6,292 bytes, sent

The same applies to ask_codebase questions and every other knowledge and fixes call.

Change

  • proofline/_mcp.py: serialize with ensure_ascii=False and encode with backslashreplace. Text goes out as UTF-8, the bytes the bridge sends. A lone surrogate has no UTF-8 form, so backslashreplace writes it as the JSON escape \udXXX, which is what JSON.stringify does. The 8,192-byte check is unchanged and now measures what is sent.
  • README.md: document the request limit, which was not written down.
  • tests/test_http.py: one sync and async test against the local server.

Verification

  • The new test sends a 2,000-character Arabic and emoji note through client.fixes.request_reverification and checks that the request is at most 8,192 bytes, carries the note as UTF-8, and decodes to the same note on the server. It checks that a lone surrogate keeps its escape and still decodes, and that a request over the limit still raises ValueError before anything is sent. It fails on main with MCP request exceeds 8192 bytes. and passes with the change.
  • python3 scripts/check.py passes (generation, HTTP contracts, wheel and source installs). The suite is 221 tests.
  • End to end with ProoflineClient against the local MCP stub in tests/http_server.py:
main:   note: 2000 characters
        refused before sending: MCP request exceeds 8192 bytes.
branch: note: 2000 characters
        sent: 3968 bytes (limit 8192) -> server received the note intact: True

To reproduce, run the new test with pytest tests/test_http.py -k utf8 on main and on this branch.

Proofline review

I ran Proofline on this branch in my fork (hamzatlh/sdk-python#1). It raised one warning: the oversized-request case counted only tools/call requests, so a regression that sent the initialize handshake before refusing the request would still pass. I agreed and changed the test to assert that the server receives no request at all across the refused call. To check the stronger test, I moved the size check after the handshake in the sync client: the test then fails with assert 8 == 6, and it passes on this branch.

🤖 Generated with Claude Code

_body serialized MCP requests with json.dumps' default ensure_ascii=True,
which escapes every non-ASCII character as \uXXXX (6 bytes, 12 for
astral characters) before the 8,192-byte check. A re-verification note
within the documented 2,000-character limit in Arabic, Chinese, accented
Latin or emoji was refused locally (12,292 bytes) although its UTF-8 body
is 4,292 bytes, the form the MCP bridge sends.

Serialize with ensure_ascii=False and encode with backslashreplace, so a
lone surrogate, which has no UTF-8 form, keeps its JSON escape. Document
the request limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test counted only tools/call requests, so a regression that sent the
initialize handshake before refusing an oversized request would still
pass. Count every request the server receives across the refused call.
Found by a Proofline review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant