MCP security best practices.

The main MCP security risks, from prompt injection to token passthrough, what the specification requires for each, and checklists for server builders and for teams using MCP.

By the NestedBit team · Updated

Why MCP needs its own security review

An MCP server gives a language model tools that act with someone’s access. That changes who you’re defending against. The caller isn’t a person clicking a button or a program following fixed code: it’s a model choosing tools and arguments based on text, and some of that text can be written by an attacker. So besides the usual questions about sign-in and input handling, you have to ask what happens when the model is misled.

The risks below come from the MCP specification’s security best practices (2026-07-28 revision) and the OWASP MCP Top 10, grouped by where they arise. Checklists for server builders and for teams using MCP follow.

Risks in what the model reads

Prompt injection
A tool returns a web page, ticket or email containing instructions, and the model follows them: it might read private files and send them elsewhere. No filter stops this reliably, so limit the damage instead: narrow scopes, and a person’s approval before anything that sends data out or can’t be undone.
Tool poisoning
Tool descriptions go to the model as well, and users rarely read them. A malicious server can hide instructions there, including in invisible characters. The specification tells clients to treat annotations as untrusted unless the server is trusted, since readOnlyHint on a tool proves nothing.
Tools that change after approval
A server’s tool list can change over time, so a tool you reviewed last month may do something else now. Clients should show changes and ask again, and teams should pin the versions they’ve reviewed.
Over-sharing context
Everything sent to the model or a tool can reach whoever runs it. A server that returns whole records when one field would do puts more data in play than the task needs, for both the model and any other tool in the session.

Risks in sign-in and tokens

No authentication
Remote servers left open, or checking only that a token is present. Require OAuth on anything private: see Adding OAuth to an MCP server.
Token passthrough
A server that accepts a client’s token and forwards it to another API, or accepts tokens not issued for it. The specification forbids both. Downstream services then trust a token nobody checked was meant for them, and your logs can’t tell who did what. Get a separate token for each upstream API.
Confused deputy
An MCP proxy uses one static client ID with a third-party API, lets clients register themselves, and remembers consent in a cookie. A malicious client can then skip the consent screen and collect an authorization code meant for someone else. Proxies must get consent per client before going to the third party, match redirect_uri exactly, and use a single-use state set only after consent. Consent cookies should use the __Host- prefix with Secure, HttpOnly and SameSite=Lax, and the consent page should refuse to be framed.
Scope creep
One broad scope, or a client that asks for everything on first sign-in, so a stolen token or misled model can reach all of it. Start with a minimal scope, ask for more as tools need it, and don’t use wildcards.
Stolen tokens
Tokens stored loosely, or cached and logged on the server, work for whoever finds them. Store them securely, keep access tokens short-lived, rotate refresh tokens for public clients, and keep tokens out of logs, errors and URLs.
Authorization mix-up
A client talking to several authorization servers can be tricked into sending a code from an honest one to a malicious one. Clients must compare iss on the response with the issuer they recorded before the redirect (RFC 9207).

Risks in the server itself

Command injection
Tool arguments come from a model that may be acting on an attacker’s text, so treat them as hostile input. The same goes for SQL, file paths and URLs.
// Unsafe: text the model chose reaches a shell.
exec(`git log ${branch}`);

// Safer: check the value, and run the program with no shell.
if (!/^\w[\w./-]*$/.test(branch)) throw new Error('Invalid branch name');
execFile('git', ['log', branch, '--']);
Server-side request forgery
A malicious server can name internal addresses in resource_metadata, authorization_servers or its endpoints, and the client fetches them, cloud metadata services at 169.254.169.254 included. Any URL-fetching tool has the same problem. Require HTTPS, block private and link-local ranges, check each redirect, and watch for DNS rebinding. An egress proxy such as Smokescreen does much of this for you.
Local server compromise
A local server runs with the user’s privileges, so a one-click install is a remote code execution risk if the command isn’t shown. Clients must show the exact command and get consent. Run local servers in a sandbox, prefer stdio, and if one must use HTTP, require a token or use an IPC socket.
Requests from web pages
A page in a user’s browser can reach a server on their own machine or network. Validate the Origin header and refuse unknown origins with a 403.
State handle hijacking
The 2026-07-28 revision has no protocol sessions, but servers can still hand out handles to server-side state. A handle is never proof of identity. Generate handles randomly, and bind them to the user on the server, for example by storing them under <user_id>:<handle>, so a guessed or leaked handle gets another user nothing.

Risks in how teams adopt MCP

