Skip to content
Index Ai Academy
Phase 9 · Protocol foundations

Versions and stateless requests

Revisions by date, the legacy handshake, per-request _meta and version negotiation.

About 30 minutes · Versions and API rules checked November 2026 · A free account opens the whole lesson.
Already have an account? Sign in to open this lesson

What it covers9

First principles

How can different server processes handle later calls in the same workflow?

A self-describing request carries enough protocol context to be interpreted independently. Durable workflow state can travel through an explicit handle, so processing does not depend on returning to the same worker.

  1. Starting point

    First request declares its protocol version

  2. What changes

    Server returns a handle for continuing the work

  3. Result

    Later request declares its version and carries that handle

Compare all three steps
  1. Starting point

    First request declares its protocol version

  2. What changes

    Server returns a handle for continuing the work

  3. Result

    Later request declares its version and carries that handle

Complete and reverse the trace

Given First request declares its protocol version and Later request declares its version and carries that handle, write down the missing step that connects them.

Compare with the worked step

Server returns a handle for continuing the work

Now take Server returns a handle for continuing the work and the result above. Write an input and an implementation that could produce this trace.

Check one starting point

First request declares its protocol version. Check that your implementation produces the result shown above.

Try it on a new case

The load balancer sends a follow-up to a worker that never saw the first request. What information lets it continue?

Show worked reasoning

It needs the request's protocol context and the work handle. The worker can use the handle to recover the shared durable state.

Run, change, and build

