MCP Server Security in Production: A Baseline You Can Audit
Most internet-facing MCP servers run without authentication. This guide covers the OAuth 2.1 baseline the spec mandates, per-tool scopes, token handling, validation, sandboxing, and audit logging, with a pre-production checklist.

Two measurement studies published in 2026 found that between 40 and 92 percent of internet-facing MCP servers run with no OAuth authentication at all, and hundreds of them expose shell execution tools with no access controls. If you are putting an MCP server in front of real company data, the fix is not exotic: the protocol specification already mandates an OAuth 2.1 baseline, and the rest is disciplined application of least privilege, input validation, and audit logging. This guide lays out that baseline as something you can actually build and then audit, with the places teams usually get it wrong.
Why MCP servers are a different security problem
A traditional API is called by code a developer wrote. Every request is deliberate, parameterized, and reviewed before it ships. An MCP server is called by a language model that decides at runtime which tool to invoke and with what arguments, influenced by everything in its context, including content it just read from the outside world.
That changes the threat model in three ways:
- The caller is probabilistic. The model can hallucinate arguments, misread tool descriptions, or be steered by prompt injection embedded in data it processed.
- Tools chain. Individually harmless calls like reading a file and sending a message compose into data exfiltration when a malicious instruction links them.
- The blast radius is whatever the server can reach. An MCP server holding a broad API token is one bad tool call away from using all of it.
The practical consequence: you cannot rely on the model to police access. Authentication, authorization, and validation have to live in the infrastructure, enforced on every request regardless of what the model decided to do. The same shift, from code that calls APIs to models that decide at runtime, is why AI agent security is the defining cybersecurity challenge of 2026. MCP concentrates it into one protocol.
What the 2026 measurement studies found
Two academic studies are worth knowing because they tell you what "average" looks like right now, and it is bad.
A team at Fudan University ran the first measurement study of authentication security in real-world remote MCP servers. They identified 7,973 live remote MCP servers and found that 40.55% exposed their tools with no authentication at all. Among the 119 OAuth-enabled servers they could test dynamically, every single one had at least one authentication flaw, 325 flaws in total, with dynamic client registration flaws affecting 96.6% of tested servers. Many of the flaws allowed sensitive information leakage or account takeover, and responsible disclosure produced nine CVE IDs.
A second study, a dynamic security assessment of internet-facing MCP servers, scanned over 21,000 detectable server instances and dynamically audited 414 of them. It found 91.8% lacked OAuth authentication completely, 687 tool instances exposed shell execution capabilities without access controls, and confirmed SQL injection, SSRF against cloud metadata endpoints, and path traversal in production servers. One detail stands out for operators: 41.6% of confirmed servers disappeared within three days between measurement runs. People are spinning MCP servers up and down constantly, with no security review in the loop.
If your team deploys an MCP server with proper OAuth, scoped tokens, and logging, you are immediately ahead of the vast majority of what is reachable on the public internet today.
The baseline the spec already mandates
You do not have to invent the security model. The MCP authorization specification already makes the hard calls, and several of them are MUSTs, not suggestions. Build to the current 2026-07-28 revision; most tutorials still reference older drafts.
OAuth 2.1 is the foundation
For HTTP-based MCP servers, authorization servers must implement OAuth 2.1 for both confidential and public clients. In practice that means:
- PKCE with S256 for every client. Most MCP clients are CLIs, desktop apps, and IDE extensions that cannot hold a secret. PKCE is what makes the authorization code flow safe for them. Reject requests without a code challenge.
- Resource indicators (RFC 8707). Clients must name the MCP server they intend to call in the authorization and token requests. This binds each token to one server.
- Audience validation on every request. Your server must check that each token was issued specifically for it, and reject anything else. A token minted for another MCP server must not work on yours.
- Protected Resource Metadata (RFC 9728). Your server must publish metadata pointing clients at the right authorization server, so discovery works without manual configuration.
Two changes in the July 2026 revision matter for anyone building now. Dynamic Client Registration, the mechanism behind the most common flaw class in the Fudan study, is formally deprecated in favor of Client ID Metadata Documents, where each client hosts a static JSON metadata file at an HTTPS URL instead of registering itself on the fly. And clients must now validate the issuer identifier on authorization responses, per RFC 9207. Descope's MCP security guidance, which is written against the current revision, has the full list.
One honest caveat: authorization is technically OPTIONAL in the protocol. That optionality exists for local stdio servers, which should pull credentials from the environment instead. The moment your server is reachable over a network, treat the OAuth baseline as mandatory.
Separate the authorization server from the MCP server
Early MCP deployments often had the server issuing its own tokens, which meant building an identity provider from scratch. The cleaner pattern, which Red Hat recommends for enterprise Kubernetes environments and the spec now endorses, is to delegate token issuance to an external OIDC provider such as Keycloak, Entra ID, or your existing SSO. Your MCP server then only validates tokens and enforces scopes, which is a much smaller and more auditable job. It also means user login, MFA, and revocation stay in the identity system your organization already runs.
Scopes: design them per tool, not per server
This is where most real-world deployments cut corners, and it is the highest-leverage control you have. A single broad scope like mcp.full_access turns every compromised token into total compromise. Per-tool scopes shrink the blast radius to whatever one operation needed.
A worked example. Say you build an internal MCP server for an operations team with five tools: read_calendar, create_calendar_event, search_crm, update_crm_record, and send_email. A reasonable scope design:
calendar.readcoversread_calendarcalendar.writecoverscreate_calendar_eventcrm.readcoverssearch_crmcrm.writecoversupdate_crm_recordemail.sendcoverssend_email, and nothing else
An agent that helps a user prepare for meetings gets calendar.read and crm.read. It physically cannot send email or modify CRM records, no matter what a prompt injection attempts. When a task needs more, use progressive scoping: the server returns a 403 with an insufficient_scope error listing the required scopes, the client requests exactly those, and the user consents to the expansion. Descope's MCP security guidance describes this step-up pattern, and the current spec defines it directly.
Two enforcement details matter. First, check scopes on every request in middleware before tool execution, not just at connection time. Second, map token claims to internal roles where you need finer control, so a tool like delete_records can require an admin role in addition to its scope.
Tokens: never pass through, exchange or vault
MCP servers frequently call downstream APIs on behalf of users, and the spec is blunt about the failure mode: an MCP server must not pass the token it received from the client to an upstream API. Passthrough breaks audience binding, bypasses the upstream service's own policy, and creates the confused deputy problem, where your privileged server can be tricked into lending its authority to a less-privileged caller. The MCP security best practices document details the attack: a static client ID at a third-party provider, combined with dynamic client registration and a consent cookie, lets an attacker obtain tokens without proper user consent.
The secure patterns, in order of preference:
- Token exchange (RFC 8693). Exchange the inbound token for a fresh, narrowly scoped token for each downstream call. The AWS Builder Center guide gives a clean example: instead of forwarding a broad user token to S3, assume a role scoped to read-only access on one bucket prefix, valid only for that call.
- Vaulted credentials with rotation. Where the downstream service only offers API keys or personal access tokens, keep them in a secrets vault such as HashiCorp Vault or a cloud secret manager, never in environment variables, source code, or logs, and never visible to the model. Rotate on a schedule.
- Short lifetimes everywhere. Access tokens should live minutes, not hours. Rotate refresh tokens for public clients, and honor revocation from the identity provider.
Beyond auth: validation, sandboxing, and supply chain
Authentication decides who gets in. Three more layers decide how much damage anything inside can do, and the OWASP MCP Security Cheat Sheet covers all of them in detail.
Input and output validation. Validate every JSON-RPC request against a strict schema before any business logic runs, with additionalProperties: false and patterns on string fields. Use parameterized queries for databases, never string interpolation. Avoid passing model-generated arguments to a shell at all; where unavoidable, use argument arrays and allowlists, not shell strings. Apply SSRF controls: a tool that fetches URLs from model-generated input must validate against an allowlist, because prompt injection will otherwise steer it to your cloud metadata endpoint. And treat every tool response as untrusted data, even from servers you approved, because tool responses are a prompt injection channel.
Sandboxing and isolation. Run servers as non-root in minimal containers with read-only filesystems. Restrict filesystem access to required directories and disable network egress unless needed. Separate sensitive servers (payments, PII, credentials) from general-purpose ones. For local servers, prefer stdio transport, which avoids a listening network endpoint entirely, though note that stdio does nothing to restrict what the process itself can touch. OWASP is specific that a bare chroot is not a process sandbox.
Supply chain hygiene. Typosquatted server package names are a common attack vector, and tool definitions can change silently after you approve them, a so-called rug pull. Hash the full tool definition including schemas and annotations, not just the description, and re-review on any change. Maintain an inventory of approved servers and scan for shadow servers. Tools like the open-source mcp-scan project, now maintained by Snyk, automate detection of poisoned tool descriptions and cross-server shadowing, and fit naturally into CI.
Logging and audit: what to record
If you cannot answer "who connected, what did they do, and why were they allowed," the deployment is not production ready. Log every tool invocation with timestamp, the client and user identity, tool name, input parameters with sensitive fields redacted, an output summary, and the authorization decision. Feed those logs into your SIEM and alert on anomalies: failed authentication spikes, unusual tool sequences like list_files immediately followed by send_email, sensitive tools used outside business hours, and abnormal data volumes in responses.
Treat every agent and server as a non-human identity with its own credentials, a provisioning and deprovisioning process, and periodic access reviews. Never write secrets or PII to logs in plaintext. This is also the layer regulators and auditors will ask about first, which matters if you operate in financial services or handle personal data under regimes like Kenya's Data Protection Act. For the wider control set this plugs into, from identity lifecycle to governance documentation, see our guide to enterprise AI agent security requirements.
A pre-production checklist
Before an MCP server touches production data, confirm each of these:
- HTTPS transport with TLS 1.2 or higher, and mTLS between your gateway and internal services where feasible.
- OAuth 2.1 with PKCE S256 enforced for every client, and no authentication fallback path.
- Resource indicators sent by clients; audience validation on every inbound token; tokens for other servers rejected.
- Authorization handled by an external identity provider, not code you wrote.
- Scopes defined per tool, checked in middleware on every request, with progressive step-up for sensitive operations.
- No token passthrough anywhere; downstream calls use token exchange or vaulted, rotated credentials.
- Strict JSON Schema validation on inputs and outputs; parameterized queries; no shell strings from model input; SSRF allowlists on any URL-fetching tool.
- Sandboxed execution: non-root, read-only filesystem, restricted egress.
- Approved server inventory; tool definitions hashed and re-approved on change; dependency scanning in CI.
- Full audit logging to a SIEM with redaction, plus alerting on anomalous tool patterns.
- Human confirmation required for irreversible or high-risk actions such as payments, deletions, and external messages, with spending limits enforced outside the model's context.
Common mistakes
These are the failures that show up repeatedly in the research and in vendor guidance:
- Shipping without auth because it is internal. Internal networks are not a trust boundary anymore, and "temporary" deployments have a way of becoming permanent. The Fudan study's 40% unauthenticated figure includes plenty of servers their owners probably considered private.
- One broad scope for the whole server. It feels like simplicity and behaves like a master key. Per-tool scopes cost an afternoon of design and pay off the first time anything leaks.
- Static API keys in environment variables for downstream calls. Long-lived, hard to rotate, and a single point of failure. Vault them.
- Trusting tool annotations. A
readOnlyHintis a hint the server asserts, not enforcement. Clients and gateways must make their own risk decisions. - Letting the model see credentials. If a secret appears in the model's context, assume it is compromised. Secrets belong in vaults the model cannot read.
- No review loop. The 41.6% three-day churn rate from the measurement study is the real story: servers appear and vanish faster than any annual audit cycle. Security has to be in the deployment pipeline, not in a yearly review.
When this is more than you need
Honest limits. If your MCP server runs locally over stdio for one developer's personal tooling and touches no shared or sensitive data, the full OAuth baseline is overkill; environment credentials and OS-level isolation are proportionate. If you are prototyping against synthetic data, spend your effort on input validation and spend limits rather than identity infrastructure. And if your actual need is a well-scoped prompt workflow with no external actions at all, a Claude Skill may be the right tool and an MCP server the wrong one; the build-versus-buy framing in what a custom MCP server costs to build and run applies to security effort too. The full baseline in this guide becomes non-negotiable at the point where a server is reachable over a network and can read or write data that matters.
Frequently asked questions
Is OAuth required for MCP servers?
The protocol makes authorization optional, but that option exists for local stdio servers, which use environment credentials instead. Any MCP server reachable over HTTP should implement the OAuth 2.1 baseline, and the spec's MUSTs around resource indicators and audience validation apply as soon as you do. Given that over 90% of audited internet-facing servers lacked OAuth in 2026, simply implementing it puts you well ahead of the field.
What is token passthrough and why is it forbidden?
Token passthrough is when an MCP server forwards the access token it received from a client to a downstream API. It breaks audience binding, hides the real caller from the downstream service, and enables confused deputy attacks. The correct pattern is to exchange the inbound token for a fresh, narrowly scoped token per downstream call, or to use vaulted credentials the model never sees.
How should I scope permissions for MCP tools?
Define one scope per tool or per small group of same-risk tools, check scopes in middleware on every request, and use progressive scoping so agents request additional access only when a task needs it. An agent that reads calendars should not hold a scope that can send email, because a prompt injection will eventually try to use it.
Are local stdio MCP servers safe by default?
Stdio avoids a listening network endpoint, which removes remote attack surface, but it does nothing to limit what the server process itself can access on the machine. You still need filesystem restrictions, least-privilege credentials, and validation of tool inputs, especially for servers that execute commands or read sensitive files.
What tools exist for scanning MCP servers?
The open-source mcp-scan project detects poisoned tool descriptions, cross-server shadowing, and changes to tool definitions after installation. It fits into CI pipelines, and pairs naturally with dependency scanning and hash-based tool definition approval. The research community has also released dynamic testing frameworks, though most teams should start with static scanning plus a strict deployment checklist.
Does this apply if I only use managed MCP servers from vendors?
Partly. A managed server from a trusted vendor shifts implementation risk, but you still own scope design, consent decisions, credential handling on your side, and audit review. Verify the vendor implements the OAuth 2.1 baseline and audience validation, and hash or pin the tool definitions you approve so silent changes surface.
Where to go from here
MCP security is mostly unglamorous identity engineering: OAuth done properly, scopes designed per tool, tokens exchanged rather than forwarded, and every invocation logged. None of it is optional once company data is in reach, and all of it is auditable, which is what makes it defensible to a security team or a regulator. Our Claude implementation service builds MCP servers to this baseline, and for banks and insurers our enterprise AI practice adds the governance documentation and audit evidence that compliance teams need. For broader agent hardening beyond MCP, see our guide to AI agent deployment security best practices.
About AI Agents Plus Editorial
AI automation expert and thought leader in business transformation through artificial intelligence.