Shadow servers
People connect servers to their assistants on their own, often with personal tokens, and nobody knows what has access to what. Keep a list of approved servers and make it easy to add to.
Supply chain
An MCP server is a dependency with access to your systems. A package that’s malicious, typo-squatted or later taken over gets everything the server can reach. Pin versions, review updates, and use servers from their vendors where they exist.
No audit trail
If you can’t say which agent called which tool for which user with which arguments, you can’t investigate an incident or show you’d notice one. Log tool calls from the start, with secrets kept out.

The combination to watch for

Most of these risks get serious when one session has three things together: access to private data, exposure to text an attacker can write, and a way to send data out. A model with all three can be talked into sending your data elsewhere, with no bug in any single server. The combination is easy to create by accident, because each server looks fine alone. Where a session needs all three, take one away or put a person’s approval on the outbound step.

Checklist for MCP server builders

Sign-in and tokens

  • Require OAuth on HTTP servers that hold anything private, and publish protected resource metadata.
  • Check signature, issuer, expiry and audience on every request.
  • Never forward a client’s token. Get a separate token for each upstream API.
  • Keep tokens out of logs, error messages and URLs.
  • Return a minimal scopes_supported, and no offline_access.

Tools

  • Offer the fewest tools that do the job, and keep read, write and delete as separate tools.
  • Give each tool a scope and check it when the tool runs.
  • Validate every input against its schema. Never pass one to a shell, and use parameterised SQL.
  • Restrict file paths and URLs to what the tool needs.
  • Rate limit calls, and sanitize what tools return.
  • Write honest descriptions and annotations, with nothing in them meant for the model alone.
  • Don’t mark sensitive parameters with x-mcp-header.

Network and operations

  • Serve remote servers over HTTPS, and refuse unknown Origin values.
  • Bind any state handle to the user, and never treat it as proof of identity.
  • Block private address ranges on anything that fetches a URL.
  • Log each tool call with user, client, tool and outcome, and alert on anything unusual.
  • Pin dependencies, and review updates.

Checklist for teams using MCP

  • Keep a list of approved servers, each with an owner.
  • Read each server’s tool descriptions before approving it, and review them again when they change.
  • Pin versions, and read the exact command before installing a local server.
  • Run local servers in a sandbox, with access only to the folders they need.
  • Keep a person in the loop for anything that writes, sends, deletes or moves money, as the specification advises.
  • Don’t approve whole servers at once just because the prompts are annoying.
  • Give agents their own accounts and the narrowest role, not a person’s login.
  • Keep credentials out of shared config files and repositories.
  • Watch for sessions that mix private data, untrusted content and a way to send data out.
  • Log tool calls centrally, and revoke access when people or projects move on.

For deciding what an agent’s role should allow, see RBAC or ABAC? and the RBAC Matrix Builder.

If you build an MCP client

  • Use PKCE with S256, and refuse to continue if the authorization server doesn’t list it.
  • Send resource on authorization and token requests, and check state and iss on the response.
  • Open only http and https authorization URLs, and reject schemes such as javascript:. Don’t pass URLs to a shell.
  • Block private addresses when you follow URLs from server metadata.
  • Show tool inputs before a call, ask before sensitive operations, and offer a way to deny.
  • Treat annotations from servers you don’t trust as untrusted, set time-outs, and validate results before they reach the model.

The OWASP MCP Top 10

OWASP’s list is still in beta, but it’s a useful way to check coverage. Here’s where each entry falls in this guide:

IDRiskSection above
MCP01 Token Mismanagement & Secret Exposure Sign-in and tokens
MCP02 Privilege Escalation via Scope Creep Sign-in and tokens
MCP03 Tool Poisoning What the model reads
MCP04 Software Supply Chain Attacks & Dependency Tampering How teams adopt MCP
MCP05 Command Injection & Execution The server itself
MCP06 Prompt Injection via Contextual Payloads What the model reads
MCP07 Insufficient Authentication & Authorization Sign-in and tokens
MCP08 Lack of Audit and Telemetry How teams adopt MCP
MCP09 Shadow MCP Servers How teams adopt MCP
MCP10 Context Injection & Over-Sharing What the model reads

Where to start

If you run a server, point the MCP Security Checker at it and fix what it finds, then paste your tools/list output into its review box. It can only see the outside, so the checklist above covers what your code does with a real token. If sign-in is what’s missing, start with Adding OAuth to an MCP server.

Free tool · No sign-up

MCP Server Security Checker

Check an MCP server's sign-in, discovery and tools for security gaps, with code to fix each one.

Starts with a free 30-minute intro call, or email hello@nestedbit.com.