AiIntermediate

MCP Servers in Production: Auth, Sandboxing, Governance

DeveloperHat Team
15 min read

TL;DR

Run Model Context Protocol servers safely: OAuth 2.1 auth, sandboxing, tool-poisoning defenses, and the controls that stop AI agents from abusing your tools.

A Model Context Protocol server is an API that a language model can call on its own initiative. That is the whole appeal — and the whole risk. The moment an agent can read a ticket, query a database, or run a shell command without a human in the loop, every tool you expose becomes a permission the model can exercise, and every tool description becomes an instruction the model will follow. Most teams that ship an MCP server in an afternoon spend the next month discovering what they actually exposed.

The short version: treat an MCP server like a production API that takes instructions from untrusted text, because that is what it is. Put a gateway in front of it that enforces OAuth 2.1, keep an allowlist of approved tools, read every tool description before the agent does, give each tool the least privilege it needs, and log every call. Local stdio servers are fine on a developer's machine with sandboxing; a remote server with no auth is not fine anywhere. The current specification — revision 2026-07-28, current as of November 2026 — gives you the pieces, but authorization is optional in the spec, so the enforcement is your job.

Production MCP in one picture The agent never talks to a tool directly — the gateway authenticates, scans, and logs. Agent host LLM app MCP gateway OAuth 2.1 · allowlist MCP server tools + resources Tool database · API · shell Audit log every tool call recorded Scan + allowlist descriptions reviewed Poisoned tool blocked before the agent Auth is optional in the spec — so the gateway, not the protocol, enforces it.

Why MCP changes the security model

MCP, introduced by Anthropic in November 2024 and now governed under the Linux Foundation, standardizes how an AI application gets context from outside systems: tools to call, data to read, and prompt templates to offer. Messages are JSON-RPC 2.0 between three participants — a host (the LLM application), a client (a connector inside the host), and a server (the service that provides context and capabilities). The 2026-07-28 revision made the protocol stateless: no initialize handshake, no protocol sessions, and every request carries its own version and capabilities.

Three properties of that design change the threat model relative to a normal API:

The model reads tool descriptions as instructions. A tool's name, description, and parameter schema are text the model consumes with full trust while planning. The specification itself says descriptions of tool behavior should be considered untrusted unless obtained from a trusted server, and that hosts must obtain explicit user consent before invoking any tool. A server that can change its descriptions can change what the agent does — and a compromised or malicious server can hide instructions in them. Security researchers call this tool poisoning, and it is the threat that has no equivalent in a conventional API, where the caller is code you wrote.

The server acts with its own credentials, not the caller's. When an agent calls a tool, the tool runs with whatever the server was configured with — its database credentials, its cloud role, its API keys. In 2026, researchers disclosed remote MCP servers whose authentication could be bypassed entirely, letting an unauthenticated caller run tools with the server's credentials. The agent's identity and the tool's authority are two different things, and MCP does not bind them for you.

The data the tools return is untrusted input. A tool result — an email, a ticket, a web page, a database row — can contain instructions planted by a third party. The model reads it, and the line between "data to summarize" and "instruction to follow" is one the model draws for itself. Our guide to verifying AI agent actions covers the attestation side of this problem: logs say what happened, attestation proves it.

None of this makes MCP unusable. It makes MCP a production system with a real threat model, and the teams that get hurt are the ones who treated it as a demo integration.

The options

Option 1: Local stdio servers on developer machines

The host launches the server as a local subprocess and talks to it over standard input and output. Credentials come from environment variables; there is no OAuth profile for stdio, and the specification says stdio servers should not use authorization. This is the right shape for a developer's own tools on their own machine: a filesystem server, a local database client, a git helper.

The controls here are operating-system controls. Run the server with the least privilege it needs — a dedicated user or a sandboxed process, not your login shell with your cloud credentials in the environment. Keep secrets out of the places an AI assistant can read; our secrets hygiene guide covers the exclusion rules, sandboxing, and scanning that apply here. And treat the server package as supply chain: a malicious MCP package distributed through a public registry compromised a reported 437,000 developer environments in 2025 (CVE-2025-6514), exploiting unsanitized OAuth endpoints for remote code execution. Pin versions, install from sources you trust, and review updates.

Pick this when one developer runs tools on their own machine. Do not pick it for shared tools: there is no central auth, no central audit log, and every machine is its own security boundary.

Option 2: Direct remote servers — Streamable HTTP with OAuth 2.1

The server runs as its own service and exposes one endpoint, such as https://example.com/mcp. Every client message is its own HTTP POST, and the server answers with a single JSON object or a server-sent-events stream scoped to that one request. The older HTTP+SSE transport is deprecated — migrate if you still run it.

