const handshake = await client.initialize();
console.log(handshake.protocolVersion); // what both sides agreed on
console.log(client.protocolVersion); // the same, kept on the clienthandshake = client.initialize()
print(handshake["protocolVersion"]) # what both sides agreed on
print(client.protocol_version) # the same, kept on the clientIt announces what it can speak
A server that implements the modern revision properly will refuse a handshake that claims it and then omits what it requires; an older server will quietly answer with its own revision, which hides the problem until something subtler breaks.
How a revision is chosen
The newest revision both sides know, taken from this client's ordered list. With nothing in common it raises mcp_protocol_unsupported rather than guessing.
It falls back once, and only on the right signal
A modern server that refuses the modern discovery is retried with the older handshake. The fallback happens only on a protocol-level refusal — a 401, a redirect, a silence or a timeout already name the thing to fix, and replacing them with a second attempt would replace the real cause with a different one.
Errors
| Code | Status | When |
|---|---|---|
| mcp_token_required | 401 | The server wants a token and none was given. |
| mcp_unauthorized | 401 | The token was refused. |
| mcp_redirect | 502 | A redirect. They are never followed. |
| mcp_protocol_unsupported | 502 | No revision in common. |
| mcp_unreachable | 502 | No answer. |
| mcp_timeout | 504 | Over 30 seconds. |
api.mcp does this for you
connect() initialises, lists and records the agreed revision — and get(name, { refresh: true }) does it again later.