MCP secrets · Claude Code

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 value
    A key passed with claude mcp add --env is stored in the JSON file as written.
  • .mcp.json gets shared
    Project 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 server
    claude mcp add once, and Claude Code reads 30 platforms through MoltenRock Connect with no key passed.
  • Keychain for the rest
    For other servers, a wrapper reads the key from the macOS Keychain at launch.
  • Every request logged
    Connect records each call on your Mac; a kill switch refuses everything at once.
  • Changes wait for you
    On 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

OptionWhat’s in the config fileGood for
claude mcp add --env KEY=valueThe key itself, in ~/.claude.jsonA quick test, then remove it
${VAR} in .mcp.jsonA variable name; the key sits in your environmentShared project config
Keychain and a wrapper scriptA path to the wrapper; no secretAny MCP server you trust
MoltenRock ConnectOne entry, no key at allIts 30 business platforms

How it works

Clean up Claude Code’s MCP config

  1. 01
    Find the keys
    Look in ~/.claude.json (local and user scope) and any .mcp.json in your projects for env values and Authorization headers.
  2. 02
    Add Connect once
    In Terminal: claude mcp add --scope user moltenconnect -- '/Applications/MoltenConnect.app/Contents/MacOS/MoltenConnect' mcp. No --env needed.
  3. 03
    Keychain for the rest
    Store 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.
  4. 04
    Rotate what was in the file
    Any 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.