Shell-quote JSON values in tool call examples#172
Merged
Conversation
Array and object defaults like ["markdown"] were rendered without shell
quoting, so the shell stripped the inner quotes and mcpc received
[markdown], which is not valid JSON. Wrap JSON-stringified values in
single quotes whenever they contain characters that would be mangled by
shell word-splitting, matching the style already documented in
CLAUDE.md (e.g. config:='{"key":"value"}').
…ser-WrH9Y # Conflicts: # CHANGELOG.md
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.
Summary
Fix the "Call example" output in
tools-getto properly shell-quote JSON values (arrays, objects, and strings) so they can be safely copy-pasted into a shell without being mangled by word-splitting.Changes
shellSafeExampleValue()function that wraps JSON-stringified values in single quotes when they contain shell-special characters (brackets, braces, spaces, quotes, etc.)formatToolCallExample()to useshellSafeExampleValue()when generating parameter examples'\''techniqueImplementation Details
The fix ensures that complex default values like
["markdown"]are rendered asoutputFormats:='["markdown"]'instead ofoutputFormats:=["markdown"], preventing the shell from stripping the inner quotes and causing invalid JSON to reach the parser.Updated test expectations to match the new quoting behavior and added regression tests for array and object default values.
https://claude.ai/code/session_01MocusWPNsL6TBFdAYBLyJx