Menu

Where to Store MCP Server API Keys in Claude Code Without Committing Them
📰

Where to Store MCP Server API Keys in Claude Code Without Committing Them

DEV Community: devsecops·Serge Zhuravel·10 days ago
#fDhrNDXW
#devtodevsecops#devto#dev#claude#server
Long article (2404 words) — no AI summary yet.
Reading 0:00
15s threshold

Short answer: do not put the key itself in .mcp.json . If the server supports OAuth, sign in with /mcp and the file holds only a URL. Otherwise commit a .mcp.json that contains ${VAR} references, and supply the values through your environment or a secret manager. The commands claude mcp add --env , --header and add-json write whatever you type to disk, and claude mcp get prints it back, so a literal key passed to them is a literal key in a file.

This guide is based on the Claude Code documentation, opened on October 22, 2026, and on a test of version 2.1.307 on Linux that used claude mcp commands with fake keys. No model session was run, because the CLI was not logged in; servers were exercised through the health check that claude mcp list runs, so everything below is about configuration and what the CLI writes or prints. Observed results come from one run each and may differ on your version.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.