code --add-mcp JSON loses quotes when run from PowerShell on Windows
Running
code --add-mcp '<json>'from PowerShell 7.5.3 on Windows 11 with VS Code 1.105.1 fails withInvalid JSON '{name:next-devtools,command:pnpm,...}': SyntaxError: Expected property name or '}' in JSON at position 1because the double-quotes in the JSON are stripped before the CLI parses it. Calling the same command throughnode cli.jssucceeds, so the JSON itself is valid. Is this a bug in next-devtools-mcp, and how can I add the MCP server on Windows?Originally asked on GitHub: https://github.com/vercel/next-devtools-mcp/issues/55
4 answers
This issue is closed as explained: the responder stated it is a VS Code CLI problem, not a bug in next-devtools-mcp — the
code.cmdwrapper on Windows mangles JSON double-quotes when PowerShell passes arguments through cmd.exe. The reporter filed the repro upstream at https://github.com/microsoft/vscode/issues/279280 (opens external site); this thread does not report the status of that upstream issue.Environment: Windows 11 24H2, VS Code 1.105.1 (x64), PowerShell 7.5.3, Node v22.18.0,
coderesolving toC:\Users\toaki\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd.The workaround confirmed in the thread is to bypass
code.cmdand call the VS Code CLI directly with Node, which printedAdded MCP servers: next-devtools:powershellnode "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"]}'Adjust the
cli.jspath to your own VS Code install.A second workaround listed in the thread writes the JSON to a file and reads it back, so PowerShell never passes the quotes as an argument:
powershell@' '{"name":"next-devtools","command":"pnpm","args":["dlx","next-devtools-mcp@latest"]} '@ > .\mcp.json code --add-mcp (Get-Content .\mcp.json -Raw)Note: the here-string as written in the thread has a stray leading single quote on the JSON line that looks like a typo and should be removed for valid JSON. The thread does not show the output of this second workaround.
General advice: any inline JSON passed to
code --add-mcpfrom PowerShell on Windows can hit this quoting problem; the temp-file approach avoids the wrapper quoting entirely.Did this work for you?What a GitHub user tried on GitHub (Worked)
Called the VS Code CLI directly with
node "C:\Users\toaki\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js" --add-mcp '<json>'; the same JSON was accepted and printedAdded MCP servers: next-devtools.Source: https://github.com/vercel/next-devtools-mcp/issues/55 (opens external site)
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Ran
code --add-mcp '{"name":"next-devtools",...}'from pwsh on Windows 11; thecode.cmdwrapper stripped the JSON double-quotes, producingInvalid JSON '{name:next-devtools,...}': SyntaxError: Expected property name or '}' in JSON at position 1.Source: https://github.com/vercel/next-devtools-mcp/issues/55 (opens external site)
Did this work for you?What a GitHub user tried on GitHub (Outcome unclear)
Wrote the JSON to a temp file and passed it with
code --add-mcp (Get-Content .\mcp.json -Raw); the thread lists this as a workaround but shows no output for it.Source: https://github.com/vercel/next-devtools-mcp/issues/55 (opens external site)
Did this work for you?
Related questions
- Why isn't next-devtools-mcp MCP server working in Cursor? (fixed in v0.2.2)
- next-devtools-mcp discover_servers fails on Windows: "No running Next.js dev servers with MCP enabled found"
- next-devtools-mcp in Cursor: ERR_MODULE_NOT_FOUND advanced-patterns.js from npx cache
- Codex goes idle with 'Initialization complete.' after next-devtools.init
- Fix next-devtools-mcp ERR_MODULE_NOT_FOUND (execa) in Cursor on Windows