The Protocol Layer: JSON-RPC, Transports, and Discovery
- Distinguish the data layer (JSON-RPC 2.0) from the transport layer (stdio or Streamable HTTP)
- Explain why stdio servers must never write to stdout
- Describe how clients and servers negotiate protocol versions using server/discover
Two Layers, One Protocol
MCP's architecture separates two concerns that most protocols conflate: what a message contains and how it travels. This separation is deliberate and powerful.
The data layer is JSON-RPC 2.0. It defines the format of requests, responses, and notifications. Every MCP message is a JSON-RPC message, regardless of transport. If you understand JSON-RPC, you understand the shape of every message MCP can send.
The transport layer defines how those messages move between client and server. MCP currently supports two transports: stdio (for local servers) and Streamable HTTP (for remote servers). The same JSON-RPC messages work over either transport — the data layer is fully transport-agnostic.
This separation means you can build an MCP server without knowing or caring which transport a client will use. The server receives a JSON-RPC request; it sends back a JSON-RPC response. Whether that exchange happened over a subprocess pipe or an HTTP connection is handled entirely by the SDK's transport layer.
JSON-RPC 2.0: The Data Layer
JSON-RPC 2.0 is a lightweight remote procedure call protocol that uses JSON for encoding. It defines three message types, and MCP uses all three.
Requests are messages from the client to the server (or in some flows, the reverse) that expect a response. A request has four fields:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "get_forecast",
"arguments": { "latitude": 37.77, "longitude": -122.42 }
}
}
The id field links the request to its response. The method field names the operation. The params field carries the arguments. Every MCP operation — listing tools, calling a tool, reading a resource — is a JSON-RPC request.
Responses are replies to requests. A successful response carries a result; a failed response carries an error object with a code, message, and optional data:
-- Success
{ "jsonrpc": "2.0", "id": "1", "result": { "content": [...] } }
-- Error
{ "jsonrpc": "2.0", "id": "1", "error": { "code": -32602, "message": "Unknown tool" } }
Notifications are one-way messages with no id and no expected response. MCP uses them for events like a tool list changing or a resource being updated. Because there is no id, there is no way to correlate a notification with a request — they are fire-and-forget signals:
{ "jsonrpc": "2.0", "method": "notifications/tools/list_changed" }
Standard JSON-RPC error codes you will encounter in MCP:
-32602— Invalid params (e.g., unknown tool name, missing required argument)-32603— Internal error (server-side failure)-32600— Invalid request
The stdio Transport
The stdio transport is the standard for local servers. The host (via the client) launches the server as a child process, then communicates with it over the process's standard input and standard output streams. Each JSON-RPC message is sent as a single UTF-8 line terminated by a newline character.
This means one absolute rule applies to every stdio server you write: never write anything to stdout except JSON-RPC messages. If your server writes a debug message, a startup banner, or a log line to stdout, it will corrupt the message stream and break the connection. All logging must go to stderr. The SDKs enforce this by routing the standard logging framework to stderr automatically — you do not need to configure it manually, but you do need to know why the rule exists.
The stdio transport has essentially zero overhead. There is no network stack, no TLS handshake, no connection establishment beyond the subprocess launch. For local tools, this makes it the right default. The tradeoff is isolation: a stdio server can only serve the client that launched it. It cannot be shared across machines or across multiple host instances.
The Streamable HTTP Transport
Streamable HTTP is the transport for remote servers. Client-to-server messages are sent as HTTP POST requests to a fixed endpoint. The server can respond immediately (a standard HTTP response) or open a Server-Sent Events stream for responses that arrive over time or in multiple parts.
Streamable HTTP supports full authentication. Clients can send bearer tokens, API keys, or any custom header. The protocol recommends OAuth for obtaining tokens in multi-user deployments. This makes Streamable HTTP suitable for SaaS tools, shared organizational servers, and any server that needs to identify and authorize individual users.
Because each request is a stateless HTTP call, Streamable HTTP servers can scale horizontally without sticky sessions. Any instance of the server can handle any request, as long as it has access to whatever backing store the server uses. This is a significant advantage over stateful connection models for high-availability deployments.
Statelessness in the Current Spec
The 2026-07-28 version of the MCP specification introduced a fully stateless protocol model. In earlier versions of the spec, clients opened a persistent session with an initialize handshake that established capabilities for the duration of the connection. The current version removes that session concept.
Instead of session state, each request carries its own context in a _meta field using the io.modelcontextprotocol/ namespace. A client that wants to identify itself sends:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": { "elicitation": {} }
}
}
}
Statelessness has important implications. Servers cannot rely on remembering anything about a client between requests. Any state a tool needs across calls must be encoded in the tool's arguments (the handle pattern, covered in Lesson 10). This is a stricter model than session-based protocols, but it is what enables horizontal scaling and simplified failure recovery.
If you are using an MCP SDK, it handles _meta automatically. You do not write these fields by hand. But understanding them helps you debug protocol-level issues when they arise.
Discovery: server/discover
When a client connects to a server, the first thing it optionally calls is server/discover. This request returns everything the client needs to know about the server: which protocol versions it supports, which capabilities it declares, and its identity information.
A discovery response looks like this:
{
"supportedVersions": ["2026-07-28", "2025-11-25"],
"capabilities": {
"tools": { "listChanged": true },
"resources": {}
},
"serverInfo": {
"name": "my-weather-server",
"version": "1.0.0"
},
"ttlMs": 300000,
"cacheScope": "server"
}
The ttlMs and cacheScope fields tell the client how long to cache the discovery result. A client does not need to re-discover on every request if the discovery result is still fresh. cacheScope: "server" means the result is valid for all clients talking to this server; cacheScope: "client" means each client should cache independently.
Calling server/discover is optional — a client can skip it and include capabilities in _meta on every request instead. In practice, SDKs call it on first connection and cache the result.
Version Negotiation
MCP is a versioned protocol. Servers may support multiple protocol versions simultaneously. Clients declare which version they prefer in _meta. If the server does not support the requested version, it returns an UnsupportedProtocolVersionError that lists the versions it does support:
{
"code": -32603,
"message": "UnsupportedProtocolVersionError",
"data": { "supportedVersions": ["2026-07-28", "2025-11-25"] }
}
The client then retries with one of the supported versions. This negotiation happens transparently when you use the SDKs. The TypeScript serveStdio function, for example, automatically serves both 2026 and 2025 clients from the same server code by detecting which version the client requests.
For your own servers, using the current SDK version is the best way to ensure compatibility. The SDKs track the spec and handle version negotiation on your behalf. You write your tools, resources, and prompts once; the SDK handles the protocol layer.
- Every MCP message is a JSON-RPC 2.0 message — the same structure works over any transport
- stdio transport is zero-overhead for local tools; Streamable HTTP enables remote, scalable, authenticated servers
- The 2026-07-28 spec is stateless — each request carries its own context in a _meta field
Progress is saved in this browser only — clear your cache or switch device and it's gone. Create a free account and it follows you everywhere.