fix: preserve quoted args with spaces when launching via CLI#1162
Open
petereon wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: preserve quoted args with spaces when launching via CLI#1162petereon wants to merge 1 commit intomodelcontextprotocol:mainfrom
petereon wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Args containing spaces (e.g. --description 'get todays date') were silently split into multiple tokens by the proxy, breaking MCP servers that rely on multi-word argument values. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Fixes a bug where CLI arguments containing spaces lose their quoting when passed through
start.jsto the proxy server. The root cause is a singleArray.join(" ")call that collapses the args array into a flat string, making multi-word arguments indistinguishable from multiple single-word arguments by the timeshellParseArgsruns in the proxy.Type of Change
Changes Made
Root cause
client/bin/start.jsjoined the args array with a plain space before passing it to the server process:This transforms
["--description", "get todays date"]into"--description get todays date". From that point on, the three words are indistinguishable, andshellParseArgsin the proxy correctly splits them — producing the wrong result.Fix
client/bin/start.js— serialize as a JSON array instead:server/src/index.ts—/configendpoint — convert the JSON array back to a properly shell-quoted string for the client UI.shell-quote(already a dependency) is used to produce e.g.--description 'get todays date', whichshellParseArgsin the proxy correctly parses back to a single element. Legacy plain shell strings (from direct server invocations) pass through unchanged.server/src/index.ts—createTransport()— defensive hardening: tryJSON.parseonquery.argsfirst; if it is a valid array use it directly, otherwise fall back toshellParseArgs. This handles any direct API callers that send a JSON array.server/__tests__/args-parsing.test.ts(new) — 15 vitest tests covering the full round-trip and each conversion step in isolation.Related Issues
N/A
Testing
Test Results and/or Instructions
Automated tests (
cd server && npm test):Manual reproduction (before fix):
bunx @modelcontextprotocol/inspector sh2mcp \ --tool date --description 'get todays date' --command dateProxy logs showed:
After fix:
"get todays date"appears as a single element — 5 args total instead of 7.Checklist
npm run prettier-fix)Breaking Changes
None. Legacy invocations that pass
--args="..."as a plain shell string to the server directly continue to work — the/configendpoint detects whether the value is a JSON array or a plain string and handles each case accordingly.Additional Context
The data flow through the pipeline (showing where corruption occurred):