McpClient

initialize()

client.initialize({ signal? }) → Promise<{ protocolVersion, … }>

The handshake. It announces the revisions this client really speaks and settles on the newest both sides know.

30 sannounces honestlyfalls back once
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const handshake = await client.initialize();
console.log(handshake.protocolVersion);   // what both sides agreed on
console.log(client.protocolVersion);      // the same, kept on the client
handshake = client.initialize()
print(handshake["protocolVersion"])   # what both sides agreed on
print(client.protocol_version)        # the same, kept on the client

It announces what it can speak

Announcing a revision you do not speak is worse than announcing an old one

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

CodeStatusWhen
mcp_token_required401The server wants a token and none was given.
mcp_unauthorized401The token was refused.
mcp_redirect502A redirect. They are never followed.
mcp_protocol_unsupported502No revision in common.
mcp_unreachable502No answer.
mcp_timeout504Over 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.