Skip to main content

Module frames

Module frames 

Source
Expand description

JSON-RPC frame understanding for the MCP observe channel (GL#101).

The reverse proxy (mcp::proxy) does not shovel opaque bytes: it reads the request frame (which method? which tool?) and the response frame (result or error? how big?) so metering and the tool inventory get real semantics.

Everything here is total: malformed input yields None/fallbacks, never a panic — a broken client frame must pass through unharmed (observe never blocks) and simply produces a generic event.

Determinism (#498): token/byte figures are computed over the canonical JSON form (recursively key-sorted, compact separators), so the same result payload always yields the same numbers regardless of upstream key order.

Structs§

ParsedRequest
A parsed request frame: the JSON-RPC id (needed to match the response in an SSE stream) plus the classified method.
ResponseInfo
What the response frame told us. Sizes are measured over the canonical JSON of the result (or error) member — the payload a client would hand to its LLM as tool context.
ToolDef
One tool definition extracted from a tools/list response — the unit the inventory tracks. schema_sha256 is the rug-pull fingerprint: SHA-256 over the canonical JSON of the entire definition (name, description, input schema, annotations…), so any silent redefinition changes the hash.

Enums§

RequestKind
What an incoming JSON-RPC request frame asks for.

Functions§

analyze_response_json
Analyzes a plain application/json response body against the request id. None when the body is not a JSON-RPC response to that id (e.g. an unrelated notification) — the caller then books a generic event.
analyze_response_sse
Reassembles a buffered SSE body (text/event-stream) and finds the response to request_id among its events. MCP servers answer a POST either as plain JSON or as an SSE stream carrying the response (plus optional interleaved server requests/notifications) — this handles the latter after the proxy has teed the bytes through to the client.
canonical_json
Canonical JSON: objects recursively key-sorted, arrays in order, compact separators. Independent of serde_json’s preserve_order feature flag — the hash contract must not silently change with a dependency feature unification (#498: deterministic fingerprints).
parse_request
Parses a single JSON-RPC request frame from a POST body.
sha256_hex_of
Lowercase hex SHA-256 (shared convention with gateway keys / evidence).