Skip to main content

Data Layer Protocol

2.1 JSON-RPC 2.0 Fundamentals

The MCP data layer is built on the JSON-RPC 2.0 specification. All messages are in JSON format and fall into three categories:

Request

  • jsonrpc: Fixed as "2.0"
  • id: Unique request identifier (string or number), used for matching responses
  • method: The method name to call
  • params: Method parameters (optional, Object type)

Response

Success response:
Error response:
result and error are mutually exclusive; a response will contain only one of them.

Notification

Has no id field and expects no response:
Notifications are unidirectional; the sender does not wait for any reply.

2.2 Server-Side Primitives

An MCP Server can expose three core capabilities:

Tools — Model-Controlled

Executable functions. The AI model autonomously decides when to call them. Tool Definition (protocol version 2025-11-25):
Key field descriptions:
  • name: Unique identifier for the tool
  • title: Human-readable display name
  • description: Describes the tool’s purpose; directly influences the AI model’s selection decisions
  • inputSchema: Input parameter definition in JSON Schema format (required)
  • outputSchema: Output structure definition in JSON Schema format (optional, added in 2025-11-25)
Tool execution result:
  • content: Content array supporting multiple types (text, image, audio, resource_link, embedded_resource)
  • structuredContent: Structured data corresponding to the outputSchema (optional, returned alongside content, preferred for programmatic processing)
  • isError: Indicates whether this is a tool-level error (true means the tool execution failed but the protocol layer is fine)
Two types of errors:
  1. Protocol-level errors: JSON-RPC error responses, indicating the request itself has issues (method not found, invalid parameters, etc.)
  2. Tool-level errors: isError: true, indicating the tool executed but encountered a business error (product not found, insufficient permissions, etc.)

Resources — Application-Controlled

Data sources that provide contextual information. The difference from Tools: Tools “do things,” Resources “provide information.” Resource Definition:
Annotations field descriptions:
  • audience: Target audience; possible values include "user" and "assistant"
  • priority: Priority, a float between 0 and 1 (1 is highest priority)
  • lastModified: Last modified time (ISO 8601 format)
URI Templates: Resource URIs support RFC 6570 URI template syntax for defining dynamic resources:

Prompts (Prompt Templates) — User-Controlled

Reusable interaction templates. Servers can provide predefined prompts that users actively select in the Host application. Prompt Definition:
Getting a Prompt:

2.3 Client-Side Primitives

MCP Clients can also expose capabilities to Servers (must be declared during initialization):

Sampling — Server Requests LLM Inference

The Server does not need a built-in AI SDK; it can request the Host’s LLM to complete inference.
modelPreferences fields:
  • hints: Model hint list; the Server suggests which model to use (the Host may ignore this)
  • costPriority: Cost priority (0-1, higher values favor lower-cost models)
  • speedPriority: Speed priority (0-1, higher values favor faster models)
  • intelligencePriority: Intelligence priority (0-1, higher values favor more capable models)

Elicitation — Server Requests User Input

Used when the Server needs user confirmation or supplementary information.

Roots — Filesystem Boundaries

The Server queries the accessible filesystem scope.

Logging — Log Messages

The Server sends log messages to the Client for debugging and monitoring.
Log levels: debug, info, notice, warning, error, critical, alert, emergency.

2.4 Capability Negotiation

During initialization, both sides declare their supported capabilities. Only declared capabilities can be used. Server capabilities:
  • listChanged: The Server will send notifications when the list changes
  • subscribe: Supports resource subscription (notifies the Client when content changes)
Client capabilities:
  • sampling: The Client supports Server requests for LLM inference
  • elicitation: The Client supports Server requests for user input
  • roots.listChanged: The Client will notify the Server when filesystem boundaries change

2.5 Error Handling

MCP uses standard JSON-RPC 2.0 error codes plus MCP-specific extensions:

Standard JSON-RPC Error Codes

MCP Custom Error Codes

Tool-Level Errors

Business errors during tool execution do not use JSON-RPC error; instead, they are conveyed via the isError flag in the normal response:
This design allows the AI model to see the error message and adjust its behavior accordingly (for example, retrying with a different order ID).
Next Chapter: Transport Layer — Detailed explanation of stdio and Streamable HTTP transport methods