API keys out of Claude Code’s MCP config
claude mcp add --env KEY=value is quick, and it writes the value into a JSON file. Here’s how to stop doing that.
The short answer
Claude Code keeps local and user-scoped MCP servers in ~/.claude.json and project servers in .mcp.json, which teams often commit. A key passed with --env lands in that JSON as written. In .mcp.json, Claude Code expands ${VAR} and ${VAR:-default}, so the file can name a variable instead of holding the key. For business platforms, MoltenRock Connect goes further: one MCP server that holds the keys itself, so neither file, nor your shell, ever has one.
The problem
Where it goes wrong
- --env writes the valueA key passed with claude mcp add --env is stored in the JSON file as written.
- .mcp.json gets sharedProject servers live in .mcp.json, which is meant for version control.
- Env vars still live somewhere${VAR} keeps the key out of the file, but it has to sit in a shell profile or a .env file instead.
The solution
MoltenRock Connect: Keys that are never in a file
- One Connect serverclaude mcp add once, and Claude Code reads 30 platforms through MoltenRock Connect with no key passed.
- Keychain for the restFor other servers, a wrapper reads the key from the macOS Keychain at launch.
- Every request loggedConnect records each call on your Mac; a kill switch refuses everything at once.
- Changes wait for youOn Stripe, Cloudflare and GitHub, Claude Code can only propose; you approve with Touch ID.
Side by side
Where a Claude Code MCP key can live
| Option | What’s in the config file | Good for |
|---|---|---|
| claude mcp add --env KEY=value | The key itself, in ~/.claude.json | A quick test, then remove it |
| ${VAR} in .mcp.json | A variable name; the key sits in your environment | Shared project config |
| Keychain and a wrapper script | A path to the wrapper; no secret | Any MCP server you trust |
| MoltenRock Connect | One entry, no key at all | Its 30 business platforms |
How it works
Clean up Claude Code’s MCP config
- 01Find the keysLook in ~/.claude.json (local and user scope) and any .mcp.json in your projects for env values and Authorization headers.
- 02Add Connect onceIn Terminal: claude mcp add --scope user moltenconnect -- '/Applications/MoltenConnect.app/Contents/MacOS/MoltenConnect' mcp. No --env needed.
- 03Keychain for the restStore the key once with security add-generic-password -a "$USER" -s my-mcp-key -w (it asks for the value, so it never lands in your shell history), then point the server’s command at a two-line wrapper script that reads it with security find-generic-password -s my-mcp-key -w, exports it and starts the server. The config then holds a path, not a secret.
- 04Rotate what was in the fileAny key that sat in a config file may have been copied, synced or shared. Make a new one and revoke the old.
Straight answer
What this fixes, and what it doesn’t
Stays on your Mac
- Platform keys, in Connect or MoltenRock’s vault
- Keys for other servers, in the Keychain
- MCP config files with nothing secret in them
Leaves your Mac
- Connect’s calls from your Mac to each platform
- Tool results, to Claude Code and its model
- MoltenRock Connect covers its 30 business platforms (Stripe, Shopify, WooCommerce, GitHub, Cloudflare and more). An MCP server for anything else still needs its own key: keep that one in the Keychain.
Questions
What people ask first
Does Claude Code expand environment variables in MCP config?
In .mcp.json, yes: ${VAR} and ${VAR:-default}, in command, args, env, url and headers. The key then sits in your environment instead of the file.
Where does claude mcp add store servers?
Local and user scope in ~/.claude.json; project scope in .mcp.json at the project root.
Does Claude Code need a key to use MoltenRock Connect?
No. Connect runs on your Mac and holds the platform keys; Claude Code talks to it over MCP and gets answers.
What does it cost?
Connect is free for two platforms; one $9.99 unlock opens all 30, and MoltenRock Pro includes it.
No more --env for your business tools.
MoltenRock Connect is free for Mac.