D2 · Tool Design & MCP › Cluster 5 · MCP Fundamentals

5.4 · Lifecycle & Capability Negotiation

initialize → operate → shutdown

CONCEPT MCP is a stateful, lifecycle-managed protocol

MCP is a stateful protocol: a connection isn't just "send whatever" — it has a defined lifecycle. Every connection goes through three phases:

  1. Initialization — an initialize handshake that negotiates the protocol version and each side's capabilities, followed by an initialized notification.
  2. Operation — normal request/response/notification traffic: tools/list, tools/call, resources/read, notifications, etc.
  3. Shutdown — the connection is closed (for stdio, the client closes the server's stdin and terminates the subprocess).
🔑 "The purpose of lifecycle management is to negotiate the capabilities that both client and server support." You must handshake before you can operate. No initialize, no tools.

CONCEPT The initialize handshake in detail

The client opens with an initialize request carrying a protocolVersion, its capabilities, and clientInfo. The server replies with its protocolVersion, capabilities, and serverInfo. Three things happen:

StepFieldPurpose
Version negotiationprotocolVersionEnsure compatible versions. "If a mutually compatible version is not negotiated, the connection should be terminated."
Capability discoverycapabilitiesEach side declares what it supports (tools, resources, prompts, notifications) so neither calls unsupported methods
Identity exchangeclientInfo / serverInfoName + version, for debugging and compatibility

A capability can carry sub-flags — e.g. "tools": {"listChanged": true} means the server will emit notifications/tools/list_changed when its tool set changes. After a successful handshake, the client sends notifications/initialized to signal it's ready — then normal operation begins.

Capability negotiation makes the protocol efficient and safe: a client won't attempt resources/read against a server that never declared a resources capability, and a server won't push list_changed notifications a client can't handle.

DIAGRAM The connection lifecycle

sequenceDiagram participant C as Client participant S as Server Note over C,S: 1 · Initialization (handshake) C->>S: initialize {protocolVersion, capabilities, clientInfo} S-->>C: result {protocolVersion, capabilities, serverInfo} C--)S: notifications/initialized Note over C,S: 2 · Operation (normal traffic) C->>S: tools/list S-->>C: result {tools:[…]} C->>S: tools/call {name, arguments} S-->>C: result {content:[…]} S--)C: notifications/tools/list_changed Note over C,S: 3 · Shutdown C->>S: close connection / terminate

CODE The initialize request & response

The literal JSON-RPC handshake — version + capability negotiation, then the ready notification:

// Client → Server
{
  "jsonrpc": "2.0", "id": 1, "method": "initialize",
  "params": {
    "protocolVersion": "2025-06-18",
    "capabilities": { "elicitation": {} },
    "clientInfo": { "name": "example-client", "version": "1.0.0" }
  }
}

// Server → Client (declares its own capabilities)
{
  "jsonrpc": "2.0", "id": 1,
  "result": {
    "protocolVersion": "2025-06-18",
    "capabilities": { "tools": { "listChanged": true }, "resources": {} },
    "serverInfo": { "name": "example-server", "version": "1.0.0" }
  }
}

// Client → Server : ready — now normal operation may begin
{ "jsonrpc": "2.0", "method": "notifications/initialized" }

TRADE-OFFS Negotiated handshake vs. assume-everything

✅ Explicit initialize + capability negotiation

  • Version mismatches fail fast and cleanly (terminate, don't misbehave)
  • Each side only calls methods the other declared — no wasted round-trips
  • Optional features (list-changed notifications, sampling) gate cleanly on capability

⚠️ Skipping the handshake / assuming support

  • Slightly less ceremony up front
  • But: silent failures when versions differ or a feature is unsupported
  • Breaks the stateful contract — operation before initialize is invalid

EXAM TRAPS

Trap: "MCP is stateless like plain HTTP." → MCP is a stateful protocol requiring lifecycle management. (A subset can be made stateless over Streamable HTTP, but the lifecycle model still applies.)
Trap: "You can call tools/list immediately." → Not until after the initialize handshake completes and the client sends notifications/initialized.
Trap: "Capabilities are just metadata." → They're load-bearing: a listChanged: true tools capability is what authorizes the server to send tools/list_changed notifications; undeclared features must not be used.
Trap: "Version mismatch just uses the client's version." → If no mutually compatible version is negotiated, the connection should be terminated, not silently forced.

PRACTICE

Q1 · What are the three phases of an MCP connection lifecycle?

Initialization (the initialize handshake + initialized notification), operation (normal request/response/notification traffic), and shutdown (connection close / subprocess termination).

Q2 · What three things does the initialize exchange accomplish?

Protocol-version negotiation (compatible versions or terminate), capability discovery (each side declares what it supports), and identity exchange (clientInfo / serverInfo for debugging/compatibility).

Q3 · A server declares "tools": {"listChanged": true}. What does that authorize?

It authorizes the server to send notifications/tools/list_changed whenever its available tool set changes, prompting the client to re-fetch tools/list. Without that declared capability, the server must not send those notifications.