Can't use/escape spaces or use environment variables in MCP configurations

Describe the Bug

Hey,

I can’t find a way to escape spaces in MCP configurations. This is an issue for me because I have to use –static-oauth-client-metadata of mcp-remote with a scope parameter, which has spaces.

It’s also mentioned in the docs of mcp-remote so I assume it’s probably already known by the community, but I couldn’t find anything here:

Note: Cursor and Claude Desktop (Windows) have a bug where spaces inside args aren’t escaped when it invokes npx, which ends up mangling these values.

It provides this workaround, using env variables:

{
  // rest of config...
  "args": [
    "mcp-remote",
    "https://remote.mcp.server/sse",
    "--header",
    "Authorization:${AUTH_HEADER}" // note no spaces around ':'
  ],
  "env": {
    "AUTH_HEADER": "Bearer <auth-token>" // spaces OK in env vars
  }
},

But this doesn’t work either for me, it looks like the $ is escaped and I can’t find a way to use environment variables in the args.

Steps to Reproduce

Try this configuration:

{
  "mcpServers": {
    "buggy": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:4567",
        "--static-oauth-client-metadata",
        "{\"scope\":\"openid groups\"}"
      ]
    }
  }
}

MCP logs will output:

[13382] Fatal error: SyntaxError: Unterminated string in JSON at position 16 (line 1 column 17)
    at JSON.parse (<anonymous>)
    at parseCommandLineArgs (file:///[redacted]/_npx/705d23756ff7dacc/node_modules/mcp-remote/dist/chunk-OXNXVROF.js:13830:40)
    at file:///[redacted]/_npx/705d23756ff7dacc/node_modules/mcp-remote/dist/proxy.js:188:1
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

No problem without the space between openid and groups (ie if I just pick one).

And with:

{
  "mcpServers": {
    "buggy": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:4567",
        "--static-oauth-client-metadata",
        "${SCOPES}"
      ],
      "env": {
        "SCOPES": "{\"scope\":\"openid groups\"}"
      }
    }
  }
}

It will output:

[13474] Fatal error: SyntaxError: Unexpected token '$', "${SCOPES}" is not valid JSON
    at JSON.parse (<anonymous>)
    at parseCommandLineArgs (file:///[redacted]/_npx/705d23756ff7dacc/node_modules/mcp-remote/dist/chunk-OXNXVROF.js:13830:40)
    at file:///[redacted]/_npx/705d23756ff7dacc/node_modules/mcp-remote/dist/proxy.js:188:1
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Expected Behavior

  • Spaces should be escaped
  • Environment variables should work

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.2.2 (Universal)
VSCode Version: 1.99.3
Commit: faa03b17cce93e8a80b7d62d57f5eda6bb6ab9f0
Date: 2025-07-07T06:07:27.002Z
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.5.0

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

1 Like

I’m having the same issue. I also tried doing the env workaround, and it didn’t work.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.