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 responsesmethod: The method name to callparams: Method parameters (optional, Object type)
Response
Success response:result and error are mutually exclusive; a response will contain only one of them.
Notification
Has noid field and expects no response:
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.| Method | Direction | Purpose |
|---|---|---|
tools/list | Client -> Server | List all available tools (supports pagination) |
tools/call | Client -> Server | Execute a specified tool |
notifications/tools/list_changed | Server -> Client | Tool list change notification |
2025-11-25):
name: Unique identifier for the tooltitle: Human-readable display namedescription: Describes the tool’s purpose; directly influences the AI model’s selection decisionsinputSchema: Input parameter definition in JSON Schema format (required)outputSchema: Output structure definition in JSON Schema format (optional, added in2025-11-25)
content: Content array supporting multiple types (text, image, audio, resource_link, embedded_resource)structuredContent: Structured data corresponding to theoutputSchema(optional, returned alongsidecontent, preferred for programmatic processing)isError: Indicates whether this is a tool-level error (truemeans the tool execution failed but the protocol layer is fine)
- Protocol-level errors: JSON-RPC error responses, indicating the request itself has issues (method not found, invalid parameters, etc.)
- 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.”| Method | Direction | Purpose |
|---|---|---|
resources/list | Client -> Server | List all available resources (supports pagination) |
resources/read | Client -> Server | Read a specified resource |
resources/subscribe | Client -> Server | Subscribe to resource changes |
resources/unsubscribe | Client -> Server | Unsubscribe |
notifications/resources/list_changed | Server -> Client | Resource list change notification |
notifications/resources/updated | Server -> Client | Subscribed resource content change notification |
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)
Prompts (Prompt Templates) — User-Controlled
Reusable interaction templates. Servers can provide predefined prompts that users actively select in the Host application.| Method | Direction | Purpose |
|---|---|---|
prompts/list | Client -> Server | List all available prompts (supports pagination) |
prompts/get | Client -> Server | Get a specified prompt (supports parameterized arguments) |
notifications/prompts/list_changed | Server -> Client | Prompt list change notification |
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.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.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 changessubscribe: Supports resource subscription (notifies the Client when content changes)
sampling: The Client supports Server requests for LLM inferenceelicitation: The Client supports Server requests for user inputroots.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
| Error Code | Meaning |
|---|---|
| -32700 | Parse error |
| -32600 | Invalid Request |
| -32601 | Method not found |
| -32602 | Invalid params |
| -32603 | Internal error |
MCP Custom Error Codes
| Error Code | Meaning | Description |
|---|---|---|
| -32001 | Request timeout | Server processing took too long |
| -32002 | Resource not found | Requested resource URI is invalid |
Tool-Level Errors
Business errors during tool execution do not use JSON-RPC error; instead, they are conveyed via theisError flag in the normal response:
Next Chapter: Transport Layer — Detailed explanation of stdio and Streamable HTTP transport methods