A zero-dependency Node.js module that loads MCP (Model Context Protocol) environment variables and executes commands with those variables set. This tool creates temporary scripts to run commands with specific environment variables, making it easy to manage different configurations for your MCP applications.
- Zero Dependencies: Only uses Node.js built-in modules (except for
dotenv) - Cross-Platform Support: Works on Windows, macOS, and Linux
- Environment Variable Management: Loads variables from
.env.mcp(in your user directory) file or custom env file - Script Caching: Reuses generated scripts for identical commands to improve performance
- Secure: Uses MD5 hashing for script naming to avoid conflicts
npm install mcp-envOr use it directly with npx:
npx mcp-envThe tool automatically loads environment variables from .env.mcp file in your user directory. You can specify a custom environment file using the MCP_ENV_FILE environment variable:
MCP_ENV_FILE=.env.custom npx mcp-env VAR1=VALUE1 -- commandnpx mcp-env VAR1=VALUE1 VAR2=VALUE2 -- COMMAND_TO_RUNnpx mcp-env NODE_ENV=production API_KEY=your-api-key -- node app.jsnpx mcp-env PYTHONPATH=/usr/local/lib/python3.9 DATABASE_URL=postgresql://localhost:5432/mydb DEBUG=true -- python script.pynpx mcp-env AWS_REGION=us-west-2 AWS_PROFILE=production -- aws s3 lsnpx mcp-env DOCKER_IMAGE=myapp:latest PORT=3000 -- docker run -p $PORT:3000 $DOCKER_IMAGE- Parsing: The tool parses environment variables and the command from the command line arguments
- Script Generation: Creates a temporary script file with the environment variables and command
- Caching: Uses MD5 hash of variables and command to create unique script names
- Execution: Runs the generated script with the specified environment variables
The tool creates platform-specific scripts:
- Windows:
.batfiles usingsetcommands - Unix-like systems:
.shfiles usingexportcommands
Scripts are stored in the same directory as the executable and are reused for identical commands.
MIT License - see LICENSE file for details.