DS DevShelfHub Projects · AI tools
Tutorials / MCP / JSON-RPC 2.0
MCP Beginner · 9 min read Page 3 of 23

JSON-RPC 2.0 Fundamentals

By DevShelfHub

Every MCP interaction is a JSON-RPC 2.0 message. Learn the four message types, the standard error codes, and the rules that keep clients and servers in sync.

Series progress3 / 23

Why JSON-RPC?

MCP needs a tiny, well-understood message format that runs over any transport — stdio, HTTP, WebSockets. JSON-RPC 2.0 is exactly that: a one-page spec, native JSON, and bidirectional support for requests, responses, and one-way notifications.

One-line version: JSON-RPC defines the envelope; MCP defines what goes inside.

The four message types

Request

Has an id. The receiver MUST reply with a Response or Error.

Response (success)

Echoes the request's id and carries a result.

Response (error)

Same id but carries an error with code & message.

Notification

NO id. Fire-and-forget — the receiver MUST NOT reply.

Request shape

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search_docs",
    "arguments": { "query": "MCP transports" },
    "_meta": { "progressToken": "abc123" }
  }
}
  • jsonrpc MUST be the literal string "2.0".
  • id is a string or integer — unique across all in-flight requests.
  • params._meta.progressToken opts into progress notifications.

Response (success vs error)

Success
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      { "type": "text", "text": "Found 3 hits." }
    ]
  }
}
Error
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}

A response MUST contain exactly one of result or error — never both.

Standard error codes

Code Meaning When you see it
-32700Parse errorInvalid JSON.
-32600Invalid RequestMissing required JSON-RPC field.
-32601Method not foundUnknown method name.
-32602Invalid paramsWrong types, missing required, etc.
-32603Internal errorServer-side bug.
-32000…-32099Server-definedReserve for your own implementation.

Important: Tool execution failures (invalid input, business-rule violations) belong in CallToolResult.isError: true, NOT a JSON-RPC error. That distinction lets the LLM read the failure and self-correct.

Notifications

Notifications have no id and never get a reply. MCP uses them heavily — progress, cancellation, log messages, list-changed events, the initialized handshake.

json
{
  "jsonrpc": "2.0",
  "method": "notifications/progress",
  "params": { "progressToken": "abc123", "progress": 50, "total": 100 }
}

Quick summary

  • Every MCP message is JSON-RPC 2.0 — request, response (success or error), or notification
  • Requests carry an id; notifications don't
  • Standard error codes: -32600 invalid request, -32601 method not found, -32602 invalid params, -32603 internal
  • Tool execution failures use isError: true inside the result, not a JSON-RPC error

JSON-RPC 2.0 in MCP FAQ

What is JSON-RPC 2.0?

JSON-RPC 2.0 is a stateless, lightweight remote procedure call protocol encoded in JSON. It defines four message types: requests (with an id), responses (with the same id), notifications (fire-and-forget, no id), and error objects.

Why does MCP use JSON-RPC 2.0?

JSON-RPC 2.0 is simple, language-agnostic, and transport-independent. MCP uses it because it provides a uniform message format that works over stdio, HTTP, and WebSockets without needing to change the protocol layer.

What is the difference between a JSON-RPC request and a notification?

A JSON-RPC request includes an 'id' field and expects a response. A notification omits the 'id' and the receiver must not send a response. MCP uses notifications for progress updates, log messages, and cancellation signals.

What are the standard JSON-RPC error codes in MCP?

Standard codes include -32700 (Parse error), -32600 (Invalid Request), -32601 (Method not found), -32602 (Invalid params), and -32603 (Internal error). MCP also defines custom codes in the -32000 to -32099 range.

Can MCP send multiple JSON-RPC messages at once?

The JSON-RPC 2.0 spec allows batch requests (an array of request objects), but MCP implementations should check the SDK and transport documentation for batch support, as it varies by implementation.

Quick jump: API Reference