Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Model Context Protocol Book

A comprehensive guide for developers who want to understand, build, and deploy MCP servers and clients.

MCP is the open standard that connects AI applications to the tools and data they need. This book takes you from “what is MCP?” to “I’m running MCP servers in production.”


Who This Book Is For

  • Backend developers building tools and APIs that AI agents should be able to use
  • AI/ML engineers creating applications that need to interact with external systems
  • Full-stack developers integrating MCP into existing products
  • Technical leads evaluating MCP for their organization
  • Anyone curious about how the sausage gets made when Claude checks the weather

No prior MCP knowledge required. Familiarity with JSON, APIs, and at least one programming language (TypeScript or Python preferred) will help.


Table of Contents

Part I: Understanding MCP

ChapterTitleWhat You’ll Learn
01The Problem MCP SolvesWhy MCP exists, the N-times-M integration nightmare, and MCP’s “USB-C moment”
02ArchitectureHosts, clients, servers, trust boundaries, capability negotiation, and the three-layer cake
03The Wire ProtocolJSON-RPC 2.0, message types, method catalog, initialization handshake, error codes, pagination, cancellation

Part II: The Three Primitives

ChapterTitleWhat You’ll Learn
04ToolsTool definitions, schemas, annotations, discovery, invocation, result types, error handling, best practices
05ResourcesURIs, resource templates, subscriptions, binary data, audience annotations, resources vs. tools
06PromptsPrompt templates, arguments, multi-message prompts, embedded resources, practical patterns

Part III: Transport and Communication

ChapterTitleWhat You’ll Learn
07Transportsstdio, Streamable HTTP, legacy SSE, the proxy pattern, transport security, debugging transports

Part IV: Building Things

ChapterTitleWhat You’ll Learn
08Building Servers in TypeScriptMcpServer API, Zod schemas, weather server example, HTTP transport, publishing to npm
09Building Servers in PythonFastMCP, decorators, type hints, SQLite explorer example, uvx, publishing to PyPI
10Building ClientsTypeScript and Python clients, building a host, managing multiple servers, the full agentic loop

Part V: The Ecosystem

ChapterTitleWhat You’ll Learn
11The SDK LandscapeAll 10 official SDKs (TypeScript, Python, Go, C#, Java, Kotlin, Swift, Rust, Ruby, PHP), choosing an SDK
12ConfigurationSetting up MCP in Claude Desktop, Claude Code, VS Code, Cursor, and Windsurf

Part VI: Security and Advanced Topics

ChapterTitleWhat You’ll Learn
13Authentication and SecurityOAuth 2.1, trust boundaries, threat modeling, security best practices for servers and hosts
14Advanced FeaturesSampling, elicitation, roots, completion, logging, progress reporting

Part VII: Production and Beyond

ChapterTitleWhat You’ll Learn
15Testing and DebuggingMCP Inspector, manual testing, common problems, testing strategies, debugging tips
16Production PatternsDeployment models, Docker/K8s, serverless, gateways, multi-tenancy, monitoring, scaling
17The EcosystemOfficial servers, community servers, registries, discovery, evaluating and building for the ecosystem
18The Future of MCPStateless protocol, server cards, transport evolution, agent convergence, the road ahead

How to Read This Book

Linear path: Read chapters 1-18 in order for the complete journey from concepts to production.

Quick start: Read chapters 1-2 for the concepts, then jump to chapter 8 (TypeScript) or 9 (Python) to start building.

Reference: Each chapter is self-contained. Jump to whatever topic you need.

Architecture deep-dive: Chapters 2, 3, 7, and 13 cover the protocol in detail.

Practical guide: Chapters 8, 9, 10, 12, and 15 are hands-on with code and configuration.


About the Protocol

The Model Context Protocol was created by Anthropic and released as an open standard in November 2024. The specification is maintained at modelcontextprotocol.io and the source code is at github.com/modelcontextprotocol.

The current specification revision at time of writing is 2025-11-25.


Contributing

Found an error? Have a suggestion? Open an issue or pull request.


License

This book is available under the license specified in the LICENSE file.