Reading the Wire: A Tool Call in JSON-RPC
Trace a tool call message by message in revision 2026-07-28: server discovery, the per-request _meta fields, a successful result, a tool execution error, a protocol error and a protocol version mismatch with its retry.
Contentsand lesson path
On this page
- The problem
- Step 1: A tool that prints the wire
- Step 2: Discovery
- Step 3: A successful tool call
- Step 4: Two kinds of failure
- Step 5: A protocol version mismatch
- Check your understanding
- Apply it
- Review prompt
Lessons of MCP Fundamentals
- Why a Protocol for Tools and Context Concept · 15 min
- Primitives: Tools, Resources and Prompts Concept · 15 min
- Lab: A Host and Your Own Client on Local and Remote Servers Lab · 30 min
- Reading the Wire: A Tool Call in JSON-RPC Worked example · 20 min
- Spec Revisions and Compatibility Concept · 10 min
- Check: MCP Architecture Scenarios Knowledge check · 6 questions
What you will learn
- Trace an MCP tool call through its JSON-RPC messages, including server discovery, protocol version handling and error results.
Prerequisites: Tool Calling
01. The problem
A user asks an agent to convert 37 degrees Celsius. The host passes the request to the model, the model picks the celsius_to_fahrenheit tool, and a number comes back. When this works, nobody looks at the messages. When it fails, the messages are the only evidence you have: did the client reach the server, did they agree on a protocol version, did the tool run, and if it failed, who should fix what?
In this worked example you trace every message of that conversation against the atlas-units server from the lab in lesson 3, using the protocol revision 2026-07-28. Then you trace three things that go wrong: bad arguments, a tool that does not exist, and a client that asks for a protocol version the server does not speak.
You need server.py, mcp_core.py and client.py from the lab. MCP messages follow JSON-RPC 2.0 (the specification is at jsonrpc.org; it is not an IETF RFC). On stdio each message is one line of JSON; on Streamable HTTP each POST body is one message, and the reply is JSON or an SSE stream.
02. Step 1: A tool that prints the wire
Clients normally hide the raw messages. wire.py does the opposite: it starts server.py on stdio, sends the requests you name on the command line, and prints each request (-->) and reply (<--) as indented JSON. It deliberately sends only the two required _meta keys and leaves out the optional clientInfo, to keep the frames short. Save it next to the lab files.
"""Print the raw JSON-RPC frames of chosen requests to server.py over stdio."""
import json
import subprocess
import sys
P = "io.modelcontextprotocol/"
TOOL = "celsius_to_fahrenheit"
STEPS = {
"discover": ("server/discover", {}),
"list": ("tools/list", {}),
"call": ("tools/call", {"name": TOOL, "arguments": {"celsius": 37}}),
"invalid": ("tools/call", {"name": TOOL, "arguments": {"celsius": -300}}),
"unknown": ("tools/call", {"name": "celsius_to_kelvin", "arguments": {}}),
"old": ("tools/list", {}),
"initialize": ("initialize", {
"protocolVersion": "2025-11-25", "capabilities": {},
"clientInfo": {"name": "old-host", "version": "1.0"}}),
}
server = subprocess.Popen([sys.executable, "server.py"], text=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
for number, step in enumerate(sys.argv[1:], start=1):
method, params = STEPS[step]
version = "1900-01-01" if step == "old" else "2026-07-28"
meta = {P + "protocolVersion": version, P + "clientCapabilities": {}}
if step != "initialize": # a handshake-era client sends no _meta
params = {**params, "_meta": meta}
request = {"jsonrpc": "2.0", "id": number, "method": method, "params": params}
server.stdin.write(json.dumps(request) + "\n")
server.stdin.flush()
reply = json.loads(server.stdout.readline())
print("-->", json.dumps(request, indent=2))
print("<--", json.dumps(reply, indent=2))
server.stdin.close()
server.wait()03. Step 2: Discovery
A client may start with server/discover to learn the server's supported versions, capabilities and identity in one round trip. It is optional: a client that already knows the server can send tools/call straight away. Every 2026-07-28 server must answer it.
python3 wire.py discover--> {
"jsonrpc": "2.0",
"id": 1,
"method": "server/discover",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
<-- {
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "atlas-units",
"version": "0.1.0"
}
},
"supportedVersions": [
"2026-07-28"
],
"capabilities": {
"tools": {},
"resources": {},
"prompts": {}
},
"ttlMs": 60000,
"cacheScope": "public"
}
}Read the request first. jsonrpc is always "2.0". The id is the client's to choose: MCP allows a string or an integer, never null, and it must not repeat an id that is still waiting for a reply. The two required _meta keys travel even on this first request, because the server keeps no memory between requests.
Now the reply. It carries the same id, which is how the client matches it to the request. result.resultType is "complete"; every 2026-07-28 result has this field. supportedVersions tells the client which value to put in protocolVersion from now on. capabilities says which families of requests the server answers, here tools, resources and prompts. The server names itself in the result's _meta under serverInfo; that is self-reported and meant for display and logs, not for security decisions. ttlMs and cacheScope say the client may reuse this answer for 60 seconds.
04. Step 3: A successful tool call
Before calling a tool, a host normally sends tools/list (try python3 wire.py list) and hands the definitions to the model. When the model chooses celsius_to_fahrenheit with {"celsius": 37}, the client sends tools/call.
python3 wire.py call--> {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "celsius_to_fahrenheit",
"arguments": {
"celsius": 37
},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
<-- {
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "atlas-units",
"version": "0.1.0"
}
},
"content": [
{
"type": "text",
"text": "{\"fahrenheit\": 98.6}"
}
],
"structuredContent": {
"fahrenheit": 98.6
}
}
}params.name and params.arguments say what to run; _meta comes along again. The result carries the answer twice on purpose: content is the text the host shows the model, and structuredContent is typed data for code, which must match the tool's outputSchema. There is no isError field, which means the same as false.
Over Streamable HTTP the body is identical. The transport adds headers that copy parts of it: MCP-Protocol-Version: 2026-07-28, Mcp-Method: tools/call and Mcp-Name: celsius_to_fahrenheit. A server must reject a request whose headers and body disagree, with HTTP 400 and error -32020, as you saw in the lab's negative tests.
05. Step 4: Two kinds of failure
Send two bad calls in one run: a temperature below absolute zero, then a tool name that does not exist. They fail in different ways, and the difference decides who can fix the problem.
python3 wire.py invalid unknown--> {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "celsius_to_fahrenheit",
"arguments": {
"celsius": -300
},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
<-- {
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "atlas-units",
"version": "0.1.0"
}
},
"content": [
{
"type": "text",
"text": "celsius must be a number >= -273.15, got -300"
}
],
"isError": true
}
}
--> {
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "celsius_to_kelvin",
"arguments": {},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
<-- {
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": -32602,
"message": "Unknown tool: celsius_to_kelvin"
}
}The first reply is a tool execution error. The request was valid and the tool ran, but the input failed its check, so the server returns an ordinary result with isError: true and a message that says what was wrong. The client should pass this to the model, which can correct the argument and try again. The specification lists API failures, business-rule failures and input validation errors (wrong type, out of range, bad format) in this category.
The second reply is a protocol error: a top-level error object with a numeric code and no result. MCP uses it when the request itself cannot be processed: an unknown tool, a request that does not match the tools/call schema, or a server failure. The specification uses -32602 (Invalid params) for an unknown tool. A model can rarely fix these, so a host usually logs them or tells the user. Other codes you will meet: -32601 for an unknown method (HTTP 404 on Streamable HTTP), -32602 for a request missing a required _meta field (HTTP 400), and -32021 when the server needs a client capability the request did not declare.
Implementations differ at the edges. The Python SDK's MCPServer, for example, reports an unknown tool as a result with isError: true rather than as -32602. A robust client handles both shapes, and a careful server author picks one and documents it.
06. Step 5: A protocol version mismatch
Finally, a client asks for a protocol version the server does not implement. wire.py old sends 1900-01-01, a value no server supports, the same placeholder the specification uses in its own example.
python3 wire.py old--> {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "1900-01-01",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
<-- {
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32022,
"message": "Unsupported protocol version",
"data": {
"supported": [
"2026-07-28"
],
"requested": "1900-01-01"
}
}
}This is UnsupportedProtocolVersionError, code -32022. Its data.supported lists what the server speaks, and data.requested echoes what the client asked for. On Streamable HTTP it arrives with HTTP 400. The client should pick a version from supported that it also speaks and send the request again with a new id, or report clearly that there is no common version. McpClient.call() in the lab does exactly that. Run it with a deliberately wrong starting version:
"""Start with a version the server rejects and let McpClient.call() recover."""
import sys
from client import McpClient, StdioTransport
transport = StdioTransport([sys.executable, "server.py"])
client = McpClient(transport, version="1900-01-01") # deliberately unsupported
try:
tools = client.call("tools/list")["tools"]
print("now speaking:", client.version, "| tools:", [t["name"] for t in tools])
finally:
transport.close()python3 retry_demo.pyatlas-units: serving on stdio
now speaking: 2026-07-28 | tools: ['celsius_to_fahrenheit']Calling server/discover first would have avoided the failed round trip, at the cost of one extra request; both approaches are allowed. What a 2026-07-28 client should not do is fall back to the old initialize handshake when it receives -32022: that error proves the server is modern. Lesson 5 covers how a client talks to servers built for 2025-11-25 and earlier.
07. Check your understanding
08. Apply it
Take the two calls you captured in the lab's practice task, one successful and one failing. For each message, label the id, the method, every _meta key, the resultType, and either isError or the error code. Decide whether the failure was a tool execution error or a protocol error, and write one sentence on who could fix it: the model, the user or the server's author. If one of your servers is on 2025-11-25 or earlier, note which fields are missing compared with the frames in this lesson.
09. Review prompt
From memory, write out a tools/call request and a successful reply for revision 2026-07-28, with every field. Then explain the difference between isError: true and a JSON-RPC error, give one example of each, and describe what a client does with error -32022.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.