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
ðŸ“Ē āđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™: fatehmohamed/load mcp client secrets from env files km - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ“Ē āđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™: fatehmohamed/load mcp client secrets from env files km - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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"
    }
  }
}
ðŸ“Ē āđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™: fatehmohamed/load mcp client secrets from env files km - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ“Ē āđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™: fatehmohamed/load mcp client secrets from env files km - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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

Top comments (0)