JSON-RPC 2.0
JSON-RPC 2.0 is the underlying communication protocol used by the Model Context Protocol (MCP). It provides a simple, stateless way for a client to request the execution of a method on a server and receive a response.
Why JSON-RPC for MCP?
- Simplicity: Easy to implement in any programming language.
- Human-Readable: Messages are structured as JSON, making them easy to debug and audit.
- Language Agnostic: Allows a Python-based client to communicate seamlessly with a Go-based server.
Message Types in MCP
- Request: A notification or a call that expects a response (e.g.,
call_tool). - Response: The result of a request, containing either the requested data or an error.
- Notification: A message sent without an
id, requiring no response (e.g., capability updates).
Questions & Answers
What is JSON-RPC 2.0, and why is it used in MCP?
JSON-RPC 2.0 is the foundational communication protocol for MCP. It provides a simple, text-based, and language-agnostic way for clients to call methods on servers and handle the results or errors.
What are the three primary message types in the MCP / JSON-RPC structure?
The primary message types are Requests (which expect a response), Responses (which contain the result or error), and Notifications (which are one-way messages requiring no response).
How does JSON-RPC 2.0 handle failed requests?
Failed requests return a structured Response object containing an error key. This key includes a numeric code and a message, providing clear feedback on what went wrong (e.g., "Method not found").