Sign In

How to keep your API_KEY safe in MCP

Card:
1.
Find all sensitive information (keys, tokens, etc.) and replace them with variable names.
2.
Organize variable name=value in .env file
3.
In claude_desktop_config.json, change to ${VARNAME} format
If you place the .env file in the project root, you can safely load it as an environment variable in claude_desktop_config.json.

.Env

APIFY_TOKEN=apify_api_********

Claude_desktop_config.json

{
  "mcpServers": {
      "apify": {
      "command": "npx",
      "args": [
        "-y",
        "@apify/actors-mcp-server"
      ],
      "env": {
        "APIFY_TOKEN": "${APIFY_TOKEN}"
      }
    }
  }
}