Protocols

Detailed technical specifications and communication formats for the Model Context Protocol

MCP uses JSON-RPC 2.0 as its communication protocol. This allows for structured messages between clients and servers, with support for requests, responses, and notifications.

Protocol Layer

The protocol layer handles message framing, request/response linking, and high-level communication patterns.

Message Structure

JSON-RPC 2.0 Format

All messages follow the JSON-RPC 2.0 specification:

{
  "jsonrpc": "2.0",
  "id": "123",
  "method": "list_resources",
  "params": {
    "filter": "documents"
  }
}

Notice that requests and responses have an "id" field to link them together, while notifications don't have this field.

Protocol Features

Required Methods

MCP requires certain methods to be implemented:

MethodDescription
initializeFirst message sent by client to establish connection
initializedNotification sent by client after initialization
shutdownRequest to terminate the connection
exitNotification to indicate connection is closed

Capability Negotiation

During initialization, clients and servers exchange their capabilities:

// Client initialize request
{
  "jsonrpc": "2.0",
  "id": "init1",
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-03-26",
    "capabilities": {
      "resources": {}
    }
  }
}
 
// Server initialize response
{
  "jsonrpc": "2.0",
  "id": "init1", 
  "result": {
    "protocolVersion": "2025-03-26",
    "serverInfo": {
      "name": "example-server",
      "version": "1.0.0"
    },
    "capabilities": {
      "resources": {
        "supports": ["list", "get", "search"]
      }
    }
  }
}

Transport Mechanisms

MCP supports multiple transport mechanisms:

Standard I/O (stdio)

  • Uses process standard input/output
  • Suitable for local processes
  • Messages are delimited by specific headers

HTTP with Server-Sent Events (SSE)

  • Uses HTTP POST for client-to-server messages
  • Uses Server-Sent Events for server-to-client messages
  • Suitable for network communication

Schema Validation

MCP uses JSON Schema to validate messages:

  1. Each message type has a defined schema
  2. Messages are validated against their schema
  3. Invalid messages result in error responses

This ensures all communications follow the expected format and contain required fields.

How is this guide?

On this page