fix(mcp): pass MCP stdio server args as separate array elements to pr… (#1222)

* fix(mcp): pass MCP stdio server args as separate array elements to prevent shell injection (issue #131)

* fix: extract buildMcpStdioCommand helper and add regression tests (PR #131 review)

* fix(mcp): handle shell -c prefix in buildMcpStdioCommand (PR #131 review)

When CLAUDE_CODE_SHELL_PREFIX contains -c (e.g. sh -c, bash -c), the
original MCP command and args must be joined as a single shell command
string after -c. Without this join, sh -c runs only the first word as
the command string and treats remaining entries as positional parameters,
so the MCP server never receives its configured arguments.

- Detect -c in prefixParts and join command+args into one string
- Non-shell prefixes (docker run --rm -i, bunx, etc.) unchanged
- Add regression test for sh -c pattern

* chore: add .tmp to gitignore

* fix(mcp): shell-quote each arg in sh -c join to prevent injection (PR #131 P2 fixup)

* fix(mcp): preserve spaced executable path in buildMcpStdioCommand -c split (PR #131 fixup)

Use lastIndexOf(' -c') instead of whitespace split so paths like 'C:\Program Files\Git\bin\bash.exe -c' are handled correctly. Removes dead old code left in from previous edit.
This commit is contained in:
ArkhAngelLifeJiggy
2026-06-09 06:23:30 +08:00
committed by GitHub
parent 492cde2619
commit 0d4e247905
3 changed files with 178 additions and 7 deletions
+2 -1
View File
@@ -17,4 +17,5 @@ package-lock.json
coverage/
agent.log
plan/
temp_reference/
.tmp
temp_reference/