MCP Secrets AI Agents

Stop Passing the Same .env File to Every Agent

By Sean · July 10, 2026 · 9 min read

MCP makes Claude, Codex, Cursor, and internal agents much more useful. It also exposes an old shortcut a lot of us have used: put the useful credentials in one .env file and pass it around. That works until someone asks who had access to what, especially if an ISO 27001 audit is in the room and AI agents have been touching client credentials.

I had a call with an agency operator who was already using AI agents for real client work.

Reports. Scripts. SOPs. Campaign checks. Small bits of automation.

Useful work, not a lab demo.

The awkward bit was not the AI tooling. That part was working. The awkward bit was access.

The practical path had become: put the API keys and client credentials into a shared .env file, then let the people and agents that need work done use it.

AI provider keys. Client ad tokens. Search Console OAuth. Webhook secrets. GitHub tokens. SOP repo access.

One file. Lots of power.

# One file passed around to humans and AI tools
OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_ADS_CLIENT_A=...
GOOGLE_ADS_CLIENT_B=...
META_ADS_CLIENT_A=...
SHOPIFY_CLIENT_C=...
GITHUB_SOP_REPO_TOKEN=...
AGENCY_OPS_WEBHOOK_SECRET=...

I understand why this happens. I have done it myself. Someone needs a report fixed. Someone needs a campaign checked. Someone asks Claude to debug an automation. Copying the .env file is the fastest way to get moving.

But once you hand someone the file, they have access to everything inside it. A contractor who only needs Client A reporting can also see Client B. The SEO specialist who only needs Search Console can also see Meta Ads tokens. The AI agent helping with SOPs can read operational webhooks it should never touch.

MCP changes the shape of the problem

The Model Context Protocol is an open standard for connecting AI tools to the systems where data and tools live. The MCP specification also describes tools as the operations an MCP server exposes for a model to invoke.

That is useful. It means the agent does not need a custom plugin for every internal system. It can ask an MCP server for the tools it supports and call them in a structured way.

But if the MCP server is sitting on top of real credentials, the security question becomes very direct:

When the model asks for a secret, what decides whether it is allowed?

It cannot just be the prompt. A prompt can say "only use Client A", but a malicious document, ticket, webpage, or copied log line can still tell the agent to ignore that and fetch everything. The model can ask. Something outside the model needs to decide.

The MCP documentation treats authorization as the control that protects sensitive resources and operations exposed by MCP servers. That is the right framing. If an MCP server can reach real business credentials, it needs named identities, permissions, expiry, and audit. Otherwise the .env file just moved behind a nicer interface.

The CertLocker pattern

The pattern I would use for that agency is straightforward.

First, take the shared .env file and split it into individual secrets in CertLocker. Do not treat the file as one blob. Each credential gets its own name, owner, description, and group.

shared-marketing-stack
  agency-openai-api-key
  agency-anthropic-api-key

client-a
  client-a-google-ads-api
  client-a-meta-ads-token
  client-a-search-console-oauth

client-b
  client-b-google-ads-api
  client-b-meta-ads-token
  client-b-linkedin-ads-oauth

agency-ops
  agency-ops-webhook-signing-secret

Then create groups that match how work actually happens: shared marketing stack, Client A, Client B, Client C, SEO, SOP library, agency ops.

The group model matters because it lets you say: this agent can ask for Client A and shared stack secrets, but not Client B or ops.

Next, register each AI agent as a first-class identity. Not "Claude". Not "the contractor's laptop". A named agent with a purpose:

  • SA Contractor Codex, read-only access to Client A and shared marketing stack secrets
  • SEO Specialist Codex, read-only access to SEO and shared stack secrets
  • Account Manager Codex, Client A and Client B reporting access
  • Agency Root Codex, owner-level demo access, used carefully and reviewed often
CertLocker AI Agents page showing registered agents with status, risk level, and group scope

Open full size screenshot

The important change is identity. Each AI agent becomes a named asset with status, risk, and group scope instead of an anonymous process holding the whole .env file.

Finally, issue an MCP token for each agent. The token is linked to one agent and carries the group access that defines what the agent can reach. That token goes into Claude Desktop, Claude Code, Cursor, Codex, Gemini CLI, Windsurf, OpenHands, or your own internal agent runner. Copy-paste configs for Claude, Codex, and Gemini live in the MCP setup guide.

{
  "mcpServers": {
    "certlocker": {
      "url": "https://trust.certlocker.io/rest/mcp",
      "headers": {
        "Authorization": "Bearer "
      }
    }
  }
}

The agent no longer gets the raw .env file. It gets a narrow way to ask CertLocker for the few values it is allowed to use.

CertLocker Create AI agent modal showing explicit MCP scopes such as secret read, certificate read, host read, probe read, approval request, and audit write

Open full size screenshot

