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.…