Check this when debugging. Thinking every MCP server still needs initialize first (modern ones don't, legacy ones do).

Trace the cause · MCP message and permission
  1. Mark which message crosses the client–server boundary and which check determines what the caller may do.
  2. Change the tool input or approved scope. Compare the returned message and stored state to distinguish a denial from an allowed change.
  3. Try the same reasoning on this case. The load balancer sends a follow-up to a worker that never saw the first request. What information lets it continue?

Why it matters

A protocol used by thousands of apps can't change all at once. MCP names each revision by date and lets clients and servers agree on one. In 2026 it also made a big design change: it dropped the opening handshake, so every request now stands on its own. That makes servers far easier to scale, but much existing software still speaks the older style. This lesson covers the versions, the old handshake, the new per-request metadata, and how a client settles on a version. Discovery and the two eras covers how a server describes itself, and how the two eras live side by side.

What you'll be able to do

  • Explain how MCP changed from a handshake protocol to a stateless one in the 2026-07-28 revision
  • Write requests with the per-request _meta fields: protocol version, client capabilities and identity
  • Handle version negotiation with UnsupportedProtocolVersion and pick a version both sides speak
  • Keep state across calls with an explicit handle instead of a session
Quick check
MCP names its versions by date, like 2025-06-18. Why do a client and a server need to agree on one?
  1. The date decides which AI model the server will use
  2. Dates make the protocol's messages load and parse faster
  3. Each revision can change messages, so both must speak the same one
  4. Older versions stop working on the day after release
Show the answer

Each revision can change messages, so both must speak the same one

A protocol used by thousands of apps can't change everywhere at once. Each side says which revisions it speaks, and they use one both know, so old and new apps can still talk.

The idea: a handshake against a self-describing request

This rests on JSON-RPC 2.0 in depth: every message is a request, a reply or a notification, and a reply carries its request's id. The question here is what else a message must say about itself.

Revisions by date

MCP versions are dates, like the editions of an atlas: 2024-11-05 (the first public release), 2025-03-26, 2025-06-18, 2025-11-25 and 2026-07-28. A date sorts naturally and says when it was published. There's no guessing whether version 3 came before version 2.1. The spec calls everything up to 2025-11-25 legacy, and 2026-07-28 onward modern.

The legacy way: a handshake

Think of a phone call. You say hello, agree on a language, and from then on you both remember what was said.

In legacy MCP, a client opens a connection and first sends initialize with its preferred version, its capabilities and its name. The server answers with the version it chose and its own capabilities. The client then sends a notifications/initialized notification, and only then do normal requests begin.

Everything agreed in the handshake is state, which means information remembered between messages. It lasts for the life of the connection, or of a session identified by an Mcp-Session-Id header over HTTP. That's the flow you used in Phase 1, and the academy's practice server still answers it.

Quick check
From the lesson on JSON-RPC: a request has an id and a method, a notification has a method and no id, and a reply has a result or an error. What does this print?
def kind(msg):
    if "method" in msg:
        return "request" if "id" in msg else "notification"
    return "error" if "error" in msg else "result"

messages = [{"id": 1, "method": "tools/list"}, {"method": "notifications/progress"},
            {"id": 1, "result": {}}, {"id": None, "error": {"code": -32700}}]
print([kind(m) for m in messages])
  1. ['request', 'request', 'result', 'error']
  2. ['request', 'notification', 'result', 'result']
  3. ['request', 'notification', 'result', 'error']
  4. ['notification', 'request', 'result', 'error']
Show the answer

['request', 'notification', 'result', 'error']

The four shapes are told apart by which keys are present. The last one is a parse error: the server couldn't read the message, so it can't know the id and sends null. In the modern revisions of MCP, each request also carries its own protocol version, which is this lesson's subject.

Try it now

Three messages before any real work, and every later message relies on them. That memory is the state the next section is about.

What state costs

State has costs. Picture a bank where only one teller holds your file. Every time you come in, you have to wait for that one teller, even when nine others are free.

A busy server runs on several machines behind a load balancer, a machine that shares requests out. If sessions live in memory, every request in a session must reach the machine that holds that session's state. Load balancers can do that, with sticky sessions, but it's extra work and it spreads the load unevenly. If that machine restarts, the session is lost and the client has to start over. Change notifications needed a long-lived stream tied to the session, too.

In plain words: a handshake makes the server remember you, and remembering is expensive once there's more than one server.

Quick check
A legacy MCP session was set up on machine 3 of ten. What must the load balancer do with the rest of that session's requests?
  1. Send each one to the least busy machine
  2. Send them all to machine 3
  3. Send them to all ten machines at once
Show the answer

Send them all to machine 3

The handshake's results live on machine 3, so the others wouldn't know the session. That's what sticky sessions means, and if machine 3 restarts, the session is gone.

The modern way: every request stands alone

A letter is different from a phone call. It has to say everything the reader needs, because the reader remembers nothing. The 2026-07-28 revision made MCP stateless, the word for keeping nothing between messages. There's no handshake. Instead, every request carries what the server needs in params._meta:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list",
  "params": {
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientCapabilities": {},
      "io.modelcontextprotocol/clientInfo": {"name": "shop-assistant",
                                             "version": "0.3.0"}
    }
  }
}
  • protocolVersion (required): the revision this request uses.
  • clientCapabilities (required): the optional features this client supports, such as elicitation. An empty object means "only the basics".
  • clientInfo (recommended): the client's name and version, for logs and display only.

The long names start with io.modelcontextprotocol/. That prefix marks them as the protocol's own, so other tools can add their own keys to _meta without clashing. Two of those fields are required in every modern request: io.modelcontextprotocol/protocolVersion and io.modelcontextprotocol/clientCapabilities. A request missing either is malformed. The server answers with error -32602 (Invalid params), and HTTP 400 over HTTP.

Results answer in kind. Each has resultType ("complete" for ordinary results), and a _meta holding io.modelcontextprotocol/serverInfo, the server's own name and version.

In plain words: the server no longer has to remember you, because each request introduces itself.

Quick check
In the modern revisions, each request carries its protocol version in its own _meta. What does this print for a request that has it, and one that doesn't?
KEY = "io.modelcontextprotocol/protocolVersion"

def version_of(request):
    return request.get("params", {}).get("_meta", {}).get(KEY)

with_meta = {"id": 1, "method": "tools/list", "params": {"_meta": {KEY: "2026-07-28"}}}
print(version_of(with_meta), version_of({"id": 2, "method": "tools/list"}))
  1. None None
  2. 2026-07-28 2026-07-28
  3. tools/list None
  4. 2026-07-28 None
