# API keys in mcp.json: are your MCP config files leaking secrets to git?

Canonical: https://caelo.sh/guides/api-keys-in-mcp-json
Published: 2026-11-27 · Updated: 2026-11-27 · Arthi Arumugam, Caelo by Irth Labs

**Short answer:** If an API key sits in plain text in `.cursor/mcp.json`, `.mcp.json`, `.vscode/mcp.json` or `.devin/mcp_config.json` and that file was ever committed, treat the key as leaked: rotate it at the provider first, then replace the value with an environment variable reference. These files live inside your project, so git commits them like any other file. `claude_desktop_config.json` lives in your user folder instead, so it only leaks when you copy it into a repository, a dotfiles backup or a support thread.

## Where do MCP config files live?

| Client | File | Inside your repo? | How to keep keys out |
| --- | --- | --- | --- |
| Cursor | `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global) | The project file is. | `${env:NAME}` in `command`, `args`, `env`, `url` and `headers`. |
| Claude Code | `.mcp.json` at the project root (project scope). Local and user scopes are stored in `~/.claude.json`. | Yes. Claude Code's docs say to check `.mcp.json` into version control. | `${VAR}` or `${VAR:-default}` in `command`, `args`, `env`, `url` and `headers`. |
| VS Code with GitHub Copilot | Workspace-root `.mcp.json`. Older `.vscode/mcp.json` files use the deprecated editor format. | Yes. | `${NAME}` references. VS Code's docs say not to commit tokens, passwords or populated authentication headers. |
| Devin Desktop (formerly Windsurf) | `.devin/mcp_config.json` (shared), `.devin/mcp_config.local.json` (gitignored), `~/.config/devin/mcp_config.json` (user) | The shared file is. | The gitignored `.local` file. `${env:VAR}` and `${file:/path}` are documented for OAuth client fields only. |
| Claude Desktop | macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`. Windows: `%APPDATA%\Claude\claude_desktop_config.json`. Linux: `~/.config/Claude/claude_desktop_config.json`. | No, it is in your user folder. | Do not copy it into a repository while its env block holds keys. |

## Check your repo in five minutes

1. List the MCP files git tracks: `git ls-files | grep -iE "mcp(_config)?(\.local)?\.json|claude_desktop_config"`
2. Open each one and read the `env` and `headers` blocks. A value such as `"ghp_..."`, `"sk-..."` or `"Bearer abc123"` is a real key. A value such as `"${env:GITHUB_TOKEN}"` or `"${GITHUB_TOKEN}"` is a reference and is fine.
3. Search history, not just today's file. A key you deleted last week is still in git: `git log -p --all -- .cursor/mcp.json .mcp.json .vscode/mcp.json .devin/mcp_config.json .devin/config.json | grep -nE "sk-|ghp_|xox|AKIA|Bearer"`
4. Run a secret scanner. `gitleaks git -v .` scans every commit. Caelo (`npx caelo .`) scans the files on disk, including dot-folders such as `.cursor` and `.vscode`, for the provider key formats on its list, but it does not read git history, so use both.
5. On GitHub, open the repository's Security tab (GitHub's docs now call it Security and quality). Secret scanning runs automatically for free on public repositories and covers the entire Git history on all branches. Push protection for users is on by default and stops you pushing supported secrets to public repositories.

## If a key was committed

1. Rotate first. Revoke the key at the provider and issue a new one. Deleting the line or rewriting history does not un-leak a key that someone already copied. GitHub's docs say to rotate the affected credential immediately when secret scanning alerts.
2. Replace the literal with a reference. In Cursor, for example: `"env": { "GITHUB_TOKEN": "${env:GITHUB_TOKEN}" }`, with `GITHUB_TOKEN` set in your shell profile or system environment.
3. Keep personal credentials out of shared files. Claude Code's local scope, stored in `~/.claude.json`, is meant for servers with credentials you do not want in version control. In Devin Desktop, put personal keys in `.devin/mcp_config.local.json`.
4. Give each MCP server a restricted key with only the permissions it needs, as Cursor's MCP docs recommend. Then clean the old key out of git history if you want to, using our guide on leaked keys.

## What do the tools protect, and what is still your job?

