What You Will Build
The protocol revision you have been speaking, 2026-07-28, is a recent
one, and much of the software you will meet still speaks the revision
before it. The two differ in how a connection starts: the older one opens
with a handshake called initialize and then treats the connection as a
session; the current one has no handshake at all, and each request
carries its own version and capabilities. The SDK's server serves both,
and its client can open either. In this lesson you open the preview
server in the client's three modes and read what each reports, then
perform the older handshake by hand and watch the same server refuse a
modern request on that connection. By the end you can look at any
transcript and say which era it is in and what will happen next.
Why the Handshake Went Away
In the handshake era (revision 2025-11-25 and earlier), a client sent
initialize with its version and capabilities, the server answered with
its own, the client sent notifications/initialized, and from then on
every message belonged to that session. Over HTTP the server minted a
session id that the client had to send back on every request, and the
server had to keep state for each live session
(S35).
Revision 2026-07-28 removed the session. Every request now carries the
protocol version and the client's capabilities in its _meta envelope,
so a server can answer any request on its own, in any order, on any
instance behind a load balancer. The handshake was replaced by
server/discover, which any client may call to learn the server's
supported versions, capabilities and instructions, and which a server
must implement
(S40,
S50).
A client that already knows what it needs can skip discovery and send its
first real request straight away. The same change replaced other
session-bound features: server-to-client requests became multi
round-trip results, and the long-lived notification stream became
subscriptions/listen, both of which later modules teach.
The versioning rules are simple
(S43):
a server that receives a version it does not support answers with
-32022 and a supported list, which you saw in the last lesson; a
client picks from that list. Over HTTP the version also travels in a
request header, and a header that disagrees with the envelope is
-32020 (the transports module). The specification's revision is dated,
and 2026-07-28 is the current release
(S76).
The Era of a Connection
A server built with this SDK is dual-era: it serves both revisions from one program. For a stdio connection, the first message decides which. The behaviour below was recorded against the preview server:
| First message on the connection | Era the connection serves | Then |
|---|---|---|
| Any request with a valid 2026-07-28 envelope | Modern | Requests with the envelope work; a request without one is -32602 |
initialize | Handshake | Session requests without an envelope work; ping works; a request with the modern envelope is -32600 |
Anything else (no params, or _meta without the required keys) | Handshake | The first request is -32602, and the connection stays in the handshake era, so modern requests after it are -32600 |
The last row is the surprising one and the reason wire_errors.py in the
previous lesson sent one good server/discover first. A connection whose
first message was a malformed modern request is treated as a
handshake-era connection, and every later modern request on it is refused
with "this connection serves the handshake protocol era". When a client
"works on the second run but not the first", this is the first thing to
check. Over HTTP the choice is made per request by the version header
instead, so there is no such lock-in
(S35,
S45).