Show the answer

2026-07-28 None

The first request says which revision it speaks, so any machine can answer it without having seen an earlier message. The second leaves the field out. A server doesn't guess: a request with a required _meta field missing gets an Invalid params error, −32602.

Worked example

Two copies of a server

Popular servers run several copies behind a load balancer, and each request may land on a different one. See what that does to a server that keeps sessions in memory.

PV = "io.modelcontextprotocol/protocolVersion"

class LegacyServer:
    def __init__(self):
        self.sessions = {}
    def handle(self, session, method):
        if method == "initialize":
            self.sessions[session] = "2025-03-26"
            return "ok"
        if session not in self.sessions:
            return "error: unknown session"
        return f"{method} answered"

class ModernServer:
    def handle(self, meta, method):
        if PV not in meta:
            return "error: missing _meta"
        return f"{method} answered"

copies = [LegacyServer(), LegacyServer()]
print(copies[0].handle("s1", "initialize"))
print(copies[1].handle("s1", "tools/list"))   # the next request lands on the other copy

copies = [ModernServer(), ModernServer()]
meta = {PV: "2026-07-28"}
print(copies[0].handle(meta, "tools/list"))
print(copies[1].handle(meta, "tools/list"))
It runs right here in your browser, with nothing to install.

The legacy server fails as soon as a request reaches a copy that didn't see the handshake. Fixing that needs sticky routing or shared storage. A modern request carries everything needed, so any copy can answer it.

Quick check
In the 2026-07-28 revision, where does a server learn which protocol version a request uses?
  1. It guesses from the method name, since each version has its own set of methods
  2. From the Mcp-Session-Id header, which the server issued when the session began
  3. From the initialize handshake at the start of the connection, which fixes it for every request
  4. From params._meta["io.modelcontextprotocol/protocolVersion"] in that same request
Show the answer

From params._meta["io.modelcontextprotocol/protocolVersion"] in that same request

Modern MCP is stateless: each request carries its version and capabilities. Initialize and session ids belong to legacy revisions.

In your own words
Where does a modern server learn a request's protocol version?

Write a sentence or two, then compare it with a good answer in the lesson.

In Python: negotiating a version and keeping state

This part writes the client's side of the agreement and then the server's answer to the question "where do I put state now?".

Negotiating a version

There's no up-front agreement, so negotiation happens per request. Picture asking for something in French abroad, and the clerk answering "sorry, I speak English and German". You pick one of those and ask again.

If the server doesn't support the version a request names, it answers with UnsupportedProtocolVersion, error code -32022, and lists what it does support:

{"jsonrpc": "2.0", "id": 1, "error": {"code": -32022,
                                      "message": "Unsupported protocol version",
  "data": {"supported": ["2026-07-28", "2025-11-25"], "requested": "2027-01-15"}}}

The client picks a version both sides support, preferring the newest it knows, and retries. If there's none in common, it reports a clear error to the user, with both lists, instead of failing mysteriously. A client remembers the answer for that server, so it doesn't pay for the extra round trip on every call.

In plain words: ask in your newest language. If the server says no, pick the newest one you both speak.

Worked example

Choosing a version from the server's list

A client prefers the newest version it knows. Given the server's supported list from an error, pick the best version both sides speak.

CLIENT_VERSIONS = ["2026-07-28", "2025-11-25", "2025-06-18"]     # newest first

def choose_version(server_supported):
    for v in CLIENT_VERSIONS:
        if v in server_supported:
            return v
    return None

print(choose_version(["2025-11-25", "2025-06-18"]))
print(choose_version(["2026-07-28"]))
print(choose_version(["2024-11-05"]))
In the lesson you can change this and run it.

The client walks its own list from newest to oldest and takes the first one the server also lists. When there's nothing in common, it returns None, and a well-behaved client shows the user a clear message (with both lists) instead of failing mysteriously.

The same retry, against the practice server. The first request names a version the server doesn't speak, the error lists what it does, and the client retries with the best common version:

