1 / 11
Learn the Model Context Protocol end to end and build real MCP servers and clients: hosts, clients, and servers, tools, resources, prompts, elicitation, sampling, and roots, JSON-RPC messages, stdio and Streamable HTTP, the Python SDK, a TypeScript server, testing and debugging, multiple servers…
Build, Test, Secure, and Ship MCP Servers and Clients with Python and TypeScript
Read before you buy: the PDF here is a free sample — the first 20 pages of the 452-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
Give AI assistants safe, well-designed access to your systems — the standard way.
Every useful AI assistant eventually needs to reach outside its own conversation: look up stock, open a ticket, read a policy, book an appointment. The Model Context Protocol (MCP) is the open standard for exactly that. Build a server once, and any MCP-capable host can use its tools, resources, and prompts. Build a client once, and it can talk to any MCP server.
This book teaches MCP the way you will actually use it. You build one realistic system step by step, read the real JSON-RPC messages that cross the wire, and learn why the protocol works the way it does — so you can design your own servers, keep them secure, and keep up as the specification evolves.
What's inside
- The MCP architecture: hosts, clients, and servers, and why MCP replaces one-off integrations
- The building blocks: tools, resources, resource templates, prompts, completions, and the client features elicitation, sampling, and roots
- Under the hood: JSON-RPC requests, responses, notifications, and errors, the protocol lifecycle, and real captured messages
- Transports: stdio for local servers and Streamable HTTP for remote ones, with sessions, headers, and SSE explained
- Servers with the Python SDK: tool schemas from type hints, structured output, annotations, error handling, progress, lifespan, and change notifications
- Clients: connecting over stdio and HTTP, handling results and errors, timeouts and caching, and driving a model's tool-use loop from a host
- Asking the user for confirmation with elicitation, and borrowing the client's model and workspace with sampling and roots
- Protocol versions: the handshake-era revisions and the 2026-07-28 revision, and how to build servers and clients that work with both
- A TypeScript server that mirrors the Python design, tested from a Python client
- Testing with in-memory clients and pytest in both protocol eras, contract tests, wire logs, and the MCP Inspector
- Many servers at once: session groups, namespacing, and gateways
- Security: OAuth-based authorization, bearer tokens, scopes, protected resource metadata, prompt injection through tools, tool poisoning, confused deputies, least privilege, and confirmation patterns
- Production: packaging, deployment and scaling, stateless operation, logging, OpenTelemetry tracing, and metrics
One running example, start to finish. You build the MCP servers for Tidewater Bike Co., a fictional bike shop with an inventory of parts, repair tickets, service quotes, and two service bays to book. It starts as a single read-only tool over stdio and grows into a complete platform: ten tools, five resources, and three prompts served over stdio and HTTP, a confirmation flow for cancellations, a sampling and roots assistant server, a TypeScript mirror, bearer-token protection, tests in both protocol eras, and request logging and traces. The sample data is small enough to check by hand.
Current and honest. The book follows the 2026-07-28 specification revision and teaches the handshake-era revisions that many hosts still use, and it says clearly which details belong to which. The Python code was run against the Python SDK 2.x, and the messages shown were captured from the book's own sample code. Anything that could not be run — specific host applications, the MCP Inspector, cloud deployments — is labeled as illustrative. There are no invented benchmarks or statistics, and no particular AI model or vendor is assumed. Every chapter includes runnable code, Tips, Notes, Warnings, exercises, and Key Takeaways, and the appendices give you a cheat sheet, templates and reference tables, a production checklist, and a glossary.
Format: PDF, 452 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. Requires basic Python knowledge; one chapter uses TypeScript. This book is independent and is not affiliated with, sponsored by, or endorsed by the maintainers of the Model Context Protocol or by any AI company.
Table of Contents
Part I — Foundations
- Ch 1 · What MCP Is and Why It Exists: Hosts, Clients, and Servers
- Ch 2 · The Building Blocks: Tools, Resources, Prompts, and Client Features
- Ch 3 · Under the Hood: JSON-RPC Messages and the Protocol Lifecycle
- Ch 4 · Transports: stdio and Streamable HTTP
- Ch 5 · Setting Up: Python, the MCP SDK, and the Tidewater Project
Part II — Building Servers in Python
- Ch 6 · Your First Server: tidewater-shop over stdio
- Ch 7 · Designing Tools: Schemas, Structured Output, Annotations, and Errors
- Ch 8 · Resources and Resource Templates
- Ch 9 · Prompts and Completions
- Ch 10 · Context, Progress, Lifespan, and Change Notifications
Part III — Clients and Interaction
- Ch 11 · Writing an MCP Client in Python
- Ch 12 · Connecting Servers to Hosts and Models: Configuration and the Tool-Use Loop
- Ch 13 · Elicitation: Asking the User for Input and Confirmation
- Ch 14 · Sampling and Roots: Borrowing the Client's Model and Workspace
- Ch 15 · Protocol Versions and Compatibility: The Handshake Era and the 2026-07-28 Revision
Part IV — HTTP, TypeScript, and Testing
- Ch 16 · Streamable HTTP Servers in Python
- Ch 17 · Building a Server with the TypeScript SDK
- Ch 18 · Testing MCP Servers: In-Memory Clients, pytest, and Contract Tests
- Ch 19 · Debugging: Wire Logs, the MCP Inspector, and Common Failures
- Ch 20 · Working with Many Servers: Session Groups, Namespacing, and Gateways
Part V — Security and Authorization
- Ch 21 · Authorization Concepts: OAuth 2.1 for MCP
- Ch 22 · Protecting tidewater-shop: Bearer Tokens, Scopes, and Protected Resource Metadata
- Ch 23 · Threats: Prompt Injection Through Tools, Tool Poisoning, and Confused Deputies
- Ch 24 · Safe Tool Design: Least Privilege, Confirmation, and Guardrails
Part VI — Production
- Ch 25 · Packaging and Distributing MCP Servers
- Ch 26 · Deploying Remote Servers: Hosting, Scaling, and Statelessness
- Ch 27 · Observability: Logging, Tracing, and Metrics
- Ch 28 · Case Study: The Complete Tidewater MCP Platform
Appendices
A · MCP Cheat Sheet
B · Templates and Reference
C · Production Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 452 |
| Format | PDF (A4) |
| Language | English |
| Level | Beginner to Intermediate |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
Files you get
No reviews yet. Only buyers can review.
More from thenexbooks