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-env
Or use it directly with npx:
npx mcp-env
npx mcp-env VAR1=VALUE1 VAR2=VALUE2 -- COMMAND_TO_RUN
npx mcp-env NODE_ENV=production API_KEY=your-api-key -- node app.js
npx mcp-env PYTHONPATH=/usr/local/lib/python3.9 DATABASE_URL=postgresql://localhost:5432/mydb DEBUG=true -- python script.py
npx mcp-env AWS_REGION=us-west-2 AWS_PROFILE=production -- aws s3 ls
npx mcp-env DOCKER_IMAGE=myapp:latest PORT=3000 -- docker run -p $PORT:3000 $DOCKER_IMAGE
The 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 -- command
- 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:
.bat
files usingset
commands - Unix-like systems:
.sh
files usingexport
commands
Scripts are stored in the same directory as the executable and are reused for identical commands.
- Node.js >= 16.0.0
- Cross-platform support (Windows, macOS, Linux)
npm run build
This project uses Vitest for testing.
# Run all tests
npm run test:run
# Run tests in watch mode
npm run test
# Run tests with UI
npm run test:ui
See test/README.md for detailed testing information.
- Runtime:
dotenv
for environment file loading - Development: TypeScript,
@types/node
,tsx
,vitest
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Created by unadlib
https://github.com/mcpland/mcp-env
MIT License - see LICENSE file for details.