Why are static API keys in MCP configs a risk?
Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team
The short answer
A static API key in an MCP config is a long-lived credential sitting in a plain-text file that gets copied into dotfiles repos, support screenshots, agent transcripts and backups. Anyone — or any server process — that can read the file holds the access the key grants, with no expiry and usually no scoping. TrustGate's scan flags static keys by name only (values are never displayed or stored) so you can find and replace them with scoped, revocable credentials before the file travels further than you intended.
What is a static API key (in a config)?
A static API key is a long-lived, bearer-style credential embedded directly in configuration — whoever presents the key is trusted, for as long as the key exists. In MCP setups they typically appear as environment values in the client config that launches a server: a database token, a SaaS API key, a cloud credential pasted in during setup “to make it work” and never revisited. “Static” is the problem in one word: unlike a session token it does not expire, unlike a scoped grant it usually carries broad permissions, and unlike a secret-manager reference it replicates silently with every copy of the file.
Config files travel — further than you think
An MCP config is not a vault; it is a working file. It gets pasted into issue reports when a server will not start, committed to a dotfiles repository, screenshotted into a tutorial, captured in an agent's context when the agent is asked to debug its own setup, and synced to every laptop and backup the user touches. Each copy is faithful, including the credentials. The original sin is rarely malice — it is that setup day rewards whatever works fastest, and a pasted key works instantly.
Now add the MCP-specific twist: the config also launches processes. A server started from that config runs with the environment the config defines, which means a server you connected for a narrow job may be able to read credentials meant for a different server entirely, if they share the file or the inherited environment. The blast-radius question from our audit guide — “if this server misbehaved, what could it touch?” — very often answers itself in the env block.
Standing access is the real cost
A leaked password can be rotated in an afternoon; a leaked static key is usually discovered in an incident review, months after the file travelled. Until then the key grants quiet, legitimate-looking access — API calls that authenticate perfectly, from anywhere, indistinguishable from yours without careful log work. Keys also tend to be over-scoped: created in a hurry from an admin console, they often carry full account rights when the server needed read access to one project.
Expiry is the other missing property. People leave teams; servers get uninstalled; the key in the config outlives both relationships. Auditors ask “which credentials exist, where do they live, when did anyone last rotate them?” and static keys in configs fail all three questions simultaneously. That is why TrustGate treats their mere presence as a finding worth surfacing, separate from any judgement about the server itself.
Why TrustGate flags names, never values
The scan's design rule is strict: static keys are flagged by name only, and credential values in configs are never displayed or stored. This is not squeamishness; it is the scanner refusing to become the leak it reports. A report that printed your keys would itself need vault handling, would end up in the same screenshots and tickets, and would teach users to avoid scanning — the worst possible outcome. The name (“a key with this label sits in this config”) carries everything an owner needs to act.
It also models the right relationship with secrets generally: detection systems should traffic in the existence and location of credentials, not in the credentials. When you remediate, you will handle the value exactly once — in the provider's console, while rotating it — and nowhere else in the toolchain.
What to use instead
The replacement pattern has three properties: scoped, revocable, and referenced rather than embedded. Scoped means the credential grants the narrow job — read-only, one project, one dataset — so a leak is a puddle, not a flood. Revocable means you can kill it in the provider's console without breaking unrelated work, which is what makes rotation a ten-minute task instead of a migration. Referenced means the config points at a secret store or an environment injected at launch, so the file itself can travel without carrying the crown jewels.
Per-server credentials deserve emphasis: one key shared by four servers cannot be revoked for one misbehaving server, and its usage logs cannot tell you which server made a call. Issuing each server its own scoped key costs minutes at setup and buys attribution forever — when a key shows up somewhere it should not, you know exactly which relationship to suspend.
Remediation order when the scan flags you
Do not start by deleting the key from the file — if the file already travelled, deletion changes nothing about the copies. Start by rotating: issue the replacement credential in the provider's console, scoped to the actual job, deploy it through your secret reference, verify the server works, then revoke the old key so every stray copy becomes inert. Only then clean the file, and note the date and the key's name (not its value) in the change record.
Then go one step upstream: ask why a long-lived key was the path of least resistance. Usually the answer is setup friction — the provider's scoped-token flow was buried, or the tutorial modelled the bad pattern. Fix the on-ramp for the next server (a team setup note, a template config with secret references) or the same finding returns wearing a different server's name.
Static keys and the rest of the TrustGate picture
Key hygiene composes with everything else in this guide series. A baseline records that a config was key-flagged at approval time (or clean — also worth recording); a re-scan shows when a new static key appears in a changed config, which is a classic “quick fix” regression during incident response; and a least-privilege review asks whether the server needed a credential at all. The toxic-flow lens adds the sharpest version: credential access sitting beside a general network tool is a chain, and the static key is what makes that chain loaded.
None of this requires heroics. It requires the scan to name the finding, the owner to rotate before deleting, and the team to make scoped references the default template. Keys will keep appearing in configs wherever setup is hurried — which is exactly why the check belongs in the automated scan rather than in a policy PDF.
The 5-action checklist
- Run the free scan and list every static key it flags, by name, across all your MCP configs.
- For each key: issue a scoped, per-server replacement, deploy it by reference, verify, then revoke the old key.
- Check where the config file has travelled (repos, tickets, screenshots) and assume those copies were live until revocation.
- Split shared keys into per-server credentials so usage is attributable and revocation is surgical.
- Update your setup template so the next server starts with secret references, not pasted values.
Worked example: a mail key, a dotfiles repo, one rotation done right
A fictional developer, Tomas, connected a mail MCP server during a hack week, pasting his provider's master API key into the client config to skip the scoped-token flow. Months later a routine TrustGate scan flagged the finding in plain words: a static key whose name indicated the mail provider, present in a config that also existed — he then remembered — in his public dotfiles repository, forked twice.
Tomas did the steps in the right order: created a scoped key (send-only, one domain), deployed it via an environment reference, confirmed the server worked, and revoked the master key, which made the public copy worthless. He also checked the provider's logs for the key's usage and found only his own traffic. The whole remediation took an evening; the lesson he wrote into his team's setup template took one line — “keys are referenced, never pasted” — and the next scan's clean config section is what that line looks like when it works.
Frequently asked questions
Is it ever acceptable to keep a key in a config?
For a throwaway local experiment with a worthless, instantly revocable test key — arguably. For anything touching real data, accounts or money, no: the file will travel and the key will outlive the experiment. The scoped-reference pattern is barely slower and removes the entire class of accident, which is why it should be the default rather than the aspiration.
Does TrustGate store or transmit my key values?
No. Credential values in configs are never displayed or stored; the scan flags static keys by name only, and scanned configs are never executed. The report tells you a key exists and what it is called — everything you need to rotate it in the provider's own console.
I found the same key in three configs. One rotation or three?
One key, one rotation — revoke it once and every copy dies together. Then issue separate scoped keys per server as replacements. The shared key was the underlying problem: it could not be revoked for one server, and its logs could not attribute calls. Splitting is the fix, not three copies of a new shared key.
How do static keys interact with the toxic-flow graph?
A config carrying credentials raises the stakes of neighbouring capabilities: credential presence beside a general network or send tool completes a chain an injector can exploit. The scan surfaces both views — the key finding itself and the combination picture — because remediation differs: rotate the key, and break or scope the chain.
What about keys for the MCP server's own service?
Same rules. A key that authenticates the server to its vendor's API is still a standing credential in a travelling file. Scope it to the server's function if the vendor allows, reference it rather than embedding it, and include it in the same rotation rhythm as every other credential in the setup.
Keep exploring
Start with the free TrustGate scan of your own MCP setup, compare Free vs Pro vs Team, try the live rug-pull demo and the MCP change impact simulator, or browse the full guides index.
- How do you audit an MCP server before connecting it?
- How do credentials get exposed through MCP configurations?
- What are toxic capability combinations in an MCP setup?
- How do least-privilege policies work for AI agents?
- What is a pinned baseline for an MCP server?
- What are command and permission risks in MCP servers?