Skip to content

MCP server security checklist

Level 4: Build. About 12 min. Checked on 19 November 2026 against MCP security best practices for spec 2026-07-28.
Stage 4 of 4: Build

In this lesson you'll check your MCP server against the attacks the MCP spec authors describe and fix the common mistakes before you ship.

Your server works, and someone in another team wants to connect it to their assistant. Before you say yes, remember what you're handing over: a program that an AI model will call on someone's behalf, with their tokens, on their data. Most problems come from a short list of mistakes, and the MCP project has written them down.

This page turns the MCP security best practices into a list you can go through before every release. "Must" below means the guidance says MUST; "should" means SHOULD. The guidance covers both sides of the protocol; these are the items that apply when you build a server.

one tool call,one round trip1Model asks2You approve3App runs it4Result back
Where a tool call goes. The model asks for a tool by name with arguments. The app checks with you, runs the tool (through an MCP server, for example), and sends the result back to the model, which answers or calls again.

Every item below protects one of the steps in that loop: who is allowed to call, what the call may do, and what comes back to the model.

Tokens and sign-in (remote servers)

  • Accept only tokens issued for your server. Check the token's audience. The guidance says servers must not accept tokens that were not explicitly issued for them, and the authorization spec forbids "token passthrough": taking a client's token and forwarding it, unchecked, to the API behind you.
  • If you proxy a third-party API with one fixed OAuth client ID, ask for consent per client. This closes the "confused deputy" attack, where an attacker uses a consent cookie from an earlier sign-in to skip the consent screen. Your consent page must name the requesting client, show the scopes and the redirect URI, protect against CSRF and refuse to be framed.
  • Match redirect URIs exactly against the registered value, with no patterns or wildcards.
  • Treat the OAuth state value as single-use: random, stored only after consent, checked exactly at the callback, deleted after use and short-lived (the guidance gives about 10 minutes as an example).
  • Ask for the smallest scopes first. Start with low-risk read scopes and ask for more when a privileged tool is first used, instead of requesting every scope up front. Avoid wildcard scopes such as * or full-access.

State and identity

  • Verify every request when your server has sign-in. The protocol is stateless as of the 2026-07-28 version, and possession of a state handle (a cart ID, a job ID) must never count as authentication.
  • Make handles unguessable and bind them to the user: random IDs, stored server-side under the verified user's ID, and rejected when another user presents them.

Outbound requests

  • Don't fetch arbitrary URLs from tool input without limits. The guidance describes server-side request forgery (SSRF) mainly against clients, but the same defences apply to any server that fetches URLs: require https, block private, loopback and link-local addresses (including the cloud metadata address 169.254.169.254), check every redirect, and prefer an egress proxy over hand-written IP checks.

Local servers

  • Use the stdio transport for local servers, so only the app that started the server can talk to it.
  • If a local server must listen on HTTP, require an auth token or use a Unix socket or other restricted IPC, so a web page or another program on the machine can't reach it.
  • Keep your install command short and readable. Apps that offer one-click setup must show the full command before running it; a command users can read is one they can trust.
  • Never write to stdout in a stdio server except protocol messages; log to stderr.

Tool design

  • Mark read-only tools with the readOnlyHint annotation. ChatGPT treats every tool without it as a write action that needs the user's confirmation.
  • Validate inputs with a schema (zod in TypeScript, type hints in Python) and reject anything outside it before you act.
  • Split dangerous actions into their own tools (delete, send, pay) so users can approve or switch them off one by one.
  • Return data, not instructions. Text your tools return goes into the model's context. Claude's and ChatGPT's docs both warn that a malicious server can hide instructions in tool results; content you pass through from web pages, emails or tickets can carry the same kind of injected instructions, so label it clearly as untrusted data.

Secrets and publishing

  • Read secrets from environment variables, never from arguments or committed config, and list them in server.json with isSecret: true.
  • Publish from an account and namespace you control (see publishing to the MCP Registry) so users can tell your server from look-alikes.
  • Document what the server can read and change, in the README and in each tool description.

Before you ship

What to try next

Share this lesson
  • Re-read your tool descriptions as if you were the model: does each one say what it changes?
  • Publish with a namespace people can verify: publishing to the MCP Registry.

Lesson 3 of 6 in this path

Words used in this lesson

Sources

Official documentation, checked on 19 November 2026. Products change: if a step differs, the source has the current version.

Get the next lesson

New Academy lessons are announced in the weekly AI-Powered email.