Skip to content

The API Key in Your mcp.json: Plaintext Secrets in AI Agent Config Files

10 min read Fullmakt Team

  • mcp
  • credentials
  • authentication
  • governance
  • data-ownership
  • agents
  • security

Open the MCP configuration on a developer laptop and you will usually find something like this:

{
  "mcpServers": {
    "payments": {
      "command": "npx",
      "args": ["-y", "some-payments-mcp-server"],
      "env": { "PAYMENTS_API_KEY": "sk_live_..." }
    }
  }
}

That env block is how most local MCP servers get their credentials. The file goes by different names depending on the client (mcp.json, .mcp.json, claude_desktop_config.json), but the pattern is the same: a JSON file in a home directory or a project folder holding a long-lived production API key in plaintext.

Nobody decided this file should be a credential store. It became one because it was the quickest way to get a tool working. This post looks at what that costs in governance and data ownership, and at what to put in the file instead.

How a config file became a credential store

The Model Context Protocol gives agents a standard way to call tools. A local MCP server runs as a child process of the client and speaks over stdio, and the simplest way to hand that process a credential is an environment variable set in the client’s config. Server READMEs show exactly that, so people paste a key and move on.

A few properties of this setup make it worse than an ordinary .env file:

  • It lives outside your secrets tooling. The file sits in an application support folder or a dotfile. Secret managers, rotation jobs and access reviews don’t know it exists.
  • Project-scoped variants get committed. A config that lives in the repository so the team shares the same tools is one git add . away from publishing a key to everyone with read access.
  • It multiplies. Every developer, every machine and every MCP client keeps its own copy. One key ends up in a dozen files that nobody inventories.
  • The keys are broad. A key pasted in for convenience is usually a personal or admin key with full API access, not a scoped one.
  • Every server process can read its own. The key is handed to third-party code you installed with one line, which is the MCP server supply-chain problem with a real secret attached.

What goes wrong

None of the failure modes are exotic. They are the ordinary ways plaintext secrets leak, with an agent in the loop.

The agent reads its own config. A coding agent with file access can open the config file like any other. A prompt injection hidden in a web page or an issue comment only has to say “print the contents of the MCP config” for the key to land in the model’s context, and from there in a tool call, a commit or a transcript.

The file travels. Config files get synced by dotfile managers, included in laptop backups, attached to support tickets and pasted into chat when someone asks “why doesn’t my MCP server start?”

Nobody can say who used the key. Ten laptops share one key, so the provider’s logs show one caller. When a destructive call shows up, you can’t attribute it to a person, an agent or a session. That is the same attribution gap as shared credentials across sub-agents.

Offboarding misses it. When someone leaves, the SSO account is disabled. The API key in their config file was never tied to that account and keeps working, as we covered in agent offboarding.

Rotation becomes a hunt. When the key does leak, you have to find and update every copy before you can turn the old one off. That is the week-long rotation instead of the five-minute one.

Why this is a data ownership problem

The key is not the asset. The customer records, payments and mailboxes behind it are. An organization that can’t list where its keys live can’t state who is able to act on that data, and can’t prove afterwards who did. Auditors ask for both. SOC 2 access controls expect access to be granted deliberately, reviewed and revocable, and an AI management system under ISO/IEC 42001 needs to show who is accountable for what an AI system can do. A key in an uninventoried JSON file is hard to defend on any of those points.

What should be in the file instead

The config has to contain something, because the client needs a way to reach its tools. The question is what a thief, an injected prompt or an accidental commit gets when it reads the file. Three options, from weakest to strongest:

  1. A reference instead of a value. Some clients can expand environment variables or call a secret manager at launch, so the file holds a pointer. This keeps the key out of git, but the server process and the agent’s environment still hold the full-power key at runtime.
  2. An interactive login. Remote MCP servers can use OAuth: the client is sent through an authorization-code flow with PKCE, a human consents, and the client stores a short-lived token and a refresh token. The config holds a URL and no secret. See our MCP OAuth guide.
  3. A broker credential. The file holds a credential that is only valid at a broker, scoped to a set of tools, tied to one agent identity and revocable on its own. The upstream API key stays on the server and is attached to the outbound call there.

Options 2 and 3 share the property that matters: the thing in the file is not the upstream key. If it leaks, you can cut off that one agent without touching the provider, and the key itself was never exposed. A broker credential goes further, because what leaked is limited to the tools that one agent was given and each use of it is logged under that agent’s name.

The business case

