MCP security: secure configuration, identity and gateway authorization

How to run the Model Context Protocol safely in production: an MCP gateway, authorization and scoping, and non-human identity controls that keep agent tooling under control.

Definition

The Model Context Protocol (MCP) is an open standard that connects AI agents to external tools and data through a uniform interface. Its rapid 2025 adoption created an identity problem: agents act as machine identities that need scoped, revocable authorization rather than long-lived shared keys.

When the Model Context Protocol took off in 2025, it solved a real problem: every agent needed a different adapter for every tool, and MCP gave them one interface. But a uniform door to your systems is also a uniform door for attackers. The hard part of MCP is not the protocol — it is identity.

Why does MCP create an identity problem?

An agent connected through MCP acts on your systems. To do that it authenticates — with an API key, a token, a certificate. That makes the agent a non-human identity (NHI), and most organizations have no real management for these. They were built to govern people: joiners, movers, leavers. An agent is none of those, yet it can read a database or send an email.

The result is what practitioners call an identity crisis: thousands of machine credentials, often long-lived, broadly scoped and owned by no one. When an agent is compromised through prompt injection, those credentials are the blast radius.

Where MCP risk concentrates (illustrative)
32%26%20%14%8%
  • Long-lived / over-scoped credentials32%
  • Missing runtime authorization26%
  • Unowned / stale machine identities20%
  • Over-trusted tool descriptions14%
  • No audit trail per identity8%
Directional weighting of common MCP/identity weaknesses observed in 2025 security guidance. Not a formal survey. · opsagent synthesis of OWASP MCP guidance and NHI research

Authentication is not authorization

A common mistake is to stop at authentication: the agent proves who it is, and then it can do anything that identity can do. That is far too coarse for autonomous systems.

The control that matters is runtime authorization — deciding, at the moment of each action, whether this identity should perform this action right now, given context. A read token should never silently become a write. A tool that summarizes invoices should not be able to issue payments.

Aspect Authentication Authorization
Question it answers Who is this identity? May it do this action, now, in this context?
When it runs Once, at connection At every sensitive action
If you stop here The identity can do anything its role allows Each action is checked against policy
MCP example The agent presents a token The gateway approves a read, denies a payment

A practical control stack

  1. Inventory. List every MCP server and the credentials it holds. Unowned identities are the first thing to fix.
  2. Least privilege per tool. Scope each credential to the minimum. Prefer short-lived, automatically rotated tokens over static keys.
  3. Runtime authorization. Put a policy decision in front of sensitive actions — an MCP gateway or authorization layer, not trust-by-default.
  4. Per-identity audit. Log which identity did what, with signed, tamper-evident records. An action you cannot attribute is an action you cannot govern.
  5. Zero-trust between agents. In multi-agent systems, one agent must not treat another’s request as automatically safe.

The 30/90/180 view

In the first 30 days, inventory and kill the worst long-lived keys. By 90 days, scope tools to least privilege and add a gateway for sensitive actions. By 180 days, every machine identity has an owner, a lifecycle and an audit trail.

Identity is where agent security and governance meet. Get the vocabulary straight in the glossary, then start with the one thing that always pays off: list what you have.

Frequently asked questions

Is MCP itself insecure?

The protocol is not the core problem; the risk comes from how teams wire it up. MCP standardises how an agent reaches tools and data, which is exactly why weaknesses around it scale: broad tokens, long-lived keys and tools that run with more access than the task needs are suddenly reachable through one uniform interface. In other words, MCP does not create new categories of vulnerability so much as it makes existing authorization and identity mistakes easy to commit everywhere at once. That also points to the fix. You do not make MCP safe by abandoning the standard — you make it safe with disciplined authorization: scoped, short-lived credentials, a policy decision in front of sensitive actions, and an owner and audit trail for every machine identity. Treat the protocol as plumbing and put your security effort into who is allowed to do what through it.

What is a non-human identity?

A non-human identity (NHI) is the digital identity of a machine actor — an agent, a service or a workload — rather than a person. Where a human logs in with a username and password, an agent authenticates with an API key, a token or a certificate, and that credential is its identity on your systems. The reason this matters is that most identity governance was built for people, around the joiner-mover-leaver lifecycle, and agents fit none of those stages while still being able to read databases or send mail. Treating NHIs as first-class identities — each with a named owner, a defined scope, a rotation schedule and an audit trail — is the heart of agent access control. Organisations that skip this end up with thousands of credentials that nobody owns and nobody can confidently revoke, which is precisely the blast radius an attacker inherits.

What should we do first?

Start with an inventory, because you cannot govern identities you have never listed. Enumerate every MCP server, every agent, and the credentials each one holds, then flag the ones that are long-lived, broadly scoped or owned by no one — those are your immediate risk. From that list, the first concrete moves are to kill or rotate the worst static keys, scope each remaining credential to least privilege, and put a runtime authorization check in front of genuinely sensitive actions. This sequence matters: discovery first, because most organisations underestimate how many machine identities they already have, and containment second, because a scoped credential limits the damage of every future compromise. Inventory is unglamorous, but it is the control that makes all the others possible, and it almost always surfaces a few forgotten keys that should have been revoked months ago.

Why are long-lived API keys so risky for agents?

A long-lived API key is a standing, often broadly scoped credential that does not expire on its own, and for agents that combination is the single most common weakness. The problem is duration multiplied by reach: the key works indefinitely, so a copy leaked in a log, through a prompt injection or via a compromised dependency stays valid long after the incident, and it usually carries far more access than any one task needs. Because the same key is frequently shared across tools, a single leak compromises everything it touches at once. The fix is to replace static keys with short-lived, automatically rotated tokens scoped to a specific identity and action, so that even a stolen credential expires quickly and reaches little. Pair that with per-identity audit logging, so a leaked token can be traced and revoked rather than quietly used for weeks. Short and narrow beats long and broad every time.