I would like the API_KEY value to be a local environment variable’s value. This way I can add this MCP server definition to my team’s Git repo and everyone will be able to easily configure their MCP servers.
Bumping this. We’re in the same situation, it’s extremely important for our team. We want to share our MCP configuration via git and without this behavior, it’s impossible. We’re considering moving to VScode AI agent for this feature.
This would be the natural evolution given that cursor now supports rules scoped to a given project: these will be committed to version control but the “secret” needs to stay out.
Using an environment variable would be the standard strategy there.
The second option would be to let the caller specify a path such as ~/.mysecret. Not as elegant, but works too.
The approach we recommend is to use a wrapper script that loads the .env variables before calling the npx script or whatever your server is. We don’t provide the full .env variables to all servers for security reasons, and there is a very easy workaround
I have tried many permutations of the dotenv command at this point (as well as many emplacements for the .env file) , even though it is possible I am missing something obvious
Hey, saw this problem and built a small tool, mcp-safe-run, to handle exactly this. It lets you use placeholders like file:./secret.txt or keyring:svc:acc in your mcp.json args, keeping secrets out of Git.
which works, BUT with Cursor the very same command produce
2025-04-23 05:58:08.416 [info] arch: Starting new stdio process with command: mcp-safe-run -p brave_search -- npx -y @modelcontextprotocol/server-brave-search
2025-04-23 05:58:08.416 [error] arch: Client error for command A system error occurred (spawn mcp-safe-run ENOENT)
While in the devcontaiver, where I deal with everything, it is installed and working. I suppose that MCP’s are running in some special container which is prepared for that and i can’t find how can i switch it or tweak
There is the VSCode suggested way to manage this, like ${env:FOO} and it was just adopted by Roo code. It would be great if Cursor used the same syntax
As an option, it might be to allow re-use of the dev-container (or host machine) as it allows to do VSCode.
Before the latest changes in VSCode, it was nice to have such a sort of isolation, but now it’s more of a hassle rather than a value. Those, who have security concerns are using workspaces and/or devcontainers anyway, and ironically, that group of users has lthe east options to manage MCP.json file and have to treat it as secret
I ended up publishing the “wrap it with a script” idea as a simple NPM package so that at least for simple stdio use cases I can define any env vars in a file and then reference them by name in the cursor MCP config by prefixing the command with npx envmcp: envmcp - npm