Skip to content

CLI --add-mcp JSON argument loses quotes when called from PowerShell via code.cmd #279280

@toakiryu

Description

@toakiryu

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.106.2
  • OS Version: Windows 11 Pro (Edition: Windows 11 Pro, Version: 24H2, OS build: 26100.7171)
  • PowerShell Version: 7.5.4
  • Node.js Version: 22.21.1

Steps to Reproduce:

  1. <path-to-vscode>\resources\app\out\cli.js
// Added temporarily to log process.argv for debugging
+ console.log("process.argv:", process.argv);
  1. From PowerShell, execute the following command:
$ code --add-mcp '{"name":"example","url":"http://localhost:3001"}'
  1. The VS Code CLI receives the JSON argument with the double quotes stripped or mangled.
    Example (actual argv received):
[
  'C:\\Users\\toaki\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe',
  'C:\\Users\\toaki\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js',
  '--add-mcp',
  '{name:example,url:http://localhost:3001}'
]
Invalid JSON '{name:example,url:http://localhost:3001}': SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
  1. Contrast this with calling the tool directly via Node:
[
  'C:\\Users\\toaki\\AppData\\Local\\Volta\\tools\\image\\node\\22.21.1\\node.exe',
  'C:\\Users\\toaki\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js',
  '--add-mcp',
  '{"name":"example","url":"http://localhost:3001"}'
]

This correctly preserves the JSON quotes and works as expected.

Expected Behavior:

  • The code CLI should preserve JSON quotes when invoked from PowerShell, without arguments being altered by code.cmd or the underlying cmd.exe invocation.

Actual Behavior:

  • When called from PowerShell, code.cmd mangles or strips JSON quotation marks, causing the --add-mcp argument to become invalid JSON.

Additional Information:

  • This issue was originally investigated while using next-devtools-mcp, and the maintainers confirmed the problem originates from VS Code’s CLI wrapper (code.cmd) rather than their package.
  • I have checked existing issues and found a few that appear related to quoting behavior on Windows, but none match this specific scenario involving code.cmd and PowerShell.
  • They recommended filing this report here.

Workaround:

  • Calling the MCP CLI directly with Node (e.g., node cli.js …) works as expected and preserves the JSON argument.

Update:

  • I have upgraded VS Code to version 1.106.2 as suggested, but the issue still persists.

Metadata

Metadata

Assignees

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