MCP Security Best Practices: 6 Controls for Agents in 2026
Practical MCP security best practices for OAuth, least privilege, audit trails and supply chain risk, with steps for servers and clients.

An agent connected to your issue tracker picks up a public bug report and reads it. Buried in the reproduction steps is a line telling it to export the private backlog. The agent holds a write token minted under a senior engineer's name, so the export goes through. Your logs show a tool call and a timestamp. Nothing in them says which person was involved, or whether that person ever approved a read of private tickets.
That's the shape of most MCP incidents. The protocol carries the request correctly. The failure is delegation without a chain of custody: the client never proved who it was, the server never checked what it was allowed to do, and the record never connected the action back to a human.
Every practice below is a link in that chain. Client authentication establishes who is asking. Scopes and approval gates bound what the asking may do. Audit trails and supply chain controls keep the record honest afterwards. Skip one link and routine work still functions, but the gap is exactly where an injected instruction becomes a data loss incident with no name attached.
1. Authenticate every MCP client with OAuth 2.1 and PKCE
Authentication is the first link in the chain of custody. The client has to prove which person it acts for, or later records have nothing to attach the action to.
Shared static API keys still show up in early MCP deployments. They identify a deployment, not a person, so a tool call cannot be tied back to whoever delegated it. Use OAuth 2.1, with PKCE required for all clients in the 28 July 2026 authorization specification. PKCE binds the authorization code to the client session that started the flow. A code taken from a redirect cannot be exchanged by an attacker.
Bind the token to one server
That specification pairs PKCE with secure local token storage, correct expiry handling, and refresh token protection and rotation. It also requires the server to validate that a token was issued for the intended MCP server before processing a request. Protected Resource Metadata tells the client which authorization server to use. A resource parameter on the authorization request binds the resulting token to one server's canonical URI.
I treat that binding as a hard gate. A token minted for a read-only reporting server must fail against the writer, and a token minted for staging must fail against production.
A worked example: a developer connects a CLI agent to a hosted board. The browser opens, they approve as themselves, and the token that comes back is scoped to their identity, not a shared key. That proof is what lets every later log line name a person.
Practical rule: reject authorization requests with no code challenge, and refuse to start a flow when the authorization server doesn't advertise S256.
- Keep access tokens short-lived: a short lifetime cuts the window a stolen token is useful.
- Rotate refresh tokens: rotate on each use and revoke the whole family when one is replayed.
- Reserve API keys for scripts and CI: store the key as a secret and send it as a Bearer token for a script, CI job, or cloud agent. Scope it to one project and keep it off interactive sessions that belong to a named person.
2. Apply least privilege to every tool and token scope
Least privilege on MCP isn't a token setting. It's a decision about what an agent may attempt, made per tool and per scope. Split capabilities by verb rather than by object: read tasks, claim tasks, write knowledge, approve decisions, administer members. Each tool declares the one scope it needs, and the server refuses calls the token doesn't cover.
The failure mode is validating once at connection. Servers should reject tokens with the wrong audience or issuer, check signature, expiry and scopes on every request, and log authorization failures with agent, person, project and resource identifiers (MCP authorization security considerations). Trusting the session after a successful handshake is how a downgraded or substituted token slips through.

