Skip to content

MCP Security Guide for Developers

The web edition

This guide lives in its GitHub repository, which also holds the setup script, the skills and the example server. This copy matches release v0.9.

How to build a Model Context Protocol (MCP) server that won't become someone's case study, from the decision to build one to the day you switch it off. Written for developers who do much of the work with a coding agent.

As of 14 November 2026. Follows the MCP specification of 2026-07-28. Read the disclaimer.

In a hurry? Start with the developer quick start: one command (mcp-guide init) adds the rules, skills and agent guardrails to your repository, then one-line prompts for your coding agent; mcp-guide audit vets someone else's server, and runs nothing risky unless you accept that risk by name.

Why a server needs more than ordinary app security

An MCP server is two things at once:

  • Software, which can have ordinary bugs: command injection, missing authentication, leaked tokens.
  • Text the model reads. Tool names, descriptions and results all land in the model's context, and the model may obey them.

Most real incidents so far needed both views to explain. This guide uses one model throughout, Feed, Behaviour, Impact: what the server makes the model read, what it lets the model do, and what it can reach. See the model.

The lifecycle

Each page says what to decide or do, what has gone wrong in real cases, the controls, what to watch for if a coding agent is doing the work, and a checklist.

# Phase The question it answers
0 Decide Should this be a server at all, and what kind?
1 Threat model What does it feed the model, let it do, and reach?
2 Design Whose identity, which scopes, which tools?
3 Build How do I write it without the classic bugs?
4 Test How do I know the controls work?
5 Release How do I publish it so nobody can impersonate it?
6 Deploy and operate Where does it run, and how will I notice trouble?
7 Change What changes need clients to approve again?
8 Incident and retire What do I do on a bad day, and at the end?

Plus using a coding agent safely: the agent itself is part of your attack surface.

Using this guide with a coding agent

The quick start has the commands and prompts. In short:

  1. Run mcp-guide init (the setup script) in your repository. It adds AGENTS.md (the guide's rules as short instructions an agent can follow) and the skills: threat modelling, security review of a change, a pre-release check, and an audit for third-party servers (with an optional Docker sandbox).
  2. Ask the agent for a threat model before any code. It interviews you, drafts it from your answers and the code, and saves it when you approve. You don't fill in a template.
  3. Keep the decisions marked human-owned for a person: the identity model, scopes, token validation, anything that changes what a tool says or does, and publishing. init adds permission rules so Claude Code has to ask you at those points, mcp-guide protect adds code owners for the security files, and mcp-guide snapshot check fails the build when a tool's definition changes (how the layers fit).

Vetting someone else's server

Most people install MCP servers rather than build them. Before you install or approve one, run mcp-guide audit (or the mcp-server-audit skill) on the exact version: it checks the publisher, scans the code and tool descriptions, checks a remote server's sign-in, and can run the server in a locked-down Docker sandbox with fake credentials to see what it really does.

Reference

Example server

examples/ask-trevor/ is a small, read-only search server written in TypeScript on the official SDK. It shows the build rules in working code, with 50 tests covering authorisation, tenant isolation, hostile content, transport checks and tool-definition changes. It is a teaching example, not a product, and its test token issuer is never for production.

Videos

This guide accompanies the video series MCP Security: Zero to Hero on YouTube.

For the agents your staff run, see the free AI Agent Check.

Contributing

Corrections are especially welcome. Every claim should trace to a source in sources. See CONTRIBUTING; report a security problem in the example server through SECURITY.

Disclaimer

This guide is general information, not professional advice. It is accurate to the best of our knowledge on the date above, but specifications, products and attacks change quickly, and following it does not guarantee that a server is secure. You are responsible for the security of what you build and deploy. Check the linked sources before relying on any detail.

Licence

Text: CC BY 4.0. Code, AGENTS.md, CLAUDE.md and skills: MIT.