MCP roles and lifecycle
What MCP connects
Model Context Protocol (MCP) specifies a common way for an AI application to exchange context and invoke capabilities exposed by another program. The host is the application that owns the user experience, model access and permission decisions. A client inside the host communicates with a particular server; a server exposes a defined set of capabilities. For example, a fictional warehouse host can ask an inventory server for a stock count without knowing how the inventory is stored. MCP is not an agent framework: it does not decide what the user wants, plan a task, or grant access automatically. The prerequisite is tool calling and bounded execution from Chapter 42.
Choose a compatible protocol revision
Pin the teaching examples to 2026-07-28, published July 28, 2026. With that revision the request carries protocol version and client capabilities in params._meta; there is no initialization handshake. Servers implement server/discover, which clients may use to learn supported versions and server capabilities. If a requested version is unsupported, the server returns an unsupported-version error with supported versions. The older 2025-11-25 lifecycle uses initialize, a version and capability exchange, then notifications/initialized. Do not send modern methods to legacy servers without selecting the correct era. The next example models only trusted preference selection after discovery or an error; it is not a transport or handshake implementation.
Version selection with a trusted preference list
The first supported revision in the client preference list wins; None means no overlap. The three results are 2025-11-25, None, and 2026-07-28. In a real client, selecting a legacy revision also requires the legacy lifecycle; an unrecognized version must never silently turn off authorization.
def select_revision(client_versions, server_versions): # Preference comes from the trusted client configuration. return next((v for v in client_versions if v in server_versions), None)
print(select_revision(["2026-07-28", "2025-11-25"], ["2025-11-25"]))print(select_revision(["2026-07-28"], ["2025-11-25"]))print(select_revision(["2026-07-28", "2025-11-25"], ["2025-11-25", "2026-07-28"]))Tools, resources and prompts
Tools expose named operations, discovered via tools/list and requested via tools/call. A resource exposes data through a URI, for example a fictional inventory snapshot, discovered and read through resources/list and resources/read. A prompt is a server-authored reusable message template that a user can select, discovered via prompts/list and retrieved via prompts/get. Capabilities indicate supported feature families, not permission to access every item. Empty objects can advertise a feature. The next example builds a modern request as a Python dictionary and lists the methods this local client would consider. The output shows that prompts are absent and that _meta remains in params. It neither sends the request nor discovers a real server.
import json
VERSION = "2026-07-28"
def request(request_id, method, arguments): if type(request_id) not in (int, str) or "_meta" in arguments: raise ValueError("Invalid fixture request") return {"jsonrpc": "2.0", "id": request_id, "method": method, "params": {**arguments, "_meta": { "io.modelcontextprotocol/protocolVersion": VERSION, "io.modelcontextprotocol/clientCapabilities": {}}}}
def available_methods(capabilities): methods = ["server/discover"] for feature, operations in [("tools", ["tools/list", "tools/call"]), ("resources", ["resources/list", "resources/read"]), ("prompts", ["prompts/list", "prompts/get"])]: if isinstance(capabilities.get(feature), dict): methods.extend(operations) return methods
print(available_methods({"tools": {}, "resources": {}}))print(json.dumps(request(7, "tools/call", {"name": "lookup", "arguments": {"item": "A"}}), sort_keys=True))Transport and lifecycle boundaries
Standard transports include stdio (newline-delimited JSON-RPC over a local process’s streams) and Streamable HTTP (POST requests with JSON or request-scoped SSE replies). The modern HTTP binding mirrors selected metadata into headers, including MCP-Protocol-Version and Mcp-Method; the body remains the source of truth. Use the matching SDK and exact revision, validate transport-specific headers, use TLS for remote deployments, and bound waiting time. The modern core is stateless, but servers may store application data and explicit handles. Never treat a new request as implicitly authorized by a previous request. The selected revision also supports multi-round-trip input requests; this small fixture intentionally does not implement them. Practice: advertise prompts but not resources, then explain which methods are candidates and why the list is not an access token. Official reading: versioning and transports, plus server tools/resources/prompts pages in source-evidence.json.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
MCP roles and lifecycle quiz
Check protocol reasoning and the local fixture contract.
Which component owns the user interface and access decisions?
Which lifecycle applies to revision 2026-07-28?
What does a tools capability advertise?
Which operation retrieves a resource by URI?
What should a client do if it supports none of the server’s protocol revisions?