Architecture, JSON-RPC Messages and Statelessness
MCP connects AI applications (hosts) to external capabilities through servers, using JSON-RPC 2.0 messages. Since revision 2026-07-28 the protocol is stateless: there is no handshake, every request carries its version and capabilities in `_meta`, and every result carries a `resultType`. Know the roles, the message shapes and ID rules, the error-code ranges, and the per-request metadata that replaced connection state.
Key points
- 1
Roles: the host is the AI application that owns the model, the conversation and consent; it creates one MCP client per server, and each client keeps a dedicated 1:1 connection; servers expose tools (model-controlled), resources (application-driven) and prompts (user-controlled). Servers never see the whole conversation or other servers.
- 2
Why MCP: it turns N apps x M tools custom connectors into N + M implementations, with runtime discovery (
*/list) and one invocation contract. It complements model function calling (the model still picks the tool; the host's client runstools/call) and RAG (a retriever can be exposed as a tool or resource). - 3
Two layers: the data layer (JSON-RPC methods,
server/discover, primitives, notifications, progress) and the transport layer (stdio or Streamable HTTP framing, connection handling, HTTP authorization). Data-layer messages are identical on every transport. - 4
JSON-RPC shapes: a request has
methodandid(string or integer, nevernull, unique among the sender's unanswered requests); a response has the sameidplusresultorerror; a notification hasmethodand noid, and gets no response. Error responses may omitidonly when it could not be read. - 5
Direction (2026-07-28): clients send requests and notifications; servers send responses and request-scoped notifications. Servers MUST NOT initiate JSON-RPC requests; when they need input they return
resultType: "input_required"(Multi Round-Trip Requests). - 6
resultTypeis required on every 2026-07-28 result:"complete"or"input_required", plus values defined by advertised extensions. Unrecognised values MUST be treated as invalid; an absentresultTypefrom an earlier-revision server MUST be treated as"complete". - 7
Per-request
_meta:io.modelcontextprotocol/protocolVersionandio.modelcontextprotocol/clientCapabilitiesare required on every request (missing means-32602, HTTP 400);clientInfois a SHOULD;logLevelandprogressTokenare opt-ins. Servers SHOULD returnio.modelcontextprotocol/serverInfoin result_meta. Info fields are self-reported and must not drive security decisions. - 8
Statelessness: servers MUST NOT rely on earlier requests on the same connection for version, capabilities or identity, and a stdio process is not a session. Cross-request state MUST be referenced by an explicit identifier, typically a server-minted handle passed as a normal tool argument. Capabilities are judged per request; a missing one needed for processing gets
-32021MissingRequiredClientCapability withdata.requiredCapabilities. - 9
Error codes: standard
-32700parse,-32600invalid request,-32601method not found,-32602invalid params (also unknown tool and, since 2026-07-28, resource not found),-32603internal.-32000to-32019is legacy;-32020to-32099is reserved for the spec (-32020HeaderMismatch,-32021MissingRequiredClientCapability,-32022UnsupportedProtocolVersion). Put new application codes outside-32768to-32000. - 10
Cancellation: on Streamable HTTP, closing the request's SSE stream is the signal; on stdio, send
notifications/cancelledwithrequestIdand an optionalreason. Servers may ignore unknown or finished requests; clients ignore late responses. Set timeouts on every request, optionally reset on progress, but always enforce a maximum. - 11
Progress: put a unique
progressTokenin_meta; the server MAY sendnotifications/progresswith an increasingprogress, optionaltotalandmessage, and MUST stop after completion. - 12
_metakeys: an optional dot-label prefix ending in/(reverse DNS preferred), then a name. Prefixes whose second label ismcpormodelcontextprotocolare reserved.traceparent,tracestateandbaggageare unprefixed exceptions for OpenTelemetry (W3C formats). Extension identifiers use the same rules with a mandatory prefix and are advertised in theextensionscapability.
Common traps
Saying the model calls the MCP server: the host's client sends
tools/call; the model only emits a tool-use request.Using
-32601for an unknown tool name:tools/callexists, so the spec uses-32602Invalid params.Putting an
idon a notification turns it into a request; notifications must never carry an ID or get a reply.Assuming a stdio connection is a session, or reusing capabilities declared on an earlier request; every 2026-07-28 request stands alone.
Calling
logging/setLevelorping: both were removed in 2026-07-28 (log level is now per request via_meta, and Logging itself is deprecated).Treating
clientInfoas authentication; it is self-reported and only for display, logging and debugging.Allocating a custom error in
-32020to-32099; that sub-range belongs to the MCP specification.
Read the source
Further reading
Suggest a resourceNo extra reading for Architecture, JSON-RPC Messages and Statelessness yet. Found a guide, video or cheat sheet that made it click? Share it and help the next learner.
Test yourself on Architecture, JSON-RPC Messages and Statelessness
Ten questions, with the answer and explanation after each one.