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

19.1 MCP (Model Context Protocol)

MCP decouples an agent host from the implementation of its tools and data sources. The host selects servers, manages permissions, and passes results to the model. Each MCP client communicates with a server that advertises capabilities, executes requests, and returns results.

MCP architecture

CapabilityClient operationsExample
Toolstools/list, tools/callCalculate a result or look up an authorized order
Resourcesresources/list, resources/readRead a help document by URI
Promptsprompts/list, prompts/getRetrieve a parameterized support-ticket summary template

The host can pass tool descriptions and input schemas to the model. The model proposes a call, and the host checks its scope and arguments before execution and then returns the result as a tool message. Applications should handle the returned content types explicitly and check whether the tool reported an error.

Protocol versions and transports

Handshake revisions through 2025-11-252026-07-28
Discovery and versioninitialize and notifications/initializedA client can use server/discover to learn versions and capabilities
Request contextNegotiated at initializationEvery request carries version and client capabilities in _meta
Streamable HTTPThe server can assign Mcp-Session-IdThe protocol has no session. Applications can use explicit handles for cross-request state
Long-running workExperimental Tasks in 2025-11-25Optional Tasks extension with tasks/get for polling and tasks/update for further input

Local tools often use stdio, and remote servers use Streamable HTTP. In the modern revision, clients can opt into change notifications through subscriptions/listen. Request-scoped progress can still travel on the response stream. The old HTTP+SSE transport and Roots, Sampling, and Logging are deprecated. Apply the remote authorization requirements and least privilege for the deployment, and check resource access in each tool.

If a modern tool needs more information, it can return an input request so the client can collect answers and continue the call. Use the Tasks extension for background work that needs polling or follow-up across requests. Check version and extension support across your SDK, host, and server. See the MCP 2026-07-28 changelog and Python SDK migration guide.

Next, run the tool discovery and invocation example in 19.5.