DEV Community

Cover image for Load MCP client secrets from env files
Fateh Mohamed 🐒
Fateh Mohamed 🐒

Posted on

Load MCP client secrets from env files

When a team collaborates on the same project, it would be better that they share the same settings, copilot instructions, and, of course, MCP configurations.

To use MCP inside your workspace, you need to create an MCP.json file under .vscode

vscode mcp config file

If you want to push the MCP.json file to share servers with other collaborators, you have to care about sensitive secrets like elasticUrl, elasticApiKey

The ugly solution is to push the file and let team members set the secret values, but what if a member push that file by mistake with real secrets? 🚨

mcp.json config

Here is a safe and clean way using envmcp package that lets you use environment variables in your VSCODE MCP client in 2 steps:

  1. Create an .env.mcp file that contains the env vars needed by the MCP server in order to run. Example for @octodet/elasticsearch-mcp:
# .env.mcp file πŸ’‘ πŸ‘
ES_URL=https://esUrl.com
ES_API_KEY=mYaPiKeY==
ES_VERSION=8
Enter fullscreen mode Exit fullscreen mode

Don't forget to add .env.mcp to .gitignore

And change the MCP.json config to

{
  "servers": {
    "elasticsearch": {
      "command": "npx",
      "args": ["envmcp", "npx", "-y", "@octodet/elasticsearch-mcp@1.0.7"],
      "type": "stdio"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Required env vars for the MCP will be picked automatically from the .env.mcp file. Start your server and enjoy!

Top comments (0)