JSON-RPC in AI Agent Communication: How MCP and A2A Use It

We researched the JSON-RPC 2.0 spec, the current MCP spec and A2A material to show how agent messages, errors and transports work on the wire.

JSON-RPC in AI Agent Communication: How MCP and A2A Use It

A JSON-RPC 2.0 request has just four members. Both MCP and A2A use that format as their message envelope, which is why JSON-RPC AI agent communication looks so alike across protocols. The format is tiny and stateless, built for calling a method and getting a reply. Learn it once and it pays off twice.

Most bugs come from the small rules. An MCP request ID may never be null, for instance, and an MCP HTTP request may carry only one message. We read the JSON-RPC 2.0 spec, the current MCP spec and the A2A material from the Agentic AI Foundation. We also read Amazon’s AgentCore contract for A2A servers.

If you want the wider picture first, read our comparison of multi-agent communication protocols. Here, we stay at the wire level.

The Four Fields in a JSON-RPC 2.0 Request

The JSON-RPC 2.0 spec dates from March 2010 and was last updated in January 2013. It does not care about transport. So the same message works inside one process, over a socket or over HTTP.

A request object has four members. First, jsonrpc must be exactly “2.0”. Second, method is a string, and names that begin with “rpc.” are reserved. Third, params is optional and holds either an array or an object. Finally, id is a string, a number or null, although the spec discourages null.

These two calls come straight from the spec. The arrow –> marks what the client sends, and <– marks the reply.

--> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
<-- {"jsonrpc": "2.0", "result": 19, "id": 1}

--> {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3}
<-- {"jsonrpc": "2.0", "result": 19, "id": 3}

The first call passes values by position. In the second, values go by name, and member names are case-sensitive. Either way, the server copies the id into its reply so the client can match them.

jsonrpc.org
JSON-RPC 2.0 Specification website screenshot
JSON-RPC 2.0 Specification

How Replies and Notifications Work

A response carries either result or error, never both. It must also carry the id from the request. However, if the server could not read the id, for example after a parse error, the id comes back as null.

A notification is a request with no id. So the server must not answer it, even inside a batch. The client never learns whether a notification failed. Agent protocols use notifications for progress updates and cancel signals, where no reply is needed.

--> {"jsonrpc": "2.0", "method": "update", "params": [1,2,3,4,5]}
(no reply)

Reserved Error Codes Every Agent Developer Meets

An error object has an integer code and a short message. It can also carry a data member with extra detail. The spec reserves the range from -32768 to -32000 for predefined errors, and the rest of the integer space is free for apps.

CodeMessageWhat it means
-32700Parse errorThe server got invalid JSON
-32600Invalid RequestThe JSON is not a valid request object
-32601Method not foundThe method does not exist or is not available
-32602Invalid paramsThe parameters are wrong for that method
-32603Internal errorSomething failed inside the JSON-RPC layer
-32000 to -32099Server errorReserved for errors each implementation defines

So when a client calls a method the server does not offer, expect -32601. Then, when the method exists but the arguments are wrong, expect -32602.

<-- {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "1"}

Batch Calls and Why MCP Leaves Them Out

Plain JSON-RPC lets a client send an array of requests in one go. The server may run them in any order, even at the same time. So the client matches each reply by id. Also, an empty array is invalid, and a batch of only notifications gets no reply at all.

MCP does not use batches. Its Streamable HTTP transport says the body of each POST must be a single request or notification. Likewise, its stdio transport sends one message per line. So an MCP client that wants three tool calls sends three separate messages.

Read also: Multi-Agent Communication Protocols: MCP, A2A, AG-UI, ANP and FIPA-ACL

MCP’s Stricter Rules on Top of JSON-RPC

Every MCP message must follow JSON-RPC 2.0. Then MCP adds rules of its own, and the current revision dated July 28, 2026 adds the most. In that revision, MCP became stateless. So each request carries everything the server needs to handle it.

IDs, Result Types and the _meta Field

An MCP request ID must be a string or an integer, and it must not be null. Also, the sender may not reuse an ID while a request with that ID is still waiting for its reply.

Next, every successful result carries a resultType field. A value of “complete” means the answer is final. With “input_required”, the server needs more, such as a user’s answer. Then the client retries the same call with the extra input. Our guide to human-in-the-loop orchestration shows how teams put a person in that loop.

