MCP JSON-RPC message layer
TL;DR
MCP encodes its protocol messages as JSON-RPC 2.0. The client and server exchange requests, responses, and notifications over the transport. Each request has an id; responses carry that id and either a result or an error object with a code and message. Notifications have no id and no response.
Request and response
A JSON-RPC request is an object with jsonrpc: '2.0', method, params (optional), and id. A response matches the id and contains either result or error. The error object has a numeric code and a message string, and optional data.
Notifications
A notification is a request without an id. The sender does not expect a response. MCP uses notifications for progress updates, logging, and server-initiated events such as tool list changes.
Batch requests
JSON-RPC 2.0 supports batch requests: an array of request objects sent together. The receiver processes each and returns an array of responses. MCP allows batching for efficiency.
Error codes
Standard JSON-RPC error codes apply: -32700 (parse error), -32600 (invalid request), -32601 (method not found), -32602 (invalid params), -32603 (internal error). MCP may define additional application-level error codes in the -32000 to -32099 range.