JSON-RPC in MCP: Requests, Responses and Notifications

JS
Jai Singh
12 Nov, 2026 3 min read 12 views

Every MCP message is a JSON-RPC 2.0 message. There are only three shapes: a request, which expects a reply; a response, which is either a result or an error; and a notification, which expects no reply. Once you can read these three, you can read any MCP traffic.

Requests

A request has four fields: jsonrpc (always the string "2.0"), a unique id, a method name and optional params. Here is a request to call a tool:

{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "tools/call",
  "params": {
    "name": "slugify",
    "arguments": { "text": "Hello World" }
  }
}

The id lets the sender match the eventual reply to this request. MCP requires that an id is not null and, within a session, not reused by the same sender. Either side can send requests: clients send tools/call, while servers can send sampling/createMessage or roots/list.

Successful responses

A response carries the same id as the request and a result object.

{
  "jsonrpc": "2.0",
  "id": 7,
  "result": {
    "content": [{ "type": "text", "text": "hello-world" }]
  }
}

Responses can arrive in any order, because requests are matched by id, not by position. A slow tool call does not block a fast ping that was sent after it.

Error responses

When a request fails at the protocol level, the response has an error instead of a result. The error has a numeric code, a message and optional data.

{
  "jsonrpc": "2.0",
  "id": 8,
  "error": {
    "code": -32602,
    "message": "Unknown tool: slugfy"
  }
}

The code -32602 is the standard JSON-RPC code for invalid params. Other standard codes include -32601 for method not found, -32600 for an invalid request, -32700 for a parse error and -32603 for an internal error.

Do not confuse this with a tool that ran but failed. A failure inside the tool is normally reported as a successful JSON-RPC response whose result has isError: true. That distinction gets its own post, because it affects how the model can recover.

Notifications

A notification looks like a request without an id. Because there is no id, there is nothing to reply to, and the receiver must not send a response.

{
  "jsonrpc": "2.0",
  "method": "notifications/tools/list_changed"
}

MCP uses notifications for events: notifications/initialized after the handshake, notifications/progress for long operations, notifications/cancelled to abandon a request, and list-changed notices when tools, resources or prompts change.

Method names you will see

MethodDirectionPurpose
initializeclient to serverStart the session
pingeitherCheck the other side is alive
tools/list, tools/callclient to serverFind and run tools
resources/list, resources/readclient to serverFind and read resources
prompts/list, prompts/getclient to serverFind and fetch prompts
sampling/createMessageserver to clientAsk the host for a model completion
roots/listserver to clientAsk for the allowed roots

Sending raw messages in code

You rarely build these by hand, but a short script makes the format concrete. This Python script starts a stdio server, performs the handshake and lists its tools, matching responses by id.

import json
import subprocess

proc = subprocess.Popen(
    ["python", "server.py"],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    text=True,
)

def send(message):
    proc.stdin.write(json.dumps(message) + "\n")
    proc.stdin.flush()

def read():
    return json.loads(proc.stdout.readline())

send({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {
    "protocolVersion": "2025-03-26",
    "capabilities": {},
    "clientInfo": {"name": "raw", "version": "0.0.1"},
}})
print(read()["result"]["serverInfo"])

send({"jsonrpc": "2.0", "method": "notifications/initialized"})
send({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
for tool in read()["result"]["tools"]:
    print(tool["name"])

proc.stdin.close()
proc.wait()

Running it against the temperature server from the earlier post prints the server's name and version, followed by the two tool names. The script assumes the server replies promptly and sends no notifications in between, which is fine for a demo but not for a real client.

Practical tips

  • When debugging, look for the id: an unanswered request means the server hung or crashed.
  • Messages over stdio are one JSON object per line, so a message must not contain raw newlines outside of JSON string escapes.
  • Use the SDK's client in real code. It handles ids, timeouts and out-of-order replies for you.
Was this article helpful?

Comments

No comments yet. Have a question or a tip? Be the first to share it.

Leave a comment

Comments are reviewed before they appear.