Finally, each request puts its protocol version and client capabilities inside params._meta. Client name and version are optional there. As a result, a server must not lean on an earlier request on the same connection to know who is calling.

MCP’s Own Error Codes

MCP keeps the standard JSON-RPC codes for general failures. Then it splits the server range. Codes from -32000 to -32019 are legacy, and new code should not use them. The range from -32020 to -32099 belongs to the MCP spec.

CodeMCP nameWhen it appears
-32020HeaderMismatchHTTP headers do not match the message body
-32021MissingRequiredClientCapabilityThe request needs a capability the client did not declare
-32022UnsupportedProtocolVersionThe server does not support the requested version
-32602Invalid paramsAlso used now for a missing resource and for a request missing required _meta fields

Also, the old resource-not-found code -32002 is retired in this revision. Still, clients should accept it from servers on older versions.

MCP Over Standard Input and Output

In the stdio transport, the client launches the MCP server as a child process. The server reads JSON-RPC messages from stdin and writes them to stdout. Each message sits on its own line, and a message must not contain a newline inside it.

The server may write logs to stderr. But it must never write anything to stdout that is not a valid MCP message. So a single stray print statement in a server corrupts what the client reads. To cancel a request on stdio, the client sends a notifications/cancelled message with the request’s ID.

modelcontextprotocol.io
MCP stdio Transport Spec website screenshot
MCP stdio Transport Spec

MCP Over Streamable HTTP

Streamable HTTP is the transport for remote MCP servers. The server exposes one endpoint, such as https://example.com/mcp, and the client sends each message as its own HTTP POST. Also, the client’s Accept header must list both application/json and text/event-stream.

For a request, the server picks one of two replies. It can return a single JSON object. Or it can open a Server-Sent Events stream for that request, send progress notifications, and end with the final response. For a notification, the server answers 202 Accepted with no body.

Headers That Mirror the Message Body

Each POST must carry an MCP-Protocol-Version header. It also needs Mcp-Method, and tool, resource and prompt calls add Mcp-Name. So a load balancer can route a call without parsing the JSON. This example comes from the spec.

POST /mcp HTTP/1.1
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: get_weather

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_weather",
    "arguments": { "location": "Seattle, WA" },
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientInfo": { "name": "ExampleClient", "version": "1.0.0" },
      "io.modelcontextprotocol/clientCapabilities": {}
    }
  }
}

If a header and the body disagree, the server rejects the call with 400 Bad Request and error -32020. The spec gives this sample reply.

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32020,
    "message": "Header mismatch: Mcp-Name header value 'foo' does not match body value 'bar'"
  }
}

A tool can also mark some of its parameters for mirroring with an x-mcp-header property. Then the client adds a header such as Mcp-Param-Region. Values that are not plain ASCII get Base64 encoding inside a =?base64?…?= wrapper.

What Changed From the Old HTTP and SSE Setup

The first MCP release used a transport called HTTP+SSE for remote servers. That transport is now deprecated, and new servers should not adopt it. Earlier Streamable HTTP revisions also had session IDs, a separate GET stream and resumable streams. The current revision drops all three, and closing a response stream now cancels that request.

Security rules stay strict. Servers must check the Origin header to block DNS rebinding. Also, a local server should bind to 127.0.0.1 and not to every network interface.

A2A Calls Wrapped in JSON-RPC

A2A offers three bindings, and JSON-RPC over HTTP is one of them. The others are gRPC and a REST-style HTTP+JSON binding. In version 1.0, the method names switched to PascalCase, such as SendMessage, GetTask and CancelTask. The older 0.x names looked like message/send.

Version 1.0 also dropped the kind field that used to label each part. Instead, the member name tells the reader what the part holds, such as text or data. In addition, example requests send an A2A-Version: 1.0 header. For the full A2A model of tasks and Agent Cards, see our guide to agent-to-agent communication.

aaif.io
A2A Version 1.0 Builder's Guide From the Agentic AI Foundation website screenshot
A2A Version 1.0 Builder’s Guide From the Agentic AI Foundation

A Real A2A Request on Amazon Bedrock AgentCore

Amazon Bedrock AgentCore Runtime hosts A2A servers. Its contract asks for JSON-RPC 2.0 over HTTP on port 9000 by default, with the Agent Card at /.well-known/agent-card.json. This request sample from AWS still uses the 0.3 style with message/send and the kind field.