Propose, don't decide
An agent should never hold more authority than the person it acts for, and often less. A pattern that works: member agents propose decisions and tasks, a person accepts them. Destructive operations (deleting a project, exporting the full backlog, changing permissions) sit behind scopes no default agent is granted.
- Start read-only: add write scopes when a specific workflow needs them, not in anticipation.
- Document each tool's scope: deny by default and treat the mapping as part of the tool manifest you review.
- Revisit grants on role changes: a person who moves teams shouldn't leave a token carrying their old access.
- Keep administrative tools off the default list: an agent that can't see a tool can't be talked into calling it.
That last one is the most underrated control on this list. Prompt injection only works on tools the model can reach.
3. Never pass through client tokens to upstream services
An MCP server that wraps a CRM, an issue tracker or a repository API gets tempted to forward the client's access token straight to the upstream service. Don't. The MCP specification forbids token passthrough, and the reason is concrete: a token minted for your server has the wrong audience upstream, so either the call fails or the upstream accepts a credential it should never have seen. Either way, the audit trail now points at the wrong party.
The temptation exists because upstream credentials are often already sitting in the server's config. Astrix Security's 2025 analysis of more than 5,200 open-source MCP server implementations found that 88% required credentials and 53% relied on long-lived static secrets such as API keys or personal access tokens, while only 8.5% used OAuth (Astrix Security on MCP server security). Static secrets held server-side are how a single compromised server becomes a breach across every connected system.
Exchange, or vault and issue
The correct pattern is a separate hop with its own credential. Where the upstream supports token exchange, request a downstream token that carries the user's context while keeping your server's identity distinct. Where it only offers API keys, hold them in a managed secrets vault and issue a short-lived, per-call credential to the client side of the request.
- Reject unknown audiences: a token that doesn't name your server gets a 401, not a best effort.
- Log both identities: the client that called you, and the upstream action you took on its behalf.
- Write the rejection test: one integration test with a deliberately mismatched audience catches regressions before a release does.
The same rule applies to every hop. A server that enforces PKCE on the first call and drops it on the upstream request has secured the front door and propped open the back.
4. Treat tool descriptions and returned content as untrusted input
Every string an agent reads can carry an instruction: task text, comments, file contents, web pages, and the tool descriptions themselves. When that instruction sits in metadata, the payload reaches the model before any tool executes.
A benchmark evaluating 20 LLM agents against tool-poisoning attacks reported many agents with attack-success rates above 60%, and the highest observed rate at 72%, which makes tool discovery itself an exploit path (tool poisoning benchmark on arXiv).

Break the dangerous trio
Untrusted input, private data, and an outbound action in the same session turn a poisoned description into exfiltration. Split that trio. An agent that reads public issue text gets a read-only token and no network egress tool.
The client still has to prove which person it acts for. The server still checks the call against that scope. Returned content stays in the record as data, not as a new grant.
Tool output is data. Treat a description that says "always call this before other tools" the same way you'd treat that sentence in a marketing email.
- Validate arguments against a schema: reject extra fields rather than passing them through.
- Label returned content: wrap tool output so the model can distinguish data from instructions.
- Pin descriptions: hash them at approval and alert on any change.
Schema checks reject fields the delegation never included. Labels stop a poisoned result from reading as an order. A hash shows when the description the person accepted has changed. I keep those three together: nothing the model reads should rewrite who acted, or what that actor was allowed to do.
5. Require human approval for sensitive or irreversible actions
An agent finishes a spec and wants to move the epic to Done. That change is reversible and cheap, so it should not wait. The same agent then wants to archive the quarter's tasks and email the client. That write leaves the workspace. Stop it.
Approval is the link where the server holds a delegated act until a person confirms it. The client has already proved who it is, and the token already limits which tools it may call. Neither check decides whether this particular change should run. Deleting data, changing permissions, sending messages outside the workspace, deploying code, or accepting a decision: pause and show the person the target and the exact change. An approval screen that asks "Allow agent to proceed?" trains people to click yes. Show the diff, the payload, and the number of records affected.
A valid delegated token can still authorize excessive writes, or let a hijacked session act unnoticed. The NSA CSI on MCP security frames the missing pieces as approval gates on irreversible actions, short-lived credentials, revocation when a session ends, and a record connecting the human, the agent, the tool and the object changed.