| Area | The tools do this | Still your job |
| --- | --- | --- |
| References | Cursor, Claude Code and VS Code expand environment variable references in MCP config. Devin Desktop documents a gitignored `.local` file instead. | Use them for every key. A literal key in the file is committed like any other text. |
| Approval | Claude Code asks you to approve project servers from `.mcp.json`. Cursor and Devin Desktop ask before MCP tool calls by default. | Only approve servers you trust and have read. |
| GitHub | Free secret scanning on public repositories, and push protection for users on by default. | Private repositories are scanned only when they belong to an organization on GitHub Team or Enterprise with Secret Protection enabled. Private repositories on a personal account are not covered. Rotate on every alert. |
| Key permissions | Not handled by the MCP client. | Give each server the narrowest key the provider offers. |

## Check your own app

1. Run the free local check: `npx caelo .` Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and `.env` files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.
2. Follow the fix in the report and rerun Caelo. For an untracked, unignored file containing secrets, preview the US$19 quick fix. https://caelo.sh/fix
3. For an engineer's assessment, book the US$490 App Health Check. Irth Labs delivers a report and fixed repair quote, with credit toward the repair. https://www.irthlabs.com/start?service=app-health-check

## Questions

### Is it safe to commit .cursor/mcp.json or .mcp.json?

Yes, if every key is an environment variable reference. Claude Code's docs recommend checking `.mcp.json` into version control so the team shares the same servers; the key values should come from each person's environment.

### I deleted the key from mcp.json. Am I safe?

No. The key is still in git history and in every clone or fork. Rotate it at the provider, then clean the history if you want to.

### Does Caelo check MCP config files?

For the files on disk, yes. Caelo reads every text file in the folder you point it at, including `.cursor/mcp.json` and `.vscode/mcp.json`, and flags keys that match its provider formats (Stripe, OpenAI, Anthropic, AWS, GitHub, SendGrid, Google, Slack and private keys) with the value redacted. It runs locally, uploads nothing and does not read git history. It also does not look outside the folder you give it, so it will not see `claude_desktop_config.json` in your user folder.

### Where is claude_desktop_config.json?

On macOS at `~/Library/Application Support/Claude/claude_desktop_config.json`, on Windows at `%APPDATA%\Claude\claude_desktop_config.json`, and on Linux at `~/.config/Claude/claude_desktop_config.json`.

## Sources

- [Model Context Protocol docs: Connect to local MCP servers (Claude Desktop config).](https://modelcontextprotocol.io/docs/develop/connect-local-servers)
- [Cursor docs: Model Context Protocol (mcp.json and config interpolation).](https://cursor.com/docs/mcp)
- [Claude Code docs: Connect Claude Code to tools via MCP (scopes and .mcp.json).](https://code.claude.com/docs/en/mcp)
- [VS Code docs: MCP configuration reference.](https://code.visualstudio.com/docs/agents/reference/mcp-configuration)
- [Devin docs: MCP configuration and managing secrets.](https://docs.devin.ai/cli/extensibility/mcp/configuration)
- [GitHub docs: Secret scanning.](https://docs.github.com/en/code-security/concepts/secret-security/secret-scanning)
- [GitHub docs: Push protection.](https://docs.github.com/en/code-security/concepts/secret-security/push-protection)
- [Gitleaks on GitHub.](https://github.com/gitleaks/gitleaks)
- [Caelo source: file scanner and secret patterns.](https://github.com/arthi-arumugam-git/caelo/blob/master/lib/rules.js)

## Related guides

- [Is there a security scanner MCP server for Cursor or Claude Code?](https://caelo.sh/guides/security-scanner-mcp-server-cursor-claude-code)
- [I leaked an API key or the Supabase service_role key. What do I do now?](https://caelo.sh/guides/leaked-api-key-what-to-do)
- [Is my Cursor app secure? What Cursor protects and what it does not](https://caelo.sh/guides/is-my-cursor-app-secure)
- [Is my Windsurf app secure? Checks for apps built in Windsurf (now Devin Desktop)](https://caelo.sh/guides/is-my-windsurf-app-secure)
- [Got a GitHub secret scanning alert? What to do next](https://caelo.sh/guides/github-secret-scanning-alert-what-to-do)
