Model Context Protocol › JSON-RPC: the wire format

Michael BrenndoerferDecember 1, 20263 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 377Model Context Protocol › JSON-RPC: the wire format
Reading section 4 of 14 · JSON-RPC: the wire format · 3 minSection 4 of 14 · 3 min

Section 4 of 14 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

JSON-RPC 2.0 defines the message envelope. A request has a version marker, an ID and a method. A response carries either a result or an error and echoes the request ID when it can be read. Generic JSON-RPC 2.0 places null in the response ID when a malformed request's ID cannot be recovered. Dated MCP permits the error response to omit the ID in that case. A notification omits the ID and receives no JSON-RPC reply. The MCP revision defines which directions and message patterns it uses. In 2026-07-28, clients send JSON-RPC requests and servers send the responses. Optional input such as elicitation can be requested within a response using the multi round-trip pattern.

Every modern MCP request declares its protocol revision and relevant client capabilities in params._meta. An empty client-capability object is valid for a client with none to declare. Client metadata can identify an implementation name and version. It is descriptive, so identity and permissions still belong to the transport and application policy. Clients can send server/discover to learn supported versions and capabilities. A modern server implements it, and a modern client can also make another operation first. If the revision is unsupported, the error names supported versions. The client should retry with a mutually supported revision or tell the user that the peers have no compatible version. Base protocol, versioning and compatibility, discovery.

PythonIn [5]
CollapseExpand
import json
from copy import deepcopy
from dataclasses import dataclass

PROTOCOL = "2026-07-28"
VERSION_KEY = "io.modelcontextprotocol/protocolVersion"
CLIENT_CAPS_KEY = "io.modelcontextprotocol/clientCapabilities"
CLIENT_INFO_KEY = "io.modelcontextprotocol/clientInfo"
SERVER_INFO_KEY = "io.modelcontextprotocol/serverInfo"


def request(request_id, method, payload=None, *, version=PROTOCOL):
    params = dict(payload or {})
    params["_meta"] = {
        VERSION_KEY: version,
        CLIENT_CAPS_KEY: {},
        CLIENT_INFO_KEY: {"name": "catalog-notebook", "version": "1.0"},
    }
    return {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": method,
        "params": params,
    }


def success(request_id, result):
    return {
        "jsonrpc": "2.0",
        "id": request_id,
        "result": {
            "resultType": "complete",
            "_meta": {
                SERVER_INFO_KEY: {"name": "fictional-catalog", "version": "1.0"}
            },
            **result,
        },
    }


def failure(request_id, code, message, **details):
    error = {"code": code, "message": message}
    if details:
        error["data"] = details
    response = {"jsonrpc": "2.0", "error": error}
    if request_id is not None:
        response["id"] = request_id
    return response

The 2025-11-25 revision used initialize followed by notifications/initialized. In that revision the handshake exchanged capabilities, and a Streamable HTTP server could issue an optional Mcp-Session-Id during initialization. The modern revision removes that handshake and protocol session header. Servers can still retain application state, for example a catalog service keeps records, but the modern protocol does not use a connection's prior lifecycle exchange to interpret a request. Check the SDK and server revision when porting a client. A version mismatch does not imply a malformed tool argument. Legacy lifecycle, legacy transport, 2026-07-28 changelog.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy