Sub topic 6
Initialization and Capability Negotiation
This chapter assumes you know what host, client and server mean in MCP, and that you can read JSON-RPC messages (requests, responses and notifications). If you need a refresher, review the chapters on architecture and the message format first.
Why a handshake exists
An MCP client and server are written by different people and released on different schedules. Before they exchange real work, they must agree on two things:
- Which version of the protocol they will speak.
- Which optional features each side supports.
The connection lifecycle handles this. It has three phases: initialization, normal operation, and shutdown. Nothing else may happen until initialization finishes. The one exception is that either side may send ping requests.
Step 1: The initialize request
The client always speaks first. It sends an initialize request that states the newest protocol version it supports, the features it offers, and who it is.
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": { "roots": { "listChanged": true } },
"clientInfo": { "name": "my-assistant", "version": "1.0.0" }
}
}The capabilities object lists optional client features, such as roots (directories the server may work in), sampling (the server asking the host's model for a completion) and elicitation (the server asking the user for input).
Step 2: The server's response
The server replies with the protocol version it will use and its own capabilities.
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-06-18",
"capabilities": {
"tools": { "listChanged": true },
"resources": { "subscribe": true }
},
"serverInfo": { "name": "calculator", "version": "0.1.0" }
}
}Version negotiation works like this. If the server supports the client's version, it echoes it back. If not, it answers with another version it does support, usually its latest. The client then decides whether it can work with that version. If it cannot, it should disconnect.
Step 3: The initialized notification
Finally, the client sends notifications/initialized. This is a notification, so it has no id and receives no reply. It tells the server that the handshake is complete and requests may begin.
Reading capabilities
Each key in a capabilities object is a feature. Sub-flags refine it.
| Capability | Declared by | Meaning |
|---|---|---|
| `tools` | Server | The server exposes tools. |
| `resources` | Server | The server exposes resources. |
| `prompts` | Server | The server exposes prompt templates. |
| `listChanged` | Server or client | The sender will notify you when its list changes. |
| `subscribe` | Server (resources) | Clients can subscribe to updates for one resource. |
| `roots` | Client | The client can tell the server which directories are in scope. |
| `sampling` | Client | The server may ask the client's model for completions. |
The rule is simple: use only what both sides declared. A client must not call tools/list if the server did not declare tools. A server must not send a sampling request if the client did not declare sampling.
Common errors
- Sending requests before the handshake finishes. A client that calls
tools/listbeforenotifications/initializedmay get an error, or the server may ignore the call. - Forgetting the initialized notification. Some servers stay silent until they receive it, so the connection looks hung.
- Assuming a capability exists. Check the negotiated capabilities, not the server's documentation. A server can disable features by configuration.
- Writing logs to stdout on a stdio server. Stdout carries the protocol. A stray
printcorrupts the handshake. Write logs to stderr instead. - Mismatched protocol versions. An older server may answer with a version your client does not support. The error appears at connect time, not when you first use a tool.
Shutdown
There is no special shutdown message. On stdio, the client closes the server's input stream and, if needed, terminates the process. On HTTP, the client closes the connection. Either way, the next connection performs a fresh handshake, and nothing from the old session carries over.
Exercise
A client connects to a server whose initialize response contains "capabilities": { "tools": {} }. The client wants to show the user a list of prompt templates. Should it send prompts/list? Explain, and say what the empty tools object tells you.
Show answer
No. The server did not declare the prompts capability, so the client must not call prompts/list. The empty tools object means the server supports tools but offers no extras, such as listChanged notifications. The client should call tools/list once and not expect updates.