How to keep secrets out of your MCP config files
By the AgentKey team - November 14, 2026 - 6 min read
Many MCP servers need credentials to do their job: API keys, tokens, sometimes database passwords. Setup docs commonly walk you through the same pattern: paste the key into a JSON config file, restart the client, move on.
Depending on the client, that file is usually called something like mcp.json or claude_desktop_config.json, and it sits on your machine in plaintext. This post is about why that is worth fixing, and what "fixed" can look like.
Where the secrets actually go
A typical MCP config entry looks something like this (fictional example):
{
"mcpServers": {
"acme-crm": {
"command": "acme-mcp-server",
"args": ["--region", "us"],
"env": {
"ACME_API_KEY": "acme_live_your_real_key_here"
}
}
}
}Convenient. It also means real secrets, in plaintext, in a predictable file with a predictable name. That file can leak in boring ways:
- It gets committed to git. Dotfiles repos often include MCP configs, and a token in git history stays there even after you delete the line.
- It gets synced. Backup and file-sync tools can copy it to other machines and the cloud.
- It shows up in screenshots, screen shares, and bug reports, because that is where your config lives.
- Any program with permission to read the file can access its contents.
- It gets shared. A teammate copies your working setup, and now your token is on their machine too.
A key sitting in a local config file is not automatically compromised. The risk is how easily these files travel further than you intended.
What "better" looks like
However you solve it, the checklist is the same:
- Nothing secret in the file. The config can hold a reference to a secret. It should not hold the secret itself.
- Scoped access. Each server and each agent gets the minimum it needs. A read-only token where read-only will do.
- Short-lived where possible. A token that expires limits the damage when one leaks.
- An audit trail. You should be able to answer "what used this secret, and when?" without guessing.
- Fast revocation. Killing access should take seconds, not an afternoon of hunting down every copy.
Practical options and their trade-offs
Environment variables instead of literals. Some MCP clients can expand environment variables into a server config or pass them to the servers they launch, but only where the client explicitly supports it. It is not a universal JSON feature, and an env file only works when something loads it. Where it works, the config references the variable instead of containing the key. Caveat: the secret is still plaintext somewhere on your machine. This mainly protects against accidental commits and screenshots, not against anything that can read your environment.
Keep configs out of git. If you track dotfiles, exclude the MCP config or use a template with placeholders. Check your history for anything already committed.
A secrets manager or OS keychain. Tools in this category (from developer options like Infisical to infrastructure staples like HashiCorp Vault and AWS Secrets Manager) store secrets outside your files and hand them out at runtime. More setup, much better hygiene. The WorkOS guide linked below compares several.
Scoped, short-lived tokens. Where the service allows it, issue tokens with the smallest permissions and shortest lifetimes that work, so a leaked token does less damage for less time.
An agent vault. A newer category built for exactly this situation: the config holds a connection to the vault rather than a credential, the agent requests access when it needs it, and a person approves each grant. The design goals are scoped access, an activity record, and revocation that does not depend on finding every copy of a file.
Where AgentKey fits
AgentKey is our take on the agent-vault approach: a password vault built for AI agents. Agents you add can request a login, you approve or deny each request, you choose the roles and sites each agent may use, and you can revoke an agent's access at any time. Our privacy policy describes exactly what is recorded and how agent sign-ins work.
Where things stand today: the AgentKey web app is live, the MCP endpoint is live and listed in the MCP Registry, and connections are approved by you in the browser. The homepage at agentkey.waiwiser.com keeps a current list of which connections and clients we have tested so far.
Five things to do today, vault or no vault
- Find your MCP configs (
mcp.json,claude_desktop_config.json, your client's equivalent) and see what is actually in them. - Rotate any secret that was committed to git, synced somewhere you did not intend, or shared with someone. Treat those as seen.
- Move the rest out of the files: environment variables at a minimum, a secrets manager or vault if you can.
- Scope tokens down to what each server actually needs.
- Delete config entries and tokens you no longer use.
Further reading
Try AgentKey
One vault for your agents. Scoped access, approved by you.
agentkey.waiwiser.com - Your agents. Your rules.