Build your own MCP server
Last reviewed October 23, 2026
An MCP server is a small program that hands an AI agent something it cannot reach on its own: your API, your database, a running application. It speaks the Model Context Protocol, so you write it once and every client that speaks MCP can use it. Today that means Claude Code, Codex, Cursor, VS Code, Claude Desktop, Gemini CLI and a long tail of others.
The server offers three kinds of thing. Tools are functions the model decides to call. Resources are data the application chooses to pass in as context. Prompts are templates a person picks, often as a slash command. Most servers start with a tool or two and never need the rest.
Do you need a server, or a skill?
A skill is instructions and scripts that the agent reads and runs with the tools it already has. If the agent only needs to know how to do something, write a skill (build your own skill). It is smaller, and people find it easier to trust.
Build a server when the agent needs access: an API with its own login, a database, live data that has to stay behind your own permission checks. And if you want to ship a server together with skills and hooks for one agent, that package is a plugin (build your own plugin or marketplace).
Read this before you copy a tutorial
MCP changed underneath most of the tutorials written about it. Specification 2026-07-28 made the protocol stateless: no initialize handshake, no session header. The TypeScript SDK moved to new packages (@modelcontextprotocol/server replaces @modelcontextprotocol/sdk), and the Python SDK renamed FastMCP to MCPServer with no fallback. A tutorial from before July 2026 will mislead you in places that matter. Every example in this guide ran against the current versions on October 23, 2026 (specification changelog).
The five steps
- 1. Build an MCP server
The specification, the SDKs, the two transports, and a complete minimal server in TypeScript and in Python.
- 2. Test an MCP server
Try it in the MCP Inspector, add it to Claude Code or Codex, read its logs, and fix the usual failures.
- 3. Publish an MCP server
Publish the package, list it in the MCP Registry, and give each client its install snippet.
- 4. Secure an MCP server
Authorization for remote servers, secrets, least privilege, and prompt injection through tool output.
- 5. MCP server checklist
Findable, trustworthy, maintainable: what to check before you tell anyone about it.