For authorization, the specification defines an OAuth 2.1 profile for HTTP servers: the MCP server acts as an OAuth resource server, publishes Protected Resource Metadata (RFC 9728), and answers unauthenticated requests with a 401 and a WWW-Authenticate header pointing at that metadata. The client discovers the authorization server from that document and obtains a token, typically from the organization's existing identity provider. The transport also requires servers to validate the Origin header to block DNS rebinding — an attack that lets a remote website reach an MCP server on a user's machine — and locally running servers should bind only to 127.0.0.1, never to all interfaces.

The catch is that authorization is optional in the specification. A remote server can simply not implement it, and many early ones did not. So the control is not "use OAuth 2.1" — it is "use OAuth 2.1, and prove the server rejects unauthenticated calls." Test it the way an attacker would: send a request with no token and confirm it stops, not that it returns an error and continues. The probe below does exactly that.

Pick this when you have one or two low-risk, read-only servers and a team that will own their auth configuration. Do not pick it as the default for a fleet: every server re-implements auth, allowlisting, and logging, and the tool descriptions are still trusted by the model.

Option 3: A gateway in front of every server

Put one choke point between agents and servers. The gateway terminates OAuth 2.1, enforces a per-tool allowlist, scans tool descriptions for injected instructions, rate-limits calls, and writes an audit log of every tool call and result. The server behind it can stay simple — it only accepts traffic from the gateway, on a private network, with the gateway's identity.

This is the same shape as the gateway-versus-mesh decision in service architecture: one front door that decides who may call, and a network behind it that decides how services talk. Our service mesh vs API gateway guide covers the trade-offs of that pattern; the MCP version of it is smaller, because the gateway's job is policy and inspection, not routing between dozens of services.

The gateway is also where the runtime defenses live. Inspect tool descriptions when a server is added and again at runtime, because a server can change what it tells the agent after approval — researchers found a live campaign in August 2026 whose server behaved normally for its first three tool calls and then told the agent to collect SSH keys and cloud credentials. Pin server versions, re-scan on every session, and diff descriptions against the approved copy. Inspect tool calls and results at runtime, not only the user's prompt: the instruction that steers the agent is usually hidden in a description or a result. And red-team the setup before release — a poisoned description, an injected tool result, an unapproved server — and again after every change.

Pick this as the default for any team running MCP servers for more than one user or more than one agent. It is the only option where auth, allowlisting, scanning, and auditing live in one place you control.

Option 4: A managed MCP platform

A vendor runs the servers and the gateway; you configure which tools are exposed and who may use them. This is the fastest way to stand up production MCP, and the right choice when you have no platform team to run a gateway. You inherit the vendor's incident response, their credential handling, and their audit retention — which is the point, and also the limit.

Do not pick it when tools touch regulated data, when you need audit logs in your own SIEM on your own retention schedule, or when the vendor's credential model means the vendor holds keys to your systems. Read the data-processing terms the way you would for any SaaS that holds production credentials, because that is what it is.

The comparison

OptionAuthWho reviews toolsAuditOps burdenBest for
Local stdioNone (env creds)The developerNone, per machineLowOne developer, own machine
Direct remoteOAuth 2.1, per serverWhoever owns the serverPer server, if builtMedium — each server re-implements it1–2 read-only servers
GatewayOAuth 2.1, one placeGateway policy + human reviewCentral, every callMedium — one component to runTeams, fleets, production
Managed platformVendor'sVendor + your allowlistVendor's, on their termsLowNo platform team, low-risk tools

Trade-offs

Tool poisoning and rug pulls are the threat you cannot patch once. The model trusts descriptions, and descriptions can change after approval. The controls are process, not protocol: pin versions, review descriptions on every session, diff them against the approved copy, and alert when they change. The 2026-07-28 revision helps here — servers can notify clients when the tool list changes, and list results carry cache hints — but efficient updates are also silent updates unless someone is watching.

Prompt injection through tool results has no complete fix. You cannot fully prevent it, because the model reads text it cannot perfectly separate from instructions. What works is limiting the damage: return structured data instead of prose where you can, label third-party content as untrusted, keep sensitive capabilities out of the session, and require a human confirmation before any tool call that moves money, deletes data, or changes access. The confirmation step is a product decision, not a protocol feature — MCP cannot enforce it, so your gateway or your host must.

Authorization being optional means your tests are the enforcement. The spec says what a conforming server should do; it cannot make a server do it. Every remote server in your fleet needs an unauthenticated-call test in CI, not just a code review. If the test ever passes a call without a token, the server does not ship.

