Cover of Model Context Protocol in Practice, edition 2026.11.5, code MA29-KPNM Model Context Protocol in Practice MA29-KPNM 5 editions since Nov 2026 Rolling Edition 2026.11.5

Model Context Protocol in Practice

Edition 2026.11.5 Examples passed Nov 4, 2026 70 of 70 examples pass What changed

Written with AI. Verified by people. How we make books

Anyone can check this book or correct it. Report an error · How to fix one

Tools and data for agents, for engineers who know APIs: what MCP adds to an HTTP API and when it's the wrong choice, and how to design, build, secure, test and run MCP servers and clients on specification revision 2026-07-28 with the Python SDK, mcp 2.x, with a migration path from the 2025 revisions.

Who it's for For engineers who build or call HTTP APIs and now need to give agents tools and data, or connect an agent to someone else's. No machine learning background needed.

Start reading

Labs

Work through this book in the Lab

Run every example exactly as the book did, change the code to see what happens, and try your own ideas on the book's code and data. Nothing to install, and your work is saved. Opens in about 30 seconds.

Run every example exactly as the book did, change the code to see what happens, and try your own ideas on the book's code and data. Nothing to install, and your work is saved. Included with membership: 20 hours a month with Member, or 60 with Member Plus.

Edition history5 editions since November 2026Every edition and what it changed
2026.11.12026.11.5
2026.11.5 · Nov 4, 2026Library updateNo text changed, 69 examples on new versions

Contents

12 chapters, about 5 hours 25 minutes to read or 7 hours 32 minutes to listen to, with 70 examples.

  1. 1MCP end to end

    By the end of this chapter you can put an existing HTTP API behind a Model Context Protocol server over stdio, call its tool from a client, read every message the two exchange, and let a model choose the tool through a small host.

  2. 2What MCP adds to an API

    By the end of this chapter you can say what the host, the client and the server each do, put each of the shop's capabilities in the right Model Context Protocol primitive, read the version and capabilities that every request carries, and decide when the shop should keep a plain HTTP API instead.

  3. 3Design tools a model can use

    By the end of this chapter you can turn the shop's API into a small set of Model Context Protocol tools whose names, descriptions, input schemas, results and errors a model can act on, and measure how a change to a description changes which tool a model picks.

  4. 4Serve data as resources and prompts

    By the end of this chapter you can publish the shop's policies and records as Model Context Protocol resources, address many records with one resource template, complete an argument while a user types it, tell a client when a resource changes, and package a refund review as a prompt the user can pick.

  5. 5Ask the user in the middle of a call

    By the end of this chapter you can make the shop's refund tool stop in the middle of a call and ask the person at the host to confirm a refund, with Model Context Protocol elicitation inside a Multi Round-Trip Request, on a server that keeps no call open while it waits for the answer.

  6. 6Serve over Streamable HTTP

    By the end of this chapter you can serve the shop's Model Context Protocol server over Streamable HTTP, read what each request and response carries, stream progress from a long call and cancel it, run the server as replicas behind one address with no sticky sessions, and refuse requests that a browser was tricked into sending.

  7. 7Run long work as tasks

    By the end of this chapter you can negotiate a Model Context Protocol extension, run the shop's slow restock report as a task that the client polls, let tasks expire and cancel them, and say what MCP Apps add to a tool.

  8. 8Authorize clients with OAuth

    By the end of this chapter you can protect the shop's Model Context Protocol server with OAuth.

  9. 9Secure tools against misuse

    By the end of this chapter you can draw the trust boundaries around a Model Context Protocol server and its host, refuse token passthrough, keep a server from acting as a confused deputy, pin tool definitions so a changed one is caught, treat ticket text as data, and ask the user before any tool call with side effects.

  10. 10Build a host that works through tickets

    By the end of this chapter you can connect a host to several Model Context Protocol servers, give their tools names that can't collide, run a short loop in which a model calls tools and reads their results, answer a server's input requests on the user's behalf, put resources into the model's context, and work a queue of tickets through all of it.

  11. 11Test a server and watch it run

    By the end of this chapter you can test a Model Context Protocol server's tools in memory and over HTTP, catch a schema change that would break clients before it ships, replay a recorded host run as a regression test, trace tool calls with OpenTelemetry, measure how often a model chooses the right tool, and retire a tool without breaking the clients that use it.

  12. 12Migrate a 2025-era server

    By the end of this chapter you can move a Model Context Protocol server written for the 2025 revisions and the Python SDK's 1.x line to the specification at revision 2026-07-28 and mcp 2.3.0: find what it depends on, remove its sessions, move it off the HTTP+SSE transport, replace sampling, roots, logging and Dynamic Client Registration, port the code, and serve clients of both eras while the old ones are still around.

Cite this section

Format

Every format names this edition. Its link opens the current edition, where a section’s heading says when its text last changed. Accessed and retrieved dates are the day you open this.