Skip to content

Secure an MCP server

Last reviewed October 23, 2026

An MCP server does things with its user's access, at the request of a model that may have just read a web page written by a stranger. Hold that sentence in your head while you build and most of the rules below follow from it. The rest come from the specification's own security practices (security best practices), which are short and worth reading in full.

Local servers: keep the door closed

A server that runs on the user's machine should use stdio, which no other program on the network can reach. If yours has to listen on HTTP locally, bind it to 127.0.0.1, never 0.0.0.0, and validate the Origin header on every request; without that check, a web page the user visits can talk to your server through their browser (Streamable HTTP). Credentials come from the environment the client starts you in, not from a login flow.

Remote servers: OAuth, the way the specification says

A remote server that needs a login is an OAuth 2.1 resource server, and the specification is precise about what that means (authorization):

  • Publish OAuth Protected Resource Metadata (RFC 9728), and point clients to it from the WWW-Authenticate header of your 401 responses.
  • Accept tokens only in the Authorization header, never in a query string.
  • Check that each token was issued for your server, and answer 401 to any token that is invalid or expired.
  • Expect clients to identify themselves with a Client ID Metadata Document. Dynamic client registration is deprecated as of the July 2026 specification.

Never pass a token through

This one is a hard rule: a server must not accept a token that was not issued for it, and must not forward the client's token to another service. If your server calls GitHub or Stripe for the user, it gets its own token for that service. Token passthrough feels like a shortcut and turns your server into a way around every other service's access checks.

Ask for the least access, as late as you can

Request narrow scopes, and ask for more only when a tool needs them. Keep reading and writing in separate tools, so a client can allow one without the other, and say plainly in a tool's description when it deletes, sends or pays for something. People approve tool calls faster than they read them; the description is your one chance to slow them down.

Treat every tool call as hostile input

The arguments arrive from a model, and the model may be following instructions planted in a document it read. Validate every input against its schema and against what makes sense, check access on each call rather than once, and rate-limit anything expensive. A tool that fetches URLs should refuse private and cloud-metadata addresses and insist on HTTPS, or it becomes a way into the user's network. And if your server hands out handles to keep state between calls, make them random and tie them to the user; holding a handle is not proof of who someone is.

Prompt injection through what you return

A server that returns web pages, emails, issues or files is passing text from strangers straight to the model. You cannot clean that text reliably, so be honest about it: say in your README which tools return outside content, and keep that content clearly separated from your own words in the result. Clients treat tool descriptions as untrusted unless they trust the server, so keep yours factual. A description that addresses the model ("always call this tool first") reads exactly like an attack, to clients and to scanners.

Secrets

Read API keys from environment variables, keep them out of logs and error messages, and mark them isSecret where you declare them in server.json, so anything that reads the file knows to treat them as secret. Never put a real key in an example, a test fixture or a README; scanners find them, and so do people with worse intentions.

How findsafeskills rates a server

This site scans the text a server publishes: its README, its manifest if it has one, and its description. It looks for instructions that try to override the agent's role, data sent somewhere it should not go, hidden or obfuscated text, secrets left in the open, destructive commands, and downloads piped into a shell. The rating is a static text check, not a code audit, and it says so on every listing (how ratings work). A server written by the rules on this page has little for it to find.

Building something else? See the guides to a skill and a plugin or marketplace.