The MCP Guide
Getting started

How an MCP connection works: lifecycle and messages

Under the hood MCP is a JSON-RPC 2.0 exchange over a transport. You rarely write these messages by hand (the SDKs do it), but understanding the shape makes debugging far easier.

JSON-RPC messages #

Every message is one of three JSON-RPC types: a request (expects a response), a response (success or error), or a notification (fire-and-forget). See JSON-RPC 2.0 for the base format. A tool call is just a request named tools/call:

json{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "create_issue",
    "arguments": { "title": "Bug in checkout", "repo": "acme/store" }
  }
}

The lifecycle #

  1. Initialize. The client sends initialize with its protocol version and capabilities. The server replies with its own. This is capability negotiation: each side learns what the other supports before anything else happens.
  2. Operate. The client discovers what is available (tools/list, resources/list, prompts/list) and then uses it (tools/call, resources/read). Servers can push notifications, for example when their tool list changes.
  3. Shut down. The connection closes cleanly when the host is done.

Discovery is just another request. The client calls tools/list:

json{ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }

and the server returns its tool definitions (trimmed):

json{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "tools": [
      {
        "name": "create_issue",
        "description": "Open a GitHub issue.",
        "inputSchema": {
          "type": "object",
          "properties": { "repo": { "type": "string" }, "title": { "type": "string" } },
          "required": ["repo", "title"]
        }
      }
    ]
  }
}

Why capability negotiation matters #

Because both sides declare what they support up front, a client never calls something the server cannot do, and a server never assumes a client feature that is not there. This is what lets the protocol evolve, newer features are simply advertised and older peers ignore them.

Resources & further reading

  • MCP specification MCPThe authoritative protocol spec: messages, capabilities, transports, and lifecycle.
  • JSON-RPC 2.0 jsonrpc.orgThe message format MCP is built on: requests, responses, and notifications.