import requests

URL = "https://api.gradient.test/mcp"
PV = "io.modelcontextprotocol/protocolVersion"
CAPS = "io.modelcontextprotocol/clientCapabilities"
CLIENT = ["2026-07-28", "2025-06-18"]


def send(method, version):
    body = {"jsonrpc": "2.0", "id": 1, "method": method,
            "params": {"_meta": {PV: version, CAPS: {}}}}
    headers = {"MCP-Protocol-Version": version, "Mcp-Method": method}
    return requests.post(URL, json=body, headers=headers)


first = send("tools/list", "2027-01-15")
error = first.json()["error"]
print(first.status_code, error["code"], error["data"]["supported"])
best = next(v for v in CLIENT if v in error["data"]["supported"])
second = send("tools/list", best)
print(second.status_code, best, len(second.json()["result"]["tools"]), "tools")
Drill

Name the missing keys

Write missing_keys(request): return the list of required _meta keys the request leaves out, in this order: protocolVersion, then clientCapabilities. A request with no params or no _meta is missing both.

PV = "io.modelcontextprotocol/protocolVersion"
CAPS = "io.modelcontextprotocol/clientCapabilities"


def missing_keys(request):
    return []


print(missing_keys({"method": "tools/list"}))
In the lesson, your code is checked as you write it.
Quick check
A client picks the best version both sides support, in its own order of preference. What does this print?
ours = ["2026-07-28", "2025-11-25", "2025-06-18"]
theirs = ["2025-11-25", "2025-06-18"]
print(next((v for v in ours if v in theirs), None))
  1. 2026-07-28
  2. None
  3. 2025-06-18
  4. 2025-11-25
Show the answer

2025-11-25

2026-07-28 isn't in theirs, so next moves on, and 2025-11-25 is the first that both lists have. The newest version the client knows that the server also supports wins. None would mean there's no common version.

Drill

Agree on a version

Write negotiate(client_prefers, server_supports): return the first version in the client's preference order that the server also supports, or None if they share none. Versions are date strings like "2026-07-28".

def negotiate(client_prefers, server_supports):
    return max(server_supports)


print(
    negotiate(["2026-07-28", "2025-11-25", "2025-06-18"], ["2025-06-18", "2025-11-25"]))
In the lesson, your code is checked as you write it.

When something must be remembered

Some things really do have to last across calls. A shopping basket is the classic case: add an item now, pay for it three calls later. In stateless MCP the server still can't keep that in connection memory, because the next call may reach a different copy.

The answer is a handle: the server stores the basket somewhere all its copies can read, such as a database, and returns a short id like "bsk_0001". The client sends that id back as an ordinary tool argument on later calls. It works like a coat check. You hand over the coat, you get a ticket, and any attendant can fetch the coat from the ticket.

The server should also check that the handle belongs to the caller, so one customer can't open another's basket by guessing an id.

In plain words: state that must last gets a ticket, and the ticket travels with every request.

Worked example

A basket that any copy can find

Two copies of a modern server share one store. The first call opens a basket and gets a handle; later calls pass the handle back, whichever copy they reach.

STORE = {}                      # stands in for a database every copy can reach

class ModernServer:
    def open_basket(self):
        handle = f"bsk_{len(STORE) + 1:04d}"
        STORE[handle] = []
        return handle
    def add_item(self, handle, item):
        if handle not in STORE:
            return "error: unknown basket"
        STORE[handle].append(item)
        return f"{len(STORE[handle])} item(s) in {handle}"

copies = [ModernServer(), ModernServer()]
handle = copies[0].open_basket()             # the first call lands on copy 0
print(copies[1].add_item(handle, "socks"))   # the next lands on copy 1
print(copies[0].add_item(handle, "hat"))
print(copies[1].add_item("bsk_9999", "scarf"))
In the lesson you can change this and run it.

The handle is the only thing the client holds. Both copies read the same store, so it doesn't matter which one gets the call: socks lands as item 1 and the hat as item 2 in the same basket. A made-up handle is refused.