{
  "jsonrpc": "2.0",
  "id": "req-001",
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "parts": [
        { "kind": "text", "text": "Your message content here" }
      ],
      "messageId": "unique-message-id"
    }
  }
}

The reply is a normal JSON-RPC result with the same id.

docs.aws.amazon.com
Amazon Bedrock AgentCore A2A Protocol Contract website screenshot
Amazon Bedrock AgentCore A2A Protocol Contract

Errors With Real HTTP Status Codes

AgentCore maps its own exceptions to JSON-RPC codes in the server range. For example, -32052 means a validation error with HTTP 400. Then -32053 means throttling with HTTP 429. Also, -32054 covers conflicts with HTTP 409, and one of them says a session operation is in progress and should be retried.

However, AgentCore breaks one A2A habit. The A2A spec’s convention sends JSON-RPC errors inside an HTTP 200 reply. But AgentCore returns the real HTTP status, such as 404 or 409. So a client must read the JSON-RPC error body even when the status is not 2xx. Otherwise, it misses the retry hint.

Other Products That Speak the Same Envelope

Several agent frameworks ship A2A or MCP endpoints out of the box. For instance, LangSmith Agent Server gives a deployed LangGraph agent an A2A endpoint at /a2a/{assistant_id}. It uses the version 1.0 JSON-RPC binding. Still, it also accepts four older 0.3 names, such as message/send and tasks/get.

Also, CrewAI supports all three A2A bindings through its optional a2a install. Meanwhile, Microsoft Agent Framework can serve an agent over A2A and call remote A2A agents too. Google ADK can serve an agent over A2A and call remote ones as well. Our list of AI agent frameworks compares them on other points.

Bugs That Break JSON-RPC Agent Links

Every mistake here is one the specs warn against. Each one is cheap to test for before launch.

  • Logs on stdout. An MCP stdio server that prints debug text to stdout corrupts the message stream. Send logs to stderr.
  • Null or reused IDs. Plain JSON-RPC allows a null id, but MCP forbids it. MCP also bans reusing an ID while that request is still open.
  • Batches sent to MCP. A JSON array of requests in one POST breaks the single-message rule. Send each call alone.
  • Ignoring the error body. On AgentCore, a 409 can carry a retry hint inside the JSON-RPC error. Parse the body on every status code.
  • Waiting for a notification reply. A notification never gets an answer. So use a request with an id when you need to know the outcome.
  • Header drift. An Mcp-Name header that differs from params.name triggers -32020. Build both from the same variable.

Also, agents that retry failed calls in a loop can run up large model bills. Our guide on controlling AI agent costs covers retry caps and budgets.

Where Our Wire Examples Came From

We read the JSON-RPC 2.0 spec on jsonrpc.org. Then we read the MCP base protocol, stdio and Streamable HTTP pages for the July 28, 2026 revision. After that, we read the Agentic AI Foundation’s A2A version 1.0 builder’s guide. Finally, we read Amazon’s AgentCore A2A contract for a production example.

We copied the code samples from those specs where they exist. The one error reply with code -32601 is our own example, built from the JSON-RPC rules.

Wire-Format Puzzles We Get Asked About

Is JSON-RPC the Same as a REST API?

No. REST maps actions to URLs and HTTP verbs. JSON-RPC puts the method name inside the message, so one endpoint can serve every call. That is why an MCP server needs only a single HTTP endpoint.

Does MCP Support JSON-RPC Batching?

Not in the current revision. Each Streamable HTTP POST must hold one request or notification, and stdio sends one message per line.

Can A2A Run Without JSON-RPC?

Yes. A2A also defines gRPC and HTTP+JSON bindings. An agent lists each binding it offers in its Agent Card, and the client picks one.

Can an MCP Request ID Be Null?

No. MCP requires a string or an integer ID on every request. Plain JSON-RPC already discourages null IDs, so MCP turns that advice into a hard rule.

For the planning side of agents that make these calls, read our explainer on dynamic planning in LLM agents.

Read also: How Many SEOs Use AI Agents? Our Study of 69 Agency Websites

Related AI Agents

Explore Agent Categories

Related Articles

Joydeep Bhattacharya Avatar

Written by