Credential scope is where the blast radius is set. Give each tool the least privilege it needs, and give each server its own credentials — never one shared key across servers, and never forward a user's token through a server to a downstream API, which turns the server into a confused deputy. The 2026-07-28 revision tightens this area with Protected Resource Metadata and issuer validation on token redemption, but the scope decision is still yours: a read-only tool with a read-only credential cannot exfiltrate by writing, and a tool that cannot reach the internet cannot phone data home.

Version churn is real and recent. The 2026-07-28 revision deleted the initialize handshake, protocol sessions, and the session-ID header, and deprecated Sampling, Roots, and Logging, with removal no earlier than July 2027. Servers and clients written against the 2025-11-25 revision will break against a 2026-07-28 peer. Pin the spec revision and the SDK version in your gateway, test upgrades in staging, and treat "the protocol changed" as a scheduled event, not a surprise. For the broader picture on governing AI systems, see our AI security governance guide.

The gateway costs latency and a component. Every call passes through one more hop, and description scanning adds work per call. That is the price of the choke point, and it is cheaper than the incident. If a tool is latency-critical and low-risk — a read-only lookup with no side effects — the gateway can fast-path it by policy, but the fast path should be an explicit allowlist entry, not the default.

Recommendation

For most teams in late 2026: run a gateway, enforce OAuth 2.1, allowlist tools, scan descriptions, log everything.

If you are one developer on your own machine, stdio servers with sandboxing and pinned versions are fine. Keep secrets out of the assistant's reach and review server updates.

If you run remote servers for a team, put a gateway in front of them. Direct remote servers without a gateway are acceptable only for a single read-only server whose auth you test in CI — and the moment a second server appears, the gateway pays for itself.

If you have no platform team, use a managed platform, but only for tools whose data and credentials you are willing to put in a vendor's hands. Keep the allowlist tight and the audit exports on.

If a tool moves money, deletes data, or changes access, it gets a human confirmation step, a dedicated credential with the narrowest scope that works, and an alert on every invocation. No exceptions, and no "the agent is usually careful."

When not to use MCP

Do not adopt MCP because the protocol is fashionable. If you have a handful of tools, all internal, all stable, a plain typed API client is simpler, easier to audit, and easier to test than a protocol that lets a model choose its own calls. MCP earns its complexity when tools change often, when many agents share them, or when third-party servers are involved.

Do not expose a tool you have not staffed a review for. Every new server and every tool update needs a human to read its descriptions and check its credentials. If nobody owns that review, the allowlist quietly becomes "everything anyone asked for," which is the same as no allowlist.

Do not put a destructive tool behind an agent without a confirmation step. MCP has no built-in "are you sure" — if you do not build it, the agent will not ask.

And do not run a remote MCP server without authentication because it is "internal only." Internal networks are where the 2026 unauthenticated-server disclosures happened, and an internal server with the production database credential is the highest-value target on the network.

What to do next

This week, inventory what you already run:

  • [ ] List every MCP server in use — local and remote, approved and ad-hoc
  • [ ] For each remote server, send an unauthenticated request and confirm it is rejected
  • [ ] Read every tool description on every server; pin versions and record the approved copy
  • [ ] Give each server its own least-privilege credential; remove any shared key
  • [ ] Put a gateway (or a managed platform) in front of remote servers, with an allowlist and an audit log
  • [ ] Add a human confirmation step to any tool that moves money, deletes data, or changes access
  • [ ] Red-team the setup: a poisoned description, an injected tool result, an unapproved server
  • # An MCP server that enforces auth answers an unauthenticated
    # request with 401 and points at its Protected Resource Metadata.
    # The protocol-version and method headers are required by the
    # 2026-07-28 revision; a conforming server checks auth, not
    # just the headers.
    curl -s -i https://mcp.example.com/mcp -X POST \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json, text/event-stream' \
      -H 'MCP-Protocol-Version: 2026-07-28' \
      -H 'Mcp-Method: tools/list' \
      -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
    # Expect: HTTP/1.1 401 Unauthorized
    # WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource"
    # If you get a 200 with a tool list, the server has no auth —
    # do not connect an agent to it.

    Run that probe against every remote server before any agent connects to it. The server that answers 200 to an anonymous caller is not a tool server — it is an open door with your credentials behind it.

    Why This Matters

    Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.

    Trade-offs to Consider

    Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.

    When NOT to Use This

    Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.

    Decision Framework

    Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.

    Share this articleShare on XShare on LinkedIn

    Keep the decision frameworks coming

    One practical architecture guide a week — patterns, trade-offs, and when not to use them. No spam, unsubscribe anytime.