Resolve local environment variables in MCP server definitions

I am using cursor-agent cli version 2025.10.22-f894c2.

in mcp.json of the project i define my custom mcp server (stdio) and trying to pass my env variable

```
“custom-mcp”: {
“command”: “custom”,
“args”: [ “mcp”, “start” ],
“env”: {
“INTERNAL_TOKEN”: “${env:INTERNAL_TOKEN}”
}
},
```

while executing tools from this mcp server - token is not passed and I get auth error.

What i am doing wrong?

PS: I’ve tried both “INTERNAL_TOKEN”: “${env:INTERNAL_TOKEN}” and “INTERNAL_TOKEN”: “${INTERNAL_TOKEN}”
Does not work

Bumping this up.

The cursor cli doesn’t interpolate env vars as described in the documentation (eg. "API_KEY": "${env:API_KEY}").

cursor-agent –version: 2025.11.25-d5b3271

mcp.json
{
"mcpServers": {
"my-mcp-server": {
"type": "stdio",
"command": "uv",
"args": [
"run",
"--with=mcp",
"--directory=...",
"mcp",
"run",
"stdio_runner.py:server"
],
"env": {
"MCP_WS_URL": "${env:MCP_WS_URL}",
"RUN_SESSION_ID": "${env:RUN_SESSION_ID}",
"RUN_PROJECT_ID": "${env:RUN_PROJECT_ID}"
}
}
}
}

The stdio_runner.py sees unexpanded literals:
DEBUG Environment snapshot | {'MCP_WS_URL': '${env:MCP_WS_URL}', 'RUN_PROJECT_ID': '${env:RUN_PROJECT_ID}', ...}

Any help?
Thanks!

This is still broken as of 2026.01.02-80e4d9b. Means I am having to wrap all my MCP server commands I put in mcp.json with wrappers which source environment variables another way. Currently I am running the agent headless in a container, passing in my MCP authentication tokens via environment variables at container execution time. The CURSOR_API_KEY is interpolated up by the agent but not for defined MCP servers.

I seem to still be running into this. Any further updates or suggestions?

bumping again - we have an internal gitlab MCP server, defined like this in mcp.json:

    "gitlab-mcp-server": {
      "url": "https://gitlab-mcp.example.com/mcp",
      "capabilities": {
        "tools": true
      },
      "headers": {
        "Authorization": "Bearer <GITLAB_MCP_TOKEN>"
      }
    },

replacing <GITLAB_MCP_TOKEN> with the raw token works, but with ${env.GITLAB_MCP_TOKEN} , while GITLAB_MCP_TOKEN is exported in my ~/.zshrc file fails (I get 401 (unauthorized) status from the server).

I thought it’s solved because config interpolation is documented here: Model Context Protocol (MCP) | Cursor Docs

I just tried this for our SmartSheet MCP server as I was having the same issue. I think the key is you had env. instead of env:
Using”Bearer ${env:SS_API_KEY}” I finally got this to work.

Thanks @Ryan_Sturm ; unfortunately, that didn’t help - running the agent CLI with “${TOKEN}” works, while “${env:TOKEN}" doesn’t.

for those of you who want a quick check, you can use this command (this is how I checked it everytime):

❯ cat ~/.cursor/commands/check-mcp.md
# Check MCP connections

Check connection to the following MCP servers - <relevant MCP servers>
For each server, perform an arbitrary opreration that requires a valid authentiation token.
Do not modify any files in the filesystem.
when done, print to the screen a brief summary.

EDIT:

I think I found an interesting phenomenon - looks like the IDE and the CLI interpret things differently:

  1. IDE - ${env:VAR} works, while ${VAR} doesn’t
  2. CLI - ${VAR} works, while ${env:VAR} doesn’t

(assumption - both tools use ~/.cursor/mcp.json)

if someone from Cursor’s team can check this, that’d be great :folded_hands:t2: