MCP Server Security Best Practices for Production Hardening
A concrete MCP server security checklist: kill token passthrough, pin tool manifests and stop prompt injection with scoped OAuth 2.1, agent-scoped identities, egress allowlists and audit logs you can ship this sprint.

Shishir Sharma
Engineering & Architecture

Table of Contents
MCP Server Security Best Practices for the 2026-07-28 spec
If your MCP server security best practices still target the 2025-06-18 spec, you are patching the wrong protocol shape. The 2026-07-28 revision removes client sessions, deprecates OAuth Dynamic Client Registration, introduces Client ID Metadata Documents, and names newer failure paths such as mix-up attacks, SSRF in OAuth metadata discovery, and state handle hijacking. According to Practical DevSecOps, 'MCP Security Best Practices: What Actually Works in 2026', Knostic researchers scanned nearly 2,000 publicly accessible MCP servers and found every verified instance exposed internal tool listings with no authentication.
Treat that scan as the start of your MCP threat model. Many servers still expose tools before identity, scope, consent, and logging are settled. An unauthenticated tool list is a map for later tool poisoning.
MCP Server Security Best Practices: nine attacks, one control each
How do you secure an MCP server?
When asking how to secure an MCP server, bind every tool call to an audience-checked token, a per-agent identity, a pinned tool manifest, and an output boundary. Use this AI agent security checklist before adding transport or UI changes.
Attack
Control
File to edit
Token passthrough
Audience-bound token
auth middleware
Confused deputy MCP
Per-client consent
consent store
SSRF in metadata discovery
Block private ranges
network policy
State handle hijacking MCP
Bind state to user
state store
MCP tool poisoning
Hash signed manifests
lockfile
MCP rug pull
Diff descriptions
CI gate
MCP prompt injection
Filter output as data
sanitizer
Shared service account
Per-agent identity
identity policy
Scope inflation
Exact scopes
scopes config
A real-world example: an internal CI MCP server exposes deploy_service. If a gateway token passes through, a review bot can publish production changes. The fix is an audience claim check at the MCP endpoint, not a broader API key.
Identity before authorization: use non-human identity for AI agents
Shared service accounts make MCP security incidents impossible to trace. Give every agent, tool runtime, and background job a distinct non-human identity, then attach least privilege to that identity rather than to the model. According to Practical DevSecOps, 'MCP Security Best Practices: What Actually Works in 2026', analysis of more than 5,000 open-source MCP servers found that over half relied on static secrets, while only a small fraction used OAuth for downstream connections.
That number tells you where to start: replace static secrets with short-lived tokens and split the secret into ci-review-agent, support-agent, and data-analysis-agent. Each identity gets only the scopes, resources, and destinations it needs. That also gives you per-agent audit trails without inventing a new login.
Token passthrough is an MCP server security best practices finding
Why is token passthrough dangerous for MCP servers?
MCP token passthrough lets an agent carry an upstream token straight into a downstream MCP server. The downstream server then sees a valid signature and accepts it, even though the token was issued for another audience. In an MCP OAuth 2.1 model, accept only tokens whose aud claim names this server.
Is OAuth 2.1 required for MCP servers?
OAuth 2.1 is the practical baseline for production MCP servers using authorization code flows, resource indicators, and client metadata. The minimum is audience-bound issuance, per-client consent, and a clear rejection path.
Put this check in middleware before dispatching tools. If the token was not issued for this MCP server, never forward it downstream. Log the rejection with issuer and audience, but not the raw token.
if token.aud !== mcpServerAudience {
return 401
}
if !hasScope(token, requiredScope) {
return 403
}
The confused deputy problem, reproduced and fixed with consent
What is the confused deputy problem in MCP?
The confused deputy problem appears when a trusted MCP server accepts a client request that references another user or client resource without checking consent. An attacker can trick a capable agent into using its authority against a different resource. The fix is per-client consent storage, exact-string redirect_uri matching, and state handles tied to the original request.
Reproduce it: register two fake redirect URIs, request an unowned resource, and check whether a token returns. If yes, your consent boundary is an accidental wildcard. The state value should expire before a second client can reuse it.
SSRF in OAuth metadata discovery: stop 169.254.169.254
OAuth metadata discovery asks your client to resolve attacker-supplied URLs. If those URLs can reach 169.254.169.254, localhost, or internal admin ports, your MCP server can become an egress tunnel. Put every discovery fetch behind an egress proxy that allows only known issuers and public metadata endpoints.
Test this by pointing a fake client metadata document at an internal test endpoint. If the server follows the redirect, the fix is a validation policy that rejects non-approved URLs before the network call. The same proxy should record the rejected URL for triage.
State handle hijacking: key state as user plus handle
What is state handle hijacking in the 2026-07-28 MCP spec?
State handle hijacking appears when a server uses a token-like handle as if it were an identity. In the 2026-07-28 spec, session removal makes state handle hijacking the more relevant risk. Store state as a composite key of user id, scope fingerprint, and handle.
Generate handles with a CSPRNG and expire them shortly. If a copied handle can be replayed by another agent, your state model has become authentication. A handle bound to one user should fail for another user immediately.
Tool poisoning and MCP rug pull: pin signed manifests
What is tool poisoning in MCP?
Tool poisoning in MCP is when a tool description or manifest is altered so the agent calls a dangerous function with plausible language. A rug pull is delayed: the tool later receives a new manifest that exfiltrates data. According to Cloud Security Alliance research note, citing OWASP MCP Top 10 and Microsoft Security Blog (June 30, 2026), OWASP's MCP Top 10 ranks tool poisoning as MCP03, and Microsoft's June 2026 guidance formally classifies MCP tool descriptions as supply-chain assets requiring the same review rigor as production code.
Pin tool manifests by hash, require signatures where your registry supports them, and treat every description change as a dependency update. A CI gate should fail when a tool name, argument schema, output schema, or human description changes without a review comment. Review should compare old and new descriptions, not just the binary.
Treat descriptions and results as untrusted input
How do you prevent prompt injection in MCP tool descriptions?
You prevent MCP prompt injection by separating instructions from data. Tool descriptions, error strings, and tool results should be treated as untrusted input even when they come from a trusted server. According to Chen et al., MCPTox benchmark (arXiv:2508.14925), cited in Cloud Security Alliance AI Safety Initiative research note, the MCPTox benchmark built adversarial variants of 353 real tools from 45 live MCP servers and measured a 36.5% average tool-poisoning attack success rate across 20 LLMs, peaking at 72.8% against one model.
According to Cloud Security Alliance, 'MCP Attack Surface: Tool Poisoning and IDE Auto-Execution' (citing StepSecurity), the June 2026 Miasma worm campaign planted malicious MCP configuration files in 73 GitHub repositories, including Microsoft's azure/durabletask, executing credential-harvesting payloads on developers' machines. That is a supply-chain and configuration problem.
According to Cloud Security Alliance, 'MCP Attack Surface: Tool Poisoning and IDE Auto-Execution' (citing AIM Security and Check Point Research), CurXecute (CVE-2025-54135, CVSS 8.6) let a prompt injection in a Slack message rewrite Cursor's global MCP config and auto-execute attacker code; MCPoison (CVE-2025-54136) extended the same trust flaw to shared repository configs. IDE trust boundaries need explicit review.
The fix is not one filter. Schema-validate every tool argument, strip instruction-like text from output, render results in a separate transcript zone, and reject any response that attempts to modify policy, secrets, or tool registration. Mark tool output as data in prompts, not as new instructions.
Scope minimization and step-up authorization
Wildcards in scopes_supported are a silent permission grant. Define small scopes, expose only what clients need, and use precise challenges for higher-risk actions.
Log elevation events separately from normal tool calls. If support-agent can request deploy.production without a step-up, the vulnerability is not the tool. A step-up event should capture who approved, why, and for how long.
Least-privilege runtime for stdio servers
stdio MCP servers still need sandboxing. Run each server in a container or VM with read-only mounts, no ambient credentials, and a network namespace that only reaches approved endpoints. Deny-by-default egress allowlists reduce SSRF, rug pull follow-on actions, and secret harvesting.
Mount only the directories the tool needs. Remove write access unless the tool is explicitly a writer, and give the runtime a short token with a narrow resource indicator. That prevents a compromised tool from writing a config that the next launch trusts.
Sampling, elicitation, and destructive actions
Sampling and elicitation can turn read-only agents into action systems. Rate limit every tool, cap token spend, and require confirmation for destructive calls such as delete, publish, rotate secret, or send external message.
Use default-deny policy files where the server checks an explicit allowlist before execution. A good gate returns why the action was blocked, which identity was denied, and which approval record would unblock it. For non-destructive calls, return a preview instead of committing.
Audit logs that survive an incident review
Incident reviews fail when the log says "tool called" but not who authorized it. For each MCP call, record identities, token issuer, audience, scopes, tool name, manifest hash, sanitized arguments, duration, and policy decision. Store these in an immutable sink with retention that matches your incident workflow. Keep the token hash short so the record stays useful.
Also record denied calls, scope mismatches, consent failures, and output sanitizer hits. Those events often show attempted tool poisoning, confused deputy MCP traffic, or token passthrough before an exploit succeeds.
A 30-minute red-team test plan for your MCP server
Run these probes: no token, wrong audience, copied state handle, fake metadata URL, edited description, and instruction repetition. Each probe should end in denial plus a structured log entry.
Keep the test local to staging and use non-production identifiers. Make the pass condition mechanical: 401 for wrong audience, 403 for insufficient scope, 400 for malformed state, and no egress to private addresses. If a probe succeeds, block the path before adding features.
Rollout sequence: four controls before Friday, three for 2027
Before Friday, add audience-bound checks, per-agent identities, private-range egress blocks, and pinned manifests. Those four close token passthrough, scope confusion, SSRF, and description tampering. Write the control into the deployment pipeline so it cannot be skipped.
For the 2027 roadmap, move to signed manifests, policy-based step-up authorization, richer client metadata trust policies, and continuous red-team testing. The goal is an MCP security program where every new tool begins with the same threat model questions.
Final Thoughts
Grab the one-page MCP threat-model checklist — attack, control and the exact file to edit — with ready-to-paste OAuth 2.1 audience validation, tool-manifest hashing and egress-allowlist snippets. Then subscribe to the Loonietech engineering brief for a monthly teardown of a real agent-security failure.
Related Articles
More handpicked tutorials, architecture breakdowns, and tech analyses.

MCP Security Best Practices for AI Coding Agents 2026
MCP security best practices that actually ship: OAuth 2.1 audience checks, least-privilege tool scopes, brokered secrets, prompt-injection containment, audit logs, and a pre-production checklist for AI coding agents.


AI Coding Agent Security: A Production Checklist 2026
Secure AI coding agents in production: a checklist covering agent identities, repository and CI permissions, MCP server hardening, prompt injection limits, and audit logs.


Build a Custom AI Assistant for Your Canadian Business
Step-by-step guide on building a custom AI assistant tailored for Canadian businesses, covering legal compliance, data residency, and practical implementation for 2026.

Ready to start your next project?
Whether you need a website, mobile app, or brand design, we're here to help bring your ideas to life.