Sponsored by Deepsite.site

envmcp

Created By
griffithsbs8 months ago
A lightweight way to use environment variables in your Cursor MCP server definitions.
Content

envmcp

npm version total downloads

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",
    ]
  }
}

What does it do?

Receives a shell command as input, loads environment variables from an env file, and then executes the command

What's the point?

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",
    ]
  }
}

Installation

npm install -g envmcp

Usage

envmcp [--env-file <path>] <command> [args...]

The tool will:

  1. Look for a .env.mcp file in the current directory
  2. If not found, it will search up the directory tree for a .env.mcp file
  3. As a last resort, it will check for ~/.env.mcp
  4. If --env-file or -e is specified, it will use that file instead of searching
  5. Load the environment variables from the found .env.mcp file
  6. Execute the specified command with any provided arguments

Options

  • --env-file <path> or -e <path>: Specify a custom path to the environment file

Environment File Format

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.

Contributing

Contributions are welcome: please feel free to open issues or PRs!

Development

Prerequisites

  • Node.js 14 or later
  • npm

Setup

# Install dependencies
npm install

# Build the package
npm run build

Publishing

# Log in to npm
npm login

# Publish the package
npm publish

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
CursorThe AI Code Editor
ChatWiseThe second fastest AI chatbot™
DeepChatYour AI Partner on Desktop
Amap Maps高德地图官方 MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Tavily Mcp
WindsurfThe new purpose-built IDE to harness magic
Playwright McpPlaywright MCP server