Skip to content

Preserve UTF-8 text in MCP server responses - #1398

Open
Ramji-Purwar wants to merge 1 commit into
grame-cncm:master-devfrom
Ramji-Purwar:fix/mcpui-utf8-responses
Open

Ramji-Purwar wants to merge 1 commit into
grame-cncm:master-devfrom
Ramji-Purwar:fix/mcpui-utf8-responses

Conversation

@Ramji-Purwar

Copy link
Copy Markdown
Contributor

On targets where plain char is signed, removeControlChars() drops every non-ASCII UTF-8 byte from MCP response JSON. For example, a slider named Fréquence in group Synthé 音 🎵 is described as Frquence (Synth ). Initialization names and successful tool-call confirmations are corrupted as well.

Classify response bytes as unsigned so UTF-8 bytes survive the existing control-character filter. Pass unsigned bytes to std::isalnum() when sanitizing tool names, avoiding undefined behavior for the same non-ASCII input.

Validation with GCC 16.2.1 on Linux x86_64:

  • python3 -m unittest discover -s tests/mcpui-tests -v passes all five tests, each exercising both -fsigned-char and -funsigned-char builds.
  • Tests use the real McpUI server over stdin/stdout and parse its JSON responses for initialize, tools/list, and tools/call. They also verify UTF-8 preservation and existing ASCII control removal directly.
  • Against the original header, four tests fail under signed char; the ASCII control test and unsigned-char cases pass.

All five tests also pass with the change applied to current master-dev (f06f2697).

AddressSanitizer/UndefinedBehaviorSanitizer validation could not run because the installed compiler's sanitizer runtime libraries are missing.

Classify response bytes as unsigned so the control-character filter preserves non-ASCII UTF-8 text. Pass unsigned bytes to isalnum when sanitizing tool names. Add real JSON-RPC server regressions for initialization, tool descriptions, and call confirmations under both char signedness modes.
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