Skip to content

CLI: code --add-mcp <json> strips quotes when invoked from PowerShell on Windows #55

@toakiryu

Description

@toakiryu

CLI: code --add-mcp <json> loses quotes when invoked from PowerShell (Windows)

Summary

Invoking code --add-mcp '<json>' from PowerShell (pwsh) causes the JSON double-quotes to be stripped or mangled, leading to JSON parse errors. Running the VS Code CLI implementation (cli.js) directly with node succeeds, which suggests the issue is in the PowerShell → cmd handoff or the code wrapper's argument handling.


Environment

  • OS: Windows 11 Pro (Edition: Windows 11 Pro, Version: 24H2, OS build: 26100.6899)
  • VS Code: code --version output:
    • 1.105.1
    • 7d842fb85a0275a4a8e4d7e040d2625abbf7f084
    • x64
  • Shell: pwsh.exe (PowerShell/Core)
  • PowerShell: 7.5.3
  • Node: v22.18.0
  • code executable: C:\Users\toaki\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd

Steps to reproduce (minimal)

  1. Open PowerShell (pwsh).
  2. Run (copy-paste):
code --add-mcp '{"name":"next-devtools","command":"pnpm","args":["dlx","next-devtools-mcp@latest"]}'
  1. Expected: MCP server is added, or CLI prints a success message.
  2. Actual: Error like:
Invalid JSON '{name:next-devtools,command:pnpm,args:[dlx,next-devtools-mcp@latest]}': SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)

(Quotes appear to be removed before parsing.)


Control / Workaround

Calling the CLI directly via node succeeds, showing the JSON is valid and the internal CLI can accept it:

node "C:\Users\toaki\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js" --add-mcp '{"name":"next-devtools","command":"pnpm","args":["dlx","next-devtools-mcp@latest"]}'

Output:

Added MCP servers: next-devtools

Temporary workarounds:

  • Call cli.js directly with node as above.
  • Write JSON to a temporary file and read it in PowerShell:
@'
'{"name":"next-devtools","command":"pnpm","args":["dlx","next-devtools-mcp@latest"]}
'@ > .\mcp.json
code --add-mcp (Get-Content .\mcp.json -Raw)

Expected behavior

JSON passed from PowerShell should be forwarded intact to the code CLI and parsed successfully.


Actual behavior

Double-quotes in JSON are removed when code is invoked from PowerShell, resulting in a parse error.


Notes

This appears to be an argument-quoting/escaping issue when PowerShell hands arguments to the code wrapper (code.cmd) which forwards %* to Code.exe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions