Skip to content

Shell-quote JSON values in tool call examples#172

Merged
jancurn merged 2 commits intomainfrom
claude/apify-rag-browser-WrH9Y
Apr 15, 2026
Merged

Shell-quote JSON values in tool call examples#172
jancurn merged 2 commits intomainfrom
claude/apify-rag-browser-WrH9Y

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented Apr 15, 2026

Summary

Fix the "Call example" output in tools-get to 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

  • Added shellSafeExampleValue() function that wraps JSON-stringified values in single quotes when they contain shell-special characters (brackets, braces, spaces, quotes, etc.)
  • Updated formatToolCallExample() to use shellSafeExampleValue() when generating parameter examples
  • The function preserves simple values (numbers, booleans, null, identifiers) as-is for readability
  • Properly escapes embedded single quotes using the POSIX-portable '\'' technique

Implementation Details

The fix ensures that complex default values like ["markdown"] are rendered as outputFormats:='["markdown"]' instead of outputFormats:=["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

claude added 2 commits April 15, 2026 20:18
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"}').
@jancurn jancurn merged commit c354061 into main Apr 15, 2026
6 checks passed
@jancurn jancurn deleted the claude/apify-rag-browser-WrH9Y branch April 15, 2026 21:06
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.

3 participants