In your own words
How do you keep state without a session?

Write a sentence or two, then compare it with a good answer in the lesson.

In the SDK and a real host: which software speaks which revision

Purpose. Know what a real server and a real host will do with the versions you just handled by hand.

A real server also answers server/discover, the one request a client may send before any other. Here is the practice server's reply, copied from a real call:

The official Python SDK does this for you: version 2 of the mcp package implements the 2026-07-28 revision and still serves older clients, so one server can answer both eras, as the practice server does. Version 1.x keeps getting fixes for code that hasn't moved yet.

In an engineer's week. An upgrade week looks like this. A host updates and starts sending _meta on every request. A server that still expects initialize answers with an error, and tools vanish from the host. The fix is to read the error, look at data.supported, and either upgrade the server or keep a dual-era client that probes first. What goes wrong is a version check written as an exact match on one date, so the next revision breaks it.

Goes deeper in

In your own words
A host starts sending a version your server doesn't know. What should the server answer, and what should the host do next?

Write a sentence or two, then compare it with a good answer in the lesson.

Choose how to practice

Start with a short baseline or choose guided, independent, or AI-assisted practice.

Practice what you just read

  • 4 code examples you can edit and run
  • a practice exercise that checks your code
  • a 5-question quiz
  • 9 review cards for spaced repetition

Try a quiz question

Which two _meta fields must every modern MCP request include?

  1. io.modelcontextprotocol/protocolVersion and io.modelcontextprotocol/clientCapabilities
  2. io.modelcontextprotocol/clientInfo and io.modelcontextprotocol/serverInfo
  3. Mcp-Session-Id and io.modelcontextprotocol/protocolVersion
  4. progressToken and io.modelcontextprotocol/logLevel

Answer it at the end of the lesson to see if you're right, and why.

Before this lesson

Keep learning

Where this lesson leads.

575 lessons in thirteen phases. 176 are free without an account, and a free account opens the rest. See every lesson.

Phase 9 · about 13 hours of study

Model Context Protocol

Build MCP servers, clients and hosts, from the wire format to production 17 lessons 1 free
  1. JSON-RPC 2.0 in depth FreeRequests, notifications, errors and a dispatcher built from scratch.35 min
  2. Versions and stateless requestsRevisions by date, the legacy handshake, per-request _meta and version negotiation.30 min
  3. Discovery, capabilities and the two erasserver/discover, declared capabilities, and talking to legacy and modern software alike.30 min
  4. Transports I: stdioNewline-delimited JSON over a subprocess's standard streams.30 min
  5. Transports II: Streamable HTTPOne endpoint, required headers, JSON or event-stream replies.40 min
  6. Build a server: toolsTool definitions, schemas from type hints, results and two kinds of error.45 min
  7. Resources and promptsReadable data, URI templates and reusable prompt templates.40 min
  8. The same server with the official SDKsYour registry and dispatcher on the SDK's decorator shape, in Python and TypeScript.40 min
  9. Build a clientMetadata on every request, version fallback, paging and caching.40 min
  10. Hosts: connecting servers to a modelMany servers, one agent: namespacing, routing and approvals.40 min
  11. Progress, subscriptions and multi-round-trip requestsLong-running work, change notifications and asking the user mid-call.45 min
  12. Securing remote servers with OAuthProtected resource metadata, PKCE, audiences and scope challenges.45 min
  13. MCP securityTool poisoning, rug pulls, confused deputies and local-server risks.40 min
  14. Lab: attack and defend a hostPoisoned tools, injected results, token replay and the defenses that stop each.40 min
  15. Testing, designing and shipping serversConformance checks, tool design for models, SDKs and deployment.40 min
  16. MCP in production: gateways, limits and auditAn allowlist, per-user rate limits, header checks and an audit log in front of many servers.35 min
  17. Capstone: a production MCP serverA complete, tested server for the practice shop.45 min
Part of a free course 15 lessons

Build and Deploy MCP Integrations

Build a Model Context Protocol client and server, then verify the integration with a compatible host.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write