Scopes should be boring and explicit. A reporting agent probably needs secret read. It does not need certificate requests, SSH sessions, or broad admin rights.

What changes day to day

This is not just cleaner architecture. The day-to-day behavior changes.

A contractor can still ask an AI agent to run a report, repair a script, or check why an automation failed. But when the agent needs a credential, it calls CertLocker through MCP. CertLocker checks the token, the agent, the scope, the group, and the secret.

If the request fits, it returns the value.

If it does not fit, it denies the request and logs the attempt.

Request:
  get_secret("client-b-meta-ads-token")

Agent:
  sa-contractor-codex

Token groups:
  agency-demo, client-a

Result:
  denied

Reason:
  secret is outside the agent's group scope

That denied request matters. With a shared .env file, there is no denied request. The agent either has the value or it does not. If it has the file, it has the lot.

With scoped MCP tokens, you get a different operating model:

  • Client A access does not imply Client B access
  • SEO access does not imply ad spend access
  • contractor access can expire automatically
  • one agent can be suspended without rotating every secret
  • the audit log shows which agent asked for what
  • denied requests become visible instead of hidden inside chat history
CertLocker MCP token creation step showing group access and an agent linked to the token

Open full size screenshot

The token is where the real access boundary starts to become operational: one token, one agent, explicit group access.

Why not just make more .env files?

You can split the big file manually. One .env.client-a, one .env.client-b, one .env.seo, and so on. That is better than one giant file, but it still leaves the hard parts unsolved.

Files get copied. People keep old versions. Agents print values into logs. Contractors leave. Someone rotates a token and forgets which copy was updated. Nobody can prove which agent read which credential last Tuesday.

A secret manager does not magically remove all risk. But it gives you controls a file does not have:

  • Central rotation, change the value once, not in every copied file
  • Version history, see what changed and restore when a bad rotation breaks work
  • Scoped tokens, separate Client A, Client B, SEO, ops, and owner-level access
  • Session visibility, see which agent connected and when
  • Revocation, kill one agent token instead of asking everyone to delete a file
CertLocker MCP token created modal showing the MCP endpoint, masked token ID, and masked client configuration

Open full size screenshot

The MCP configuration is still easy to paste into an agent client, but the bearer token is shown once and can be revoked from CertLocker later.

The access model I would start with

For an agency, MSP, dev shop, or distributed ops team, I would start conservative:

  1. Import every key from the shared .env file as a separate CertLocker secret.
  2. Group secrets by client, function, and operational sensitivity.
  3. Create one agent identity per real job role or automation runner.
  4. Issue short-lived MCP tokens where possible, especially for contractors and experiments.
  5. Give agents read-only secret access first. Add broader scopes only when the workflow proves it needs them.
  6. Review denied requests. They tell you where the access model is too tight, or where an agent tried something it should not.

That last point is useful. Denials are not always attacks. Sometimes they show you that the grouping is wrong. Maybe the SEO agent really does need the Search Console credential for Client A. Fine. Add that one group. Do not hand it the full file.

What this means for audits and client trust

Agencies and contractors often get asked a simple question in a hard form: who can access my account credentials?

If the real answer is "everyone with the latest .env file", that is awkward. It might be normal, but it is hard to defend.

The better answer is:

  • each client secret is stored as a named asset
  • each AI agent is a named identity
  • each token is scoped to specific groups
  • access can expire
  • access can be revoked
  • allowed and denied requests are logged
CertLocker AI agent detail drawer showing scoped permissions, group access, recent sessions, and suspend and revoke buttons

Open full size screenshot

When a client asks who had access, you should not be searching Slack, laptops, and old zip files. The agent should have sessions, status, and revocation controls.

The point is not to slow agents down

The point is the opposite. AI agents become more useful when they can safely touch real systems. If every agent is blocked from useful credentials, people work around the controls. If every agent gets a full .env file, the control does not exist.

The practical middle ground is scoped access through MCP:

The agent does not own the secret. The agent owns a narrow, revocable right to ask for the secret.

That is the model CertLocker is built around. Secrets, groups, tokens, agents, sessions, audit events. The old operational problems are still there, but now they are things you can manage instead of a file you hope nobody forwards.

If your team is already using Claude, Codex, Cursor, or internal agents with shared .env files, this is the workflow I would test first.

Upload the secrets. Split the groups. Create the agents. Give each one an MCP token. Then watch what they actually ask for.

You will learn very quickly which access is real, which access was accidental, and which secrets should never have been in that shared file in the first place.

Try it without giving an agent the whole .env file

Register an agent, import a few demo secrets, issue a scoped MCP token, and see exactly what that agent can and cannot ask for.

Get started

MCP access evaluation

Try the workflow without handing an agent the whole .env file

Import a few demo secrets, group them by client or function, issue a scoped MCP token, and watch what the agent is allowed and denied.