
Discovery and the request lifecycle
Discovery and the request lifecycle
Where you are: Module 1, lesson 6. You have seen requests and results (L04, L05). Now you look at how a client and server agree on a protocol version and capabilities, per request, and how to interoperate with servers and clients that still use the legacy handshake.
What changed in V2: the earlier lesson taught the initialize handshake and a three-phase lifecycle as current. Revision 2026-07-28 removed the handshake; here it is the legacy mechanism (2025-11-25 and earlier) you fall back to.
What you will be able to do
- Build a valid 2026-07-28 request with the required
_metafields, and predict the error when one is missing. - Use
server/discoverand read its result, knowing that servers MUST implement it and clients MAY call it. - Recover from
UnsupportedProtocolVersionError(-32022) andMissingRequiredClientCapabilityError(-32021). - Detect a legacy server on stdio and on HTTP and fall back to
initializeonly when the rules say so.
The current model: every request stands alone
The base protocol says MCP "is a stateless protocol: all the information needed to process a request is contained in the request itself." Servers MUST NOT rely on earlier requests on the same connection to know the version, capabilities or client identity. An open stdio process is not a session.
So each client request carries these _meta keys:
| Key | Required | Meaning |
|---|---|---|
io.modelcontextprotocol/protocolVersion | Yes | Version for this request, for example "2026-07-28" |
io.modelcontextprotocol/clientCapabilities | Yes | Capabilities relevant to this request ({} if none) |
io.modelcontextprotocol/clientInfo | No (clients SHOULD send it) | Client name and version |
io.modelcontextprotocol/logLevel | No | Per-request log level (part of deprecated Logging) |
A request missing a required key is malformed: the server MUST reply -32602 (Invalid params), HTTP 400 on Streamable HTTP. Servers SHOULD put io.modelcontextprotocol/serverInfo in every result's _meta. clientInfo and serverInfo are self-reported; never base security decisions on them.
server/discover
Servers MUST implement server/discover. Clients MAY call it to learn supported versions, capabilities and identity in one round trip, but are not required to: "a client is free to invoke any RPC inline and handle UnsupportedProtocolVersionError".
Captured from the lab-l08 notes server over stdio (official Python SDK mcp 2.3.0):
{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{
"io.modelcontextprotocol/protocolVersion":"2026-07-28",
"io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":1,"result":{
"resultType":"complete",
"supportedVersions":["2026-07-28"],
"capabilities":{"prompts":{"listChanged":true},"resources":{"listChanged":true,"subscribe":true},"tools":{"listChanged":true}},
"instructions":"A DEMO notes store with synthetic data. add_note changes state; get_note is read-only.",
"ttlMs":0,"cacheScope":"private",
"_meta":{"io.modelcontextprotocol/serverInfo":{"name":"demo-notes","version":"1.0.0"}}}}
supportedVersions lists the modern versions accepted per request. The same server also answers legacy initialize (below); that era is not listed here.
Errors that drive the lifecycle
Unsupported version. If the server does not implement the requested version it MUST return -32022 with the versions it supports. The client SHOULD retry with a common version or surface an error. Captured from the same server:
{"jsonrpc":"2.0","id":1,"error":{"code":-32022,"message":"Unsupported protocol version",
"data":{"supported":["2026-07-28"],"requested":"2099-01-01"}}}
Missing capability. A server MUST NOT rely on capabilities the client has not declared. If a request needs one, it MUST return -32021 with data.requiredCapabilities (HTTP 400). In L05 the elicitation server returned {"code":-32021, ..., "data":{"requiredCapabilities":{"elicitation":{"form":{}}}}} to a client that declared {}.
HTTP only: a mismatch between headers and body is -32020 (HeaderMismatch), and an unknown method is HTTP 404 with JSON-RPC -32601. L07 covers the headers.
What "lifecycle" means now
There is no initialise, operate, shut down sequence at the protocol level. What remains:
- Per request: the client sends a request with
_meta; the server returns a result (resultType"complete"or"input_required") or an error. Long operations may stream request-scoped notifications such asnotifications/progressbefore the final response. - Cancellation: on stdio the client sends
notifications/cancelledwith therequestId; on Streamable HTTP closing the response stream is the cancellation. Senders SHOULD set timeouts on every request. - Change notifications: the client opens a
subscriptions/listenrequest and receives opted-in notifications (for examplenotifications/tools/list_changed) on that stream, each tagged withio.modelcontextprotocol/subscriptionId. - End: stdio follows the subprocess (L07); on HTTP each request ends with its response.
- Removed in 2026-07-28:
ping,logging/setLevel,notifications/initialized,notifications/roots/list_changed.
Legacy: the initialize handshake (2025-11-25 and earlier)
Legacy clients open a session: initialize (with protocolVersion, capabilities, clientInfo), the server's result (with its chosen protocolVersion, capabilities, serverInfo), then the client's notifications/initialized. Only then do normal requests flow, and they carry no _meta version. Captured from the same lab-l08 server, started fresh:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25",
"capabilities":{},"clientInfo":{"name":"x","version":"0"}}}
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-11-25",
"capabilities":{"prompts":{"listChanged":false},"resources":{"listChanged":false,"subscribe":false},"tools":{"listChanged":false}},
"instructions":"A DEMO notes store ...","serverInfo":{"name":"demo-notes","version":"1.0.0"}}}
There is no resultType; clients MUST treat its absence as "complete". This server is dual-era (an SDK compatibility layer, which the spec allows) and picks the era from how the client opens. On stdio the era is fixed per process: after a modern request, the SDK rejected a later initialize with -32022.
Fallback rules (current spec, Versioning and Compatibility)
- stdio: a dual-era client SHOULD send
server/discoverfirst with its preferred modern version. ADiscoverResultmeans modern. A recognised modern error such as-32022means modern with another version: do not fall back. Any other error, or no reply within a timeout, means legacy: fall back toinitialize. The fallback MUST NOT be keyed to one specific error code. - Streamable HTTP: send a modern request. On
400, inspect the body: a recognised modern error means modern (fix the request or version); an empty or unrecognised body means legacy, so fall back toinitialize, and possibly further to the deprecated HTTP+SSE transport. - Cache the era per server process (stdio) or origin (HTTP).
- A modern-only server SHOULD name its supported versions in any error it returns to
initialize, because legacy clients cannot move forward on their own.
Hosts differ today. Claude Code negotiates 2026-07-28 (force the handshake with MCP_PROTOCOL_NEGOTIATION=legacy); Cursor's client spoke 2025-11-25 and earlier per a staff post on 2026-09-21; other hosts are unknown. A modern-only server fails with every legacy host.
Practice task
In lab-l08, probe the server the way a dual-era client would. Create probe.jsonl with one line each:
{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2099-01-01","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":2,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":3,"method":"tools/list","params":{}}
Run (cat probe.jsonl; sleep 3) | ./run.sh serve 2>/dev/null.
Then run a fresh process with a legacy opening, legacy.jsonl:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"probe","version":"0"}}}
Run (cat legacy.jsonl; sleep 3) | ./run.sh serve 2>/dev/null.
Check your result: id 1 returns error -32022 listing "supported":["2026-07-28"] (a modern server, so a client would retry, not fall back); id 2 returns a DiscoverResult with supportedVersions and serverInfo demo-notes; id 3, which has no _meta, returns error -32602; and the fresh process answers initialize with "protocolVersion":"2025-11-25" and no resultType.
Check your understanding
-
A client skips
server/discoverand sendstools/callstraight away. Is it compliant? Yes. Servers MUST implementserver/discover; clients MAY skip it and handle-32022by retrying with asupportedversion. On stdio a dual-era client SHOULD still probe first, because some legacy servers would runtools/callunder legacy rules instead of failing. -
Over stdio your probe gets
-32601 Method not found. Fall back toinitialize? Yes:-32601is not a recognised modern error, so the server is treated as legacy. If the reply had been-32022you would stay modern and retry with a supported version. -
Your server caches the client's capabilities from its first request and reuses them later in the same stdio process. What is wrong? Servers MUST NOT rely on prior requests to establish capabilities, version or identity. Each request declares its own, and a client may interleave unrelated requests on one process. Read capabilities from the current request's
_metaevery time.
Sources
- Versioning and Compatibility: https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning
- Discovery: https://modelcontextprotocol.io/specification/2026-07-28/server/discover
- Base protocol (statelessness,
_meta, error codes): https://modelcontextprotocol.io/specification/2026-07-28/basic - stdio transport (backward compatibility, shutdown, cancellation): https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio
- Cancellation: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation
- Changelog 2026-07-28: https://modelcontextprotocol.io/specification/2026-07-28/changelog
- Claude Code MCP docs (client runtimes): https://code.claude.com/docs/en/mcp
