Use environment variables in your Cursor MCP server definitions.
Prefix your stdio command with npx envmcp
and reference env vars by name in your cursor MCP config.
You can either pass the filepath of your env file as an argument...
{
"my_mcp_server": {
"command": "npx",
"args": [
"envmcp",
"--env-file",
"/path/to/my.env.file",
"start-my-mcp-server",
"$MY_NAMED_ENVIRONMENT_VARIABLE",
]
},
"example_with_shorthand_flag_name": {
"command": "npx",
"args": [
"envmcp",
"-e",
"/path/to/my.env.file",
"npx", "pull-something-else-with-npx", "$MY_DATABASE_CONNECTION_STRING",
]
}
}
... or put your secrets into a file called .env.mcp
in your user's home directory, which will be looked up by default:
{
"my_mcp_server": {
"command": "npx",
"args": [
"envmcp",
"start-my-mcp-server",
"$MY_NAMED_ENVIRONMENT_VARIABLE",
]
}
}
Receives a shell command as input, loads environment variables from an env file, and then executes the command
Store the secrets needed by your MCP server config in a file called .env.mcp in your home directory, and then replace this...
{
"my_database": {
"command": "start-my-mcp-server",
"args": [
"my secret connection string",
]
},
"my_other_mcp_server": {
"command": "start-my-other-mcp-server",
"env": {
"MY_API_KEY": "my api key"
}
}
}
... with this:
{
"my_database": {
"command": "npx",
"args": [
"envmcp",
"start-my-mcp-server",
"$MY_DATABASE_CONNECTION_STRING",
]
},
"my_other_mcp_server": {
"command": "npx",
"args": [
"envmcp",
"start-my-other-mcp-server",
]
}
}
npm install -g envmcp
envmcp [--env-file <path>] <command> [args...]
The tool will:
- Look for a
.env.mcp
file in the current directory - If not found, it will search up the directory tree for a
.env.mcp
file - As a last resort, it will check for
~/.env.mcp
- If
--env-file
or-e
is specified, it will use that file instead of searching - Load the environment variables from the found
.env.mcp
file - Execute the specified command with any provided arguments
--env-file <path>
or-e <path>
: Specify a custom path to the environment file
The .env.mcp
file follows the standard environment file format:
KEY=value
ANOTHER_KEY=another value
# This is a comment
QUOTED_VALUE="value with spaces"
See the sample.env.mcp
file for a more detailed example.
Contributions are welcome: please feel free to open issues or PRs!
- Node.js 14 or later
- npm
# Install dependencies
npm install
# Build the package
npm run build
# Log in to npm
npm login
# Publish the package
npm publish
MIT