Gate the exceptions, not the routine
- Irreversible writes: deletes, bulk exports, permission changes.
- Anything external: email, public comments, third-party API calls.
- Decisions that become policy: a draft is not a decision until a person accepts it.
Deny on timeout. If nobody answers within an hour, the action does not happen. That hold slows the agent. It is cheaper than an irreversible write you cannot roll back.
In Projectify, decision records let an agent propose a decision while a person accepts it. The human in the loop playbook covers keeping approval prompts from turning into rubber stamps.
6. Keep full audit trails with attribution for every agent action
A log that records a tool call without a person is half a record. Write the authenticated client identity, the acting human, the tool name, the arguments with secrets redacted, the result status and a timestamp. OWASP's AI agent and MCP security guidance ties logging the human principal, agent identity, tool invoked, arguments' security-relevant metadata, result and timestamp directly to detecting tool poisoning, unauthorized changes and abnormal behaviour (OWASP DevSecOps guideline).
The second value is incident response. When an agent starts reading twenty times its usual volume at 2am, an alert on that pattern does more than any post-mortem review.

Separate the two identities
Record the person and the client as distinct fields. One person may run three agents, and one agent may serve several people across a day. Collapsing them into a single "actor" string makes both analyses impossible.
- Redact before writing: tokens, passwords and personal data never reach the log store.
- Set retention to match obligations: a compliance window, not forever.
- Alert on shape, not just volume: bursts of reads outside working hours, a new tool appearing under one agent, unusual export calls.
Projectify's activity feed shows every change with the person and the agent behind it, which is the minimum bar for a shared board. The audit trail software guide goes further on what to capture and how long to keep it.
7. Vet, pin, and monitor MCP servers in the supply chain
A third-party MCP server is a dependency running with your privileges. A 2025 study of 1,899 open-source MCP servers found that 7.2% contained at least one general security vulnerability, while 5.5% exhibited MCP-specific tool poisoning (study of MCP server vulnerabilities on arXiv). Those are not edge cases you can filter out by picking popular packages. They're a base rate.
Then there's the rug pull. A benchmark found that more than 85% of tested attacks compromised at least one MCP platform, including name squatting, data exfiltration and sandbox escape (ACM study of attacks on MCP systems). Trust is a moving dependency when schemas, descriptions and packages change after approval.
Pin and hash, then keep watching
Approve a version, hash the tool definitions, and alert when anything changes. A metadata edit that adds a parameter or rewrites a description is a security event until a person confirms otherwise.
- Allowlist servers: only reviewed ones reach developers, and review means reading the source or the vendor's provenance.
- Pin exact versions: read the changelog before bumping, and re-approve behaviour changes.
- Sandbox local servers: containers with no host filesystem and restricted egress, because a stdio server runs with your privileges.
- Retire what you don't use: an unmaintained server is a standing credential with nobody maintaining it.
Teams that run only internally built or vendor-hosted servers with pinned versions spend far less time on this than teams that let anyone add a package from a public directory. The Model Context Protocol overview is a reasonable starting point for teams still inventorying which servers they run.
8. Secure transport and block DNS rebinding on local MCP servers
Remote MCP traffic goes over TLS. That part is uncontroversial. The part teams miss is local: an HTTP MCP server bound to 0.0.0.0 with no Origin check is reachable from any page a developer visits. DNS rebinding turns a malicious website into a client of that server. The attacker's domain resolves to 127.0.0.1, the request arrives, and the local server answers because it never asked who sent it.
The specification's transport guidance asks local servers to bind to localhost where appropriate, validate the Origin header, and return clear errors for origins that aren't allowed. Add authentication even on localhost. A token check costs one header and removes the browser as an attack path entirely.
Test the block, don't assume it
Stand up a page on a different origin that fetches your local MCP endpoint, and confirm the request is rejected. Many discover their server answers.
- Bind to 127.0.0.1: never 0.0.0.0 as a default, and make a wider bind an explicit, logged decision.
- Allowlist origins: reject missing or unknown Origin headers on HTTP transports rather than falling back to permissive.
- Terminate TLS at the edge: forward only authenticated requests, and don't let the proxy strip the Authorization header.
- Require auth for stdio too: a config file pointing at an unknown package is remote code execution with extra steps.
Transport rule: if a local server can be reached by a browser tab you didn't open, it isn't local any more.
How the eight MCP security practices compare
A delegated act needs a chain of custody. The client proves who it is. The server checks what that identity may do. The record names the person and the agent. Each row is one link. Break a link and you cannot say who acted, or what they were allowed to do. I treat a missing link as a failed control, not a gap to fill later.
| Item | Main risk reduced | Best for | First step |
|---|---|---|---|
| Authenticate every MCP client with OAuth 2.1 and PKCE | Unattributed actions and shared-secret exposure | Teams connecting AI clients to shared project boards or internal systems | Require PKCE and verify each token's audience |
| Apply least privilege to every tool and token scope | Excessive access and agent misuse | Teams giving agents write access to work trackers, repositories, or client systems | Start with read-only scopes and add access only as needed |
| Never pass through client tokens to upstream services | Confused deputy attacks and cross-service token misuse | Teams hosting MCP servers that connect to external APIs | Reject tokens whose audience does not identify your server |
| Treat tool descriptions and returned content as untrusted input | Prompt injection, data exfiltration, and unauthorized actions | Agents that read tickets, documents, or web pages | Validate tool arguments against strict schemas |
| Require human approval for sensitive or irreversible actions | Harmful changes made without meaningful oversight | Teams whose agents propose changes to production systems, client boards, or shared policy | Show the exact change and require approval for sensitive actions |
| Keep full audit trails with attribution for every agent action | Untraceable changes and weak incident investigation | Engineering leaders and regulated organizations needing accountability | Log the acting person, client, tool, and outcome separately |
| Vet, pin, and monitor MCP servers in the supply chain | Malicious servers, rug pulls, and silent permission changes | Security teams and developers installing community MCP servers | Pin exact versions and review changes before upgrading |
| Secure transport and block DNS rebinding on local MCP servers | Token interception and cross-site attacks on local servers | Developers running local MCP servers and teams hosting remote endpoints | Bind local servers to localhost and validate request origins |
Turning Six Practices Into a Working Baseline
A new MCP tool lands in a pull request on a Tuesday. The client can prove which person started the session, the server can refuse a scope that person never held, and the log can name both of them after the call. If any of those three links is missing, the action has no chain of custody. Put that chain in place before the first real user, not after the first bad write.
Start with the two controls that stop the most damage. OAuth with PKCE ties every action to a named person. An approval gate stops an irreversible call from running on the model's judgement alone. Both are cheap before you have users. Retrofitting them later means re-consenting everyone and rewriting tool schemas that assumed broad access.
Then work outward. Add the audit trail next, because it is the only way to see whether the other controls are holding. After that, reject token passthrough, keep a vetted server allowlist, and check Origin on anything bound to localhost. That order puts behaviour-changing controls first and leaves drift detection for later.
The artifact teams skip is the authorization matrix. One page: person, agent, tool, scope, and whether approval is required. Store it in the repository. Update it in the same pull request that adds a tool, while the reviewer can still see why that scope exists. Each row is one link in custody: who the client is, what the server will allow, and what the record must show.
Expect friction, and tune it on purpose.
- Short-lived tokens raise refresh traffic and re-consent. Measure that cost before you shorten lifetimes again.
- Approval gates slow routine work when they cover too much. If reviewers never reject a request, the gate is on the wrong action.
- Allowlists block a developer who found a useful server. Give them a short path to submit it for review instead of a hard wall.
A defensible baseline for a team in 2026 stays small: OAuth 2.1 with PKCE, exact redirect URI matching, audience validation, per-tool scopes, no token passthrough, an approval gate on irreversible actions, and a log that names the person and the agent. The rest of this list hardens those seven.
Review the set whenever a tool, a person, or a server version changes. MCP security is ongoing maintenance, and the chain of custody is only as strong as the last link someone checked.
Projectify is a board where people and agents share the same work. Claude Code connects with one command, or through a connector the user approves in the browser, and each session acts for a named person. Agents claim a task so two sessions do not overwrite each other, and the activity feed attributes every change. Visit Projectify to connect the first agent and see that chain of custody on the board.