AdYour product here, seen by people installing AI tools every day Sponsor slots open: 12 of 12, from $249 a month

How to give an MCP server an API key safely

Local MCP servers read keys from environment variables, set in the env block of your config or with -e in Claude Code. Remote servers use a header or an OAuth sign-in. Use the smallest scope the key allows, and never commit a config with real keys.

Local servers

"my-server": {
  "command": "npx",
  "args": ["-y", "package-name"],
  "env": { "API_KEY": "your-key" }
}

Use the exact variable name from the README. On this site, a server's page lists the settings its publisher declared in the official MCP Registry, and marks which are required and which are secret.

Remote servers

Prefer OAuth sign-in when it is offered. Otherwise pass the key as a header, for example Authorization: Bearer your-key.

Keep keys safe

  • Create a key just for the AI tool, with read-only access if that is enough.
  • Do not put real keys in project files you commit, like .mcp.json or .cursor/mcp.json.
  • Remove keys you no longer use, and rotate any key you pasted somewhere public.