Two clients, one server. The first message fixes the era of a stdio connection, and a request from the other era is refused.
Exercise: Three Modes and a Handshake by Hand
Goal: open the preview server in the SDK client's auto, legacy
and pinned modes, read what each reports, then perform the handshake by
hand and watch a modern request refused on that connection.
Starting state: the course environment active;
~/mcp-practice/server-tour/preview_server.py.
Effects: creates a folder with a copy of the server and two scripts. Each script starts the server as a child process and stops it. No network is used.
-
Create the folder and copy the server in. macOS and Linux:
mkdir -p ~/mcp-practice/eras cd ~/mcp-practice/eras cp ~/mcp-practice/server-tour/preview_server.py .Windows PowerShell:
mkdir $HOME\mcp-practice\eras cd $HOME\mcp-practice\eras copy $HOME\mcp-practice\server-tour\preview_server.py . -
Save this as
modes.py:"""Open the preview server in the client's three modes.""" import asyncio import sys from mcp import Client, StdioServerParameters SERVER = StdioServerParameters(command=sys.executable, args=["preview_server.py"]) async def show(label: str, **options) -> None: async with Client(SERVER, **options) as client: name = client.server_info.name if client.server_info else None tools = len((await client.list_tools()).tools) print(f"{label:<14} protocol {client.protocol_version} server_info {name} tools {tools}") async def main() -> None: await show("auto") await show("legacy", mode="legacy") await show("pinned", mode="2026-07-28") asyncio.run(main()) -
Run it, keeping the server's log lines out of the way:
python modes.py 2> server.logauto protocol 2026-07-28 server_info inventory-preview tools 3 legacy protocol 2025-11-25 server_info inventory-preview tools 3 pinned protocol 2026-07-28 server_info None tools 3 -
Save this as
legacy.py:"""A legacy-era handshake by hand, then a modern request on the same connection.""" import json import subprocess import sys server = subprocess.Popen([sys.executable, "preview_server.py"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) def send(message: dict, expect_reply: bool = True) -> None: print(">>", json.dumps(message)) server.stdin.write(json.dumps(message) + "\n") server.stdin.flush() if expect_reply: print("<<", server.stdout.readline().strip()) send({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-11-25", "capabilities": {}, "clientInfo": {"name": "legacy-by-hand", "version": "0.1"}}}) send({"jsonrpc": "2.0", "method": "notifications/initialized"}, expect_reply=False) send({"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "stock_level", "arguments": {"sku": "belt-m6"}}}) send({"jsonrpc": "2.0", "id": 3, "method": "ping"}) send({"jsonrpc": "2.0", "id": 4, "method": "tools/list", "params": {"_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}) server.stdin.close() server.wait(timeout=10) -
Run it:
python legacy.py>> {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-11-25", "capabilities": {}, "clientInfo": {"name": "legacy-by-hand", "version": "0.1"}}} << {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"prompts":{"listChanged":false},"resources":{"listChanged":false,"subscribe":false},"tools":{"listChanged":false}},"instructions":"Read-only view of a workshop parts inventory.","protocolVersion":"2025-11-25","serverInfo":{"name":"inventory-preview","version":"0.1.0"}}} >> {"jsonrpc": "2.0", "method": "notifications/initialized"} >> {"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "stock_level", "arguments": {"sku": "belt-m6"}}} << {"jsonrpc":"2.0","id":2,"result":{"content":[{"text":"belt-m6: 7 each in bin B1","type":"text"}],"isError":false,"structuredContent":{"result":"belt-m6: 7 each in bin B1"}}} >> {"jsonrpc": "2.0", "id": 3, "method": "ping"} << {"jsonrpc":"2.0","id":3,"result":{}} >> {"jsonrpc": "2.0", "id": 4, "method": "tools/list", "params": {"_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}} << {"jsonrpc":"2.0","id":4,"error":{"code":-32600,"message":"this connection serves the handshake protocol era; requests carrying the 2026-07-28 envelope are not accepted on it"}}
Success: the three mode lines as shown, with server_info None on
the pinned line; the handshake result reports protocolVersion
2025-11-25; the tool call and ping succeed without any envelope; the
final request is refused with -32600.
How the Three Modes Work
The client's mode argument chooses how it opens a connection
(S31):
auto(the default, as in the tour lesson) sendsserver/discoverfirst. A modern server answers it, so the client reports the modern version and fillsserver_info,instructionsandserver_capabilitiesfrom the result. Against a server that does not knowserver/discover, the client falls back to the handshake. This is the mode to use unless you have a reason not to.legacyperforms the handshake:initialize, thennotifications/initialized. The negotiated version is2025-11-25, andserver_infocomes from theinitializeresult. You need this mode for features that exist only in the handshake era, such as the SDK's push-style elicitation, which the asking-the-user lesson contrasts with the modern form.- A pinned version, here
"2026-07-28", sends no discovery at all: the client assumes the version and goes straight to its first request. That is whyserver_infoisNone: the one message that would have carried the server's name was never sent, and the client does not read it out of later results'_meta. Pinning is for clients that already know the server; a handshake-era version cannot be pinned, as the independent task shows.
In every mode the client lists the same three tools: the server's offering does not change with the era, only the way the connection starts.
Reading the Handshake
The hand-written initialize carries protocolVersion, capabilities
and clientInfo as top-level params, where the modern era puts them in
_meta. The server's result mirrors it: protocolVersion (the version
it will speak on this session), capabilities, serverInfo and
instructions, with no resultType, ttlMs or cacheScope, which did
not exist yet. Notice that the capability flags are all false on this
path: the SDK's handshake-era service of this server does not promise
list-change notifications or subscriptions, while the modern discover
result advertised them. The notifications/initialized line has no id
and gets no reply, which is why the script sends it with
expect_reply=False. After that, requests carry no envelope, ping
exists and answers with an empty result, and a tool call looks like the
modern one without resultType. Then the cross-era request is refused.
The Compatibility Matrix
What happens when the two sides disagree, as recorded with this SDK and read from its documentation (S31, S35):
| Client | SDK 2.x server (dual-era) | Handshake-era-only server |
|---|---|---|
auto | Modern: discover succeeds | Falls back to the handshake |
legacy | Handshake era on that connection | Handshake |
Pinned 2026-07-28 | Modern, no discover, server_info None | Fails: the server does not understand the envelope |
| Hand-written, modern first | Modern | Fails |
Hand-written, initialize first | Handshake era; modern requests refused with -32600 | Handshake |
Hosts adopted the current revision at different times, and some you meet
will still open with initialize. Because a server written with this SDK
serves both eras, the server you build in this course works with either
kind of host; the deployment lesson shows the HTTP side, where legacy
sessions need a session id and sticky routing while modern requests need
neither. For a client of your own, use auto.
The 2.x SDK itself is where the modern path arrived: version 2.0.0
(2026-07-28) renamed FastMCP to MCPServer, put one Client in front
of the older session object and made the stateless era the default
(S03). Over stdio the
framing is the same in both eras, one JSON object per line
(S44).
When It Goes Wrong
| Symptom | Cause | Fix |
|---|---|---|
-32600 ... this connection serves the handshake protocol era | The connection's first message was initialize or a malformed modern request; later modern requests are refused | Start a new connection and send a valid envelope first |
-32022 Unsupported protocol version | The envelope names a version the server lacks | Use one from data.supported |
-32602 params._meta must be an object carrying the required ... | A modern connection received a request without the envelope | Add _meta with the two required keys |
ValueError: mode must be 'legacy', 'auto', or one of ['2026-07-28']; got '2025-11-25' ('2025-11-25' is a handshake-era version; use mode='legacy') | A handshake-era version was pinned | Use mode="legacy" |
server_info is None | The client is pinned, so it never sent server/discover | Use auto, or call server/discover yourself if you need the name |
Your Turn: Pin the Wrong Era, Then Read Four Transcripts
-
Predict what happens, then run this one-liner in the exercise folder:
python -c "import sys; from mcp import Client, StdioServerParameters; Client(StdioServerParameters(command=sys.executable, args=['preview_server.py']), mode='2025-11-25')" -
For each transcript opening, say which era the connection is in and whether the next request described succeeds:
(a) First message
server/discoverwith a valid envelope; next, atools/listwith the envelope. (b) First messageinitializeat2025-11-25; next,pingwith no params. (c) First messagetools/listwithparams: {}; next,tools/listwith a valid envelope. (d) First messageinitialize; next,tools/callwith a valid modern envelope. -
Explain in one sentence why
pingworked inlegacy.pybut was-32601in the previous lesson.
Reset and Clean Up
Both scripts start and stop their own server and can be rerun freely.
This is the end of the protocol-foundations module, so remove both this
lesson's folder and server-tour, which the next module no longer needs
(the tools module has you write your own server). macOS and Linux:
cd ~/mcp-practice
ls
rm -r eras
rm -r server-tour
ls
Windows PowerShell:
cd $HOME\mcp-practice
ls
Remove-Item -Recurse eras
Remove-Item -Recurse server-tour
ls
.venv and data remain.
Check Your Understanding
- A transcript starts with
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-11-25", ...}}and a result. The next line is aresources/listrequest whoseparamshold a 2026-07-28_metaenvelope. Write the reply'scodeand the gist of its message. - A colleague's client pins
"2026-07-28"and then printsclient.server_info.name, which raisesAttributeError: 'NoneType' object has no attribute 'name'. Explain the cause and give two fixes. - Why can a modern server answer requests in any order on any instance, while a handshake-era server cannot?
Answer and Reasoning
Your turn
- The constructor refuses before any process starts:
ValueError: mode must be 'legacy', 'auto', or one of ['2026-07-28']; got '2025-11-25' ('2025-11-25' is a handshake-era version; use mode='legacy'). A pinned mode skips discovery and assumes the modern envelope, which a handshake-era version cannot carry, so the SDK points you tomode="legacy"instead. - (a) Modern; the next request succeeds. (b) Handshake;
pingsucceeds with{}. (c) Handshake, because the malformed first message fixed the era; the next request is refused with-32600. (d) Handshake; the modern-envelope call is refused with-32600. pingis a handshake-era method that the 2026-07-28 revision removed, so the server answers it only on a connection serving that era; on a modern connection it is-32601 Method not found.
Understanding check
-32600, with the message that this connection serves the handshake protocol era and requests carrying the 2026-07-28 envelope are not accepted on it.- Pinning sends no
server/discover, and that is the only message whose result the client readsserver_infofrom, so the attribute staysNone. Either open withmode="auto"(one extra request, and the name, instructions and capabilities are filled in), or keep the pin and do not rely onserver_info. - Every modern request carries the version and the client's
capabilities itself, so the server needs nothing from earlier
messages to answer it; a handshake-era server learned those once, at
initialize, and must remember them for the rest of the session, which ties the session to one process and one connection.
References
- S03: SDK docs: What's new in v2
- S31: SDK docs: Protocol versions
- S35: SDK docs: Serving legacy clients
- S40: Specification changelog 2026-07-28
- S43: Specification: Versioning and compatibility
- S44: Specification: Transports overview and stdio
- S45: Specification: Streamable HTTP
- S50: Specification: Discovery
- S76: Specification release 2026-07-28