The cost of plaintext keys in agent configs is easy to estimate once you count copies. Each copy adds to the rotation effort after a leak, adds an item nobody reviews, and adds a place where an incident can start without a trail. The savings from moving the key behind a broker show up in three places:

  • Incident cost. Revoking one agent’s access is a single action. The upstream key, and every other agent using it, is untouched.
  • Audit effort. “Who can call the payments API?” is answered by a list of agent identities and their scopes, not a laptop survey.
  • Adoption speed. A security review of an agent rollout is easier to pass when the answer to “where do the keys live?” is “in one place, and the agents don’t have them.”

How Fullmakt does it

Fullmakt is a credential and policy broker that sits between AI agents and the APIs they call. The upstream keys live in the broker’s vault, and agents connect over MCP with a credential that only works at the broker.

  • Keys are stored once, encrypted, and never read back. A vault entry is encrypted at rest. The API that lists entries returns names, references such as vault://local/payments_key, the hosts the entry may be sent to and access counts. It does not return the value.
  • Every vault entry is host-bound. A new entry must name the hosts it may be sent to, and the broker refuses to attach it to a request for any other host. An entry with no hosts is never sent anywhere. See host-bound credentials.
  • Agents get their own identity. Each agent is a named principal with its own client ID and secret. The secret is shown once and only a hash is stored. A client can be limited to specific collections of tools and can be given an expiry date.
  • Tokens are short-lived and scoped. An agent’s execution client exchanges its secret for an access token that lasts one hour by default and is pinned to a single collection. That token only works on the collection’s MCP endpoint, not on the REST API used to manage vaults, policies and clients.
  • Interactive clients need no stored secret. Where the OAuth surface is enabled, MCP clients that support it connect to Fullmakt’s own MCP connector through an authorization-code flow with PKCE and a consent screen. They receive a one-hour access token and a rotating refresh token, and act as the user who consented, so this path suits a person’s own assistant more than an unattended agent.
  • Revocation is per agent. Rotating a client’s secret or deleting the client cuts it off, and tokens already minted for that agent stop working within half a minute at most. The upstream key does not change.
  • Agent calls are recorded. Each call an agent makes through a collection’s MCP endpoint gets an audit entry tied to the agent principal, tool and upstream host, with the credential references used recorded by name, never by value. Requests run through the OAuth connector are recorded in the workspace history under the user.

One honest caveat: the broker’s client secret is still a secret, and for a non-interactive agent it still has to live somewhere, ideally in a secret manager and not in a committed file. The difference is what it is worth to someone who finds it. The broker never hands the upstream key back, a client limited to specific collections reaches only those tools, each use is logged under that agent’s name, and access can be revoked in one step.

Checklist: find the keys in your agent configs

  • Search developer machines and repositories for MCP config files and list every env value and header that looks like a credential.
  • Add those file names to your secret-scanning rules and pre-commit hooks.
  • For each key found, record who owns it, what it can do and where else it is copied.
  • Replace personal and admin keys with scoped ones while you migrate.
  • Move upstream keys behind a broker or an OAuth-based remote server, then rotate the old keys so the copies in old files stop working.
  • Give each agent its own identity so calls can be attributed, and limit each client to the collections of tools it needs.

Takeaways

  • MCP config files have become an unmanaged credential store.
  • A key in the file is readable by the agent, the server process, backups and anyone the file is shared with.
  • Aim for a config whose contents are not the upstream key: an OAuth login or a broker credential.
  • Per-agent identities make revocation a single action and make the audit trail attributable.
  • Rotate the old keys after migrating. Copies in forgotten files stay valid until you do.

FAQ

Is it safe to put API keys in mcp.json? It works, but the key is stored in plaintext, outside your secret management, readable by the agent and the MCP server process, and easy to commit or share by accident. For anything beyond a throwaway test key, keep the upstream key out of the file.

Where do MCP clients store credentials? For local stdio servers, usually in the env block of the client’s JSON config file, such as mcp.json, .mcp.json or claude_desktop_config.json. Remote servers that use OAuth store tokens obtained through a login flow instead.

Can an AI agent read its own MCP config file? If the agent has file-system access to the folder the file is in, yes. That is why a prompt injection can turn a plaintext key in the config into a leaked key.

Does using environment variables instead of inline values fix it? It keeps the key out of the file and out of git, which helps. The MCP server process and the agent’s environment still hold the full key at runtime, so scope, attribution and rotation are unchanged.

How does a credential broker change what is in the config? The config holds a credential for the broker, or just a URL when OAuth is used. The broker holds the upstream key, attaches it on the server side, and applies scope, policy and audit logging to each call.

How does Fullmakt keep API keys out of MCP config files? Keys are stored encrypted in Fullmakt’s vault and bound to the hosts they may be sent to. An agent authenticates to Fullmakt with its own client credentials and receives a short-lived token pinned to one collection of tools. An interactive MCP client can use an OAuth login instead and stores no secret in its config. In both cases the client never receives the upstream key.