Repository navigation
Preserve UTF-8 text in MCP server responses - #1398
Open
Ramji-Purwar wants to merge 1 commit into
Open
Ramji-Purwar wants to merge 1 commit into
Ramji-Purwar wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On targets where plain
charis signed,removeControlChars()drops every non-ASCII UTF-8 byte from MCP response JSON. For example, a slider namedFréquencein groupSynthé 音 🎵is described asFrquence (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 -vpasses all five tests, each exercising both-fsigned-charand-funsigned-charbuilds.initialize,tools/list, andtools/call. They also verify UTF-8 preservation and existing ASCII control removal directly.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.