JSON-RPC 2.0: Requests, Responses, Errors, and Notifications
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn JSON-RPC 2.0: Requests, Responses, Errors, and Notifications
Why it exists
MCP messages use the JSON-RPC 2.0 envelope, making it predictable to match requests with responses and send one-way events.
Message types
- Request: Contains
id,method, and optionalparams; a response is expected. - Successful response: Contains the same
idplusresult. - Error response: Contains the same
idplus a structurederror. - Notification: Contains
methodand optionalparams, but noid; no response is returned.
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/list",
"params": {}
}{
"jsonrpc": "2.0",
"id": 7,
"result": { "tools": [] }
}Protocol error versus tool error
- A malformed request or unknown method may result in a JSON-RPC or protocol error.
- A valid tool call whose business action fails may return a tool result with
isError: true. - Actionable tool errors can help the model correct its behavior safely.
Debugging checklist
- Do the request and response IDs match?
- Has an
idaccidentally been included in a notification? - Does the method name exactly match the specification?
- Are logs corrupting the transport's stdout output?
Adapted from 20_MCP_SERVER.md · “3. JSON-RPC 2.0: Requests, Responses, Errors, and Notifications”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.