How to keep API keys out of your MCP config
Some MCP servers need a key or token, such as a GitHub token or a Firecrawl API key. The quick way is to paste it into the config file. The problem is that the config file often lives inside your project, and projects get committed to git and shared. A key that lands in git history is a leaked key. This guide shows the safer way. Tested with Claude Code 2.1.278 in September 2026.
The idea: the config holds only the name of a variable. The real key lives in your computer's environment, which never gets committed. The config builder writes it this way for you.
Claude Code
Write the variable name as ${NAME}:
"firecrawl": {
"command": "npx",
"args": ["-y", "firecrawl-mcp"],
"env": {
"FIRECRAWL_API_KEY": "${FIRECRAWL_API_KEY}"
}
}
When Claude Code starts the server it replaces ${FIRECRAWL_API_KEY} with the real value from your environment. We checked this with a small test server that only starts when it receives the exact value: it connected when the variable was set correctly and failed to start when it was missing or wrong.
You can also give a fallback for when the variable isn't set, with ${NAME:-default}. Don't use a fallback for a real key.
If you forget to set it
Run claude mcp list. Claude Code prints a warning naming the missing variable:
[Warning] [firecrawl] mcpServers.firecrawl: Missing environment variables: FIRECRAWL_API_KEY
The variable has to exist in the terminal that you start claude from.
Cursor
Cursor uses a slightly different spelling, ${env:NAME}:
"env": {
"FIRECRAWL_API_KEY": "${env:FIRECRAWL_API_KEY}"
}
Cursor's documentation says this works in command, args, env, url and headers. Cursor needs to be launched with the variable already set, so set it before you open Cursor.
Claude Desktop
Claude Desktop doesn't offer this. Its config file holds the key as plain text:
"env": {
"FIRECRAWL_API_KEY": "paste-your-key-here"
}
So for Claude Desktop, treat claude_desktop_config.json as a private file. Don't commit it, don't paste it into chats or screenshots, and use a key that only has the permissions the server needs.
How to set the variable
Windows (PowerShell)
For the current terminal only. It works right away for anything you start from that window, and disappears when you close it:
$env:FIRECRAWL_API_KEY = "your-key-here"
To keep it permanently:
[Environment]::SetEnvironmentVariable("FIRECRAWL_API_KEY", "your-key-here", "User")
This is the part that trips people up: a permanent variable does not appear in terminals or apps that are already open, or in anything started from them. We tested this. Close everything and open a brand-new terminal window from the Start menu. If it still isn't there, sign out and back in.
macOS and Linux
For the current terminal:
export FIRECRAWL_API_KEY="your-key-here"
To keep it, add that same line to your shell's startup file (~/.zshrc on recent macOS, ~/.bashrc for bash on most Linux systems) and open a new terminal.
Other habits that help
- Don't put keys in
args. Command-line arguments can be visible to other programs on your computer. Theenvsection is the safer place. - Use the smallest permissions. A GitHub token that only reads one repository does far less damage if it leaks than one with full access.
- If a key was ever committed, rotate it. Deleting the file later doesn't remove it from git history. Make a new key at the provider and revoke the old one.