Where MCP API keys end up today
Most MCP servers that wrap an API need that API’s key. The quickest setup, and the one most READMEs show, is to paste it into the client’s config. Here is what that looks like in the four clients people use most.
Cursor, in ~/.cursor/mcp.json or .cursor/mcp.json in a project:
{
"mcpServers": {
"stripe": {
"command": "npx",
"args": ["-y", "some-stripe-mcp"],
"env": { "STRIPE_SECRET_KEY": "sk_live_..." }
}
}
}
Claude Desktop, in claude_desktop_config.json (on macOS under ~/Library/Application Support/Claude/): the same mcpServers shape, the same env block, the key as written.
Claude Code, from the terminal:
claude mcp add --transport stdio github \
--env GITHUB_TOKEN=ghp_... -- npx -y some-github-mcp
That command stores the server, key included, in ~/.claude.json. Add --scope project and it goes into .mcp.json at the project root, a file meant to be committed.
VS Code, in .vscode/mcp.json, often with a remote server and a header:
{
"servers": {
"crm": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": { "Authorization": "Bearer eyJhbGciOi..." }
}
}
}
All four work. All four leave a long-lived secret in a text file.
Why that is a problem
- Plaintext on disk. Any process running as you can read these files, and so can anything that backs up or indexes your home directory.
- Synced and committed configs. Dotfile repos, cloud-synced home folders and a project
.mcp.jsonor.vscode/mcp.jsonthat was committed “just for a moment”. Secret scanners catch some of these after the fact, once the key is already out. - Prompt injection. Coding agents read files and run commands. A crafted README, issue or web page can ask the agent to print a config file or an environment variable. If the key is on the machine, the agent can be talked into reading it.
- The server process holds it too. A local MCP server is often an
npxpackage you did not review. It runs with the key in its environment and can send it anywhere. - Copied configs. The working
mcp.jsongets pasted into Slack, a wiki page or a teammate’s laptop, key and all. - Offboarding. When someone leaves, you have to know every key that was ever on their machine and rotate each one. Nobody has that list.
The root issue is not the file format. It is that the AI client holds the API’s credential at all.
Better: reference secrets, don’t paste them
Every major client now has a way to keep the literal key out of the config file. Use it. These are the documented options as of September 2026.
Claude Code
.mcp.json expands environment variables in command, args, env, url and headers, with ${VAR} and ${VAR:-default}:
{
"mcpServers": {
"crm": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": { "Authorization": "Bearer ${CRM_TOKEN}" }
}
}
}
For tokens that should never sit in your shell profile either, headersHelper runs a command at connection time that prints the headers as JSON. That command can read from your OS keychain or a secrets manager. See the Claude Code MCP docs.
Cursor
mcp.json supports ${env:NAME} in command, args, env, url and headers, and local stdio servers can load an envFile:
{
"mcpServers": {
"crm": {
"url": "https://mcp.example.com/mcp",
"headers": { "Authorization": "Bearer ${env:CRM_TOKEN}" }
}
}
}
See Cursor’s MCP docs.
VS Code
mcp.json has inputs. A promptString with "password": true asks for the value the first time the server starts, and VS Code stores it securely for later runs:
{
"inputs": [
{ "type": "promptString", "id": "crm-token", "description": "CRM API token", "password": true }
],
"servers": {
"crm": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": { "Authorization": "Bearer ${input:crm-token}" }
}
}
}
See the VS Code MCP configuration reference.
Claude Desktop
The plain claude_desktop_config.json keeps env values as written. Desktop extensions (.mcpb bundles) are the better route: fields an extension marks as sensitive, such as an API key, are stored in the OS keychain, according to Anthropic.
What this does and does not fix
References keep keys out of files you might commit or paste. That is worth doing today. But the key still reaches your machine, the MCP server process still holds it, an agent with shell access can still read an environment variable, and offboarding still means rotating every key on every laptop.
Better still: remote MCP servers with OAuth
A remote MCP server that supports MCP authorization replaces the pasted key with a browser sign-in. The client stores an OAuth token issued for that MCP server, not the API’s master key. Claude Code, for example, keeps these tokens in the macOS keychain. Tokens can be scoped, refreshed and revoked.
The catch is coverage. Only some vendors run a remote MCP server with OAuth. Many APIs you rely on, including your own internal ones, still only issue API keys or bearer tokens. And each vendor’s server is still one more sign-in, in every client, with its own rules and its own log, if it has one.
Best: a gateway with a vault
The strongest setup is one where the AI client never holds an API credential at all. An MCP gateway does this by splitting the job into two keys:
- Key A is the client’s sign-in to the gateway, over MCP OAuth. It is checked at the edge and stripped there.
- Key B is each API’s own credential. It lives encrypted in the gateway’s vault and is added at the last hop, for one call, to one host.
The two never meet. The client config holds a URL. A prompt injection cannot exfiltrate a key the agent never had.
The Apitell way
With Apitell, every client gets the same config, and nothing in it is secret:
{ "mcpServers": { "apitell": { "url": "https://mcp.apitell.com/mcp" } } }
In Claude Code it is one command:
claude mcp add --transport http apitell https://mcp.apitell.com/mcp
Here is what changes:
- Connect each API once, in the console. Paste an API key, bearer token or basic auth credential, or sign in with the provider’s OAuth. Keys are encrypted per tenant and bound to one connector and one host. OAuth tokens renew themselves.
- Sign in from each client. Cursor, VS Code, Claude Code, Claude and ChatGPT run the standard MCP OAuth sign-in. You pick which connectors the client may reach and whether it may make changes.
- The model sees names, not keys.
ai_discoveranswersstripe · connected. No tool or API ever returns a credential, and none is ever logged. - Offboarding is one click. Disconnect a client or remove a member and the next call is refused. There is nothing to rotate on their laptop, because nothing was ever there.
Writes are off by default and can require approval. Every call lands in Activity as one line: who, which client, which API, which operation, status, time. Never the payload.
A cleanup checklist
If you already have keys in MCP configs, do this once:
- Search for them:
~/.cursor/mcp.json,.cursor/mcp.json,~/.claude.json,.mcp.json,.vscode/mcp.json,claude_desktop_config.json. Look forenvandheadersvalues that are not references. - Check git history and dotfile repos for the same files.
- Rotate every key you find. Assume it has been copied.
- Replace each entry with a reference (short term) or with a single gateway URL (long term).
- Add the config file names to your secret scanner’s path list.
Try it
Create a free workspace, connect one API, and replace its mcp.json entry with the Apitell URL. Then see how the vault keeps key B away from the model, follow the setup for Cursor or Claude Code, or read what an MCP gateway is.