Skip to main content

Module json

Module json 

Source
Expand description

Shared JSON-RPC 2.0 codec.

One set of wire types serves three surfaces: the MCP client (to external servers), the self-MCP server, and the private supervisor↔subagent control channel. They differ only in framing (see frame): MCP stdio is newline-delimited; the control channel is length-prefixed.

Keeping every wire type behind serde in this one module is deliberate: it is the single isolation point from which the codec could be swapped to a lighter encoder (e.g. miniserde) without touching call sites, should the proc-macro compile weight ever need to come out of the dependency budget.

Modules§

frame
Two framings over a byte stream, sharing the JSON-RPC codec in the parent module (crate::rpc).

Structs§

Notification
A JSON-RPC 2.0 notification (no id; no response).
Request
A JSON-RPC 2.0 request (has an id; expects a response).
Response
A JSON-RPC 2.0 response (exactly one of result / error).
RpcError
A JSON-RPC 2.0 error object. Distinct from a successful result that carries isError: true — the latter is a tool-domain failure fed back to the model as an observation, the former is a protocol/transport failure. That distinction is load-bearing in the loop: an isError result keeps the conversation going, an RpcError aborts the call.
Version
The literal "2.0". A newtype so a malformed jsonrpc field is a parse error, not a silent mismatch.

Enums§

Id
JSON-RPC request/response id. Spec allows string or number (and, in responses to a parse error, null). We never send a null id.
Incoming
Any inbound JSON-RPC frame, before we know which kind it is. A reader thread parses one of these per frame and dispatches: responses resolve a pending request by id; notifications fan out to handlers; requests (only on the server side / sampling-style server→client) are answered.

Constants§

INTERNAL_ERROR
INVALID_PARAMS
INVALID_REQUEST
METHOD_NOT_FOUND
PARSE_ERROR
RESOURCE_NOT_FOUND
MCP server-defined: a resources/read for a URI the server doesn’t have.