What MCP server security covers
An MCP server is the boundary between a language model and a real system. Whatever the server exposes as a tool, an agent can call, and it calls it with whatever arguments the model produced, which may have been shaped by content the model read a moment earlier. Securing the server means controlling three things: who can connect to it, what each tool is allowed to do, and what happens to the data that passes through it in either direction.
The specification spreads its security requirements over three documents: the Authorization specification (for servers on an HTTP transport), the Security Best Practices document, and the security considerations at the end of the Tools page. This guide gathers the parts a server author is responsible for into one checklist. Requirements are quoted at the strength the specification gives them (MUST, SHOULD); where something is our recommendation rather than the specification's, it says so.
The threats the specification names
- Token passthrough. A server accepts a token from the client without checking it was issued to the server, and forwards it to a downstream API. The specification forbids it: it bypasses rate limits and monitoring that depend on the token's audience, breaks the audit trail, and lets a stolen token use the server as a proxy for exfiltration.
- Confused deputy. An MCP proxy server that uses one static client ID with a third-party authorization server, lets clients register dynamically, and skips its own per-client consent can be tricked into sending an authorization code to an attacker's redirect URI, because the third party's consent cookie skips the consent screen.
- Session hijacking. On stateful HTTP servers, an attacker who obtains or guesses a session ID can impersonate the client, or inject events into a shared queue that another server instance later delivers to the real client as if they were genuine.
- Over-broad scopes. A token granted every scope up front (
files:*,admin:*) turns one leaked token into access to every tool, and makes revocation disruptive because the one token is behind every workflow. - Local server compromise. A server installed and run on a user's machine runs with the client's privileges. A malicious startup command or package can execute code or read secrets, and a local HTTP server left open can be reached by other processes or through DNS rebinding.
- Untrusted tool metadata and output. Tool descriptions, annotations and results are all text the model reads. The specification says clients MUST treat tool annotations as untrusted unless they come from trusted servers, and servers MUST sanitize tool outputs. Content a tool returns (a web page, an inbound email) can carry instructions aimed at the model.
Checklist for a remote (HTTP) MCP server
- Validate every access token's audience. Servers MUST validate access tokens as an OAuth 2.1 resource server and MUST check the token was issued specifically for them, using the audience binding of RFC 8707 Resource Indicators. Reject anything else with a 401.
- Never forward the client's token downstream. Servers MUST NOT accept tokens that were not issued for the server. If a tool calls another API, the server gets its own credential for that API rather than passing the caller's token through.
- Don't authenticate with sessions. Servers that implement authorization MUST verify every inbound request and MUST NOT use sessions for authentication. Session IDs MUST be secure and non-deterministic, and SHOULD be bound to the user, for example by keying stored session data as
<user_id>:<session_id>with the user ID taken from the token, never from the client. - Start every client on the smallest scope. Offer a minimal baseline scope for discovery and read-only tools, and ask for more with a targeted
WWW-Authenticatescope="..."challenge the first time a privileged tool is called. Avoid wildcard or omnibus scopes, don't list every scope inscopes_supported, and still check permissions in the server's own logic rather than trusting the scopes a token claims. - If you proxy a third-party API, keep your own consent. Proxy servers MUST keep a per-user registry of approved client IDs and show their own consent page (naming the client, the scopes and the redirect URI) before forwarding to the third party. Redirect URIs MUST match the registered one exactly, and the OAuth
statevalue MUST be random, single-use, short-lived and set only after consent. - Validate inputs, control access, rate limit, sanitize outputs. The Tools page lists four things servers MUST do: validate all tool inputs, implement proper access controls, rate limit tool invocations, and sanitize tool outputs. Validate against the tool's input schema and then against business rules the schema can't express.
- Describe tools honestly and narrowly. Set the
readOnlyHint,destructiveHint,idempotentHintandopenWorldHintannotations to match what each tool really does, so clients can decide what needs confirmation. Our recommendation: one tool per action with a distinct risk level, rather than one general-purpose tool whose arguments decide whether it reads or writes. - Log what agents did and what they were allowed to do. Log scope elevation events (scope requested, subset granted) with correlation IDs, as the specification suggests, and log each tool call with the client and user it came from, so an incident can be traced to one agent and one token.
If the server runs locally over stdio
The Authorization specification is for HTTP transports. Servers on the stdio transport SHOULD NOT follow it and should take credentials from the environment instead, so the work moves to how the process is started and what it can reach.
- Prefer stdio for local servers. The specification recommends the
stdiotransport for servers meant to run locally, because only the client that launched the process can talk to it. A local server on HTTP should require an authorization token or use a unix domain socket or other restricted IPC. - Run with the least the server needs. The server runs with the same privileges as the client that starts it. Ship it so it can run in a sandbox or container with restricted file system and network access, and document which directories and hosts it actually needs.
- Keep secrets in the environment, scoped to the server. Read API keys from environment variables set for this server only, and use keys that carry only the permissions the server's tools need.
Applying it to an MCP server that sends email
A send tool deserves more care than most write tools because it is an outbound channel. An agent that can read untrusted content (inbound mail, a web page, a support ticket) and can also email any address can be steered by that content into sending data somewhere it shouldn't. A wrong send can't be recalled, and a burst of bad sends damages the sending domain's reputation for every message after it. These controls are our recommendations on top of the checklist above.
- Separate tools, separate scopes. Keep reading mail, sending one transactional message and sending a broadcast as different tools behind different scopes, so an agent that only sends receipts never holds the right to email a whole list.
- Constrain recipients on the server. Decide in server logic who a tool may email: the user the transaction belongs to, an opted-in list, or an allowlist of domains. Don't leave the recipient as a free-text argument the model fills in from whatever it read.
- Lint every message before it is accepted. Reject sends with unrendered template variables, a missing unsubscribe link on marketing mail, or a sender domain that isn't verified, and return a machine-readable error that says what to fix.
- Require an idempotency key on every send. Agents retry. Without a key, a timeout followed by a retry is two emails to the same person.
- Rate limit per agent key and keep a person on broadcasts. Limit sends per key and per time window, watch bounce and complaint rates, and put broadcast sends behind a confirmation a person can deny, in line with the specification's advice that a human should be able to deny tool invocations.
- Give each agent its own credentials and sending identity. Per-agent keys and separate sending domains or subdomains keep one agent's mistakes from spending another's reputation, and make the logs say which agent sent what.
How to check a server you didn't write
Most teams connect agents to MCP servers someone else maintains. We don't rate servers here; these are the questions to put to a vendor's documentation, security page or support team before connecting an agent.
- How does it authenticate?. OAuth per the MCP Authorization specification, or a static API key? If a key, can it be scoped and rotated per agent?
- Does it check token audience and refuse passthrough?. Ask whether it validates that tokens were issued for it, and whether it uses its own credentials for the APIs behind it.
- What scopes and tools exist?. List the tools and the permission each one needs. A server that offers only one all-access key or scope can't be given less than everything.
- Are the tool annotations accurate?. Compare
readOnlyHintanddestructiveHintwith what each tool actually does. A write tool marked read-only would skip your client's confirmation step. - What is logged, and where can you see it?. You need per-call logs naming the client and token to investigate anything an agent did.
- Who maintains it, and how are vulnerabilities reported?. Check the repository or vendor site for a security policy, a disclosure contact and recent releases.