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§
- Parsed
Request - A parsed request frame: the JSON-RPC id (needed to match the response in an SSE stream) plus the classified method.
- Response
Info - What the response frame told us. Sizes are measured over the canonical
JSON of the
result(orerror) member — the payload a client would hand to its LLM as tool context. - ToolDef
- One tool definition extracted from a
tools/listresponse — the unit the inventory tracks.schema_sha256is 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§
- Request
Kind - What an incoming JSON-RPC request frame asks for.
Functions§
- analyze_
response_ json - Analyzes a plain
application/jsonresponse body against the request id.Nonewhen 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 torequest_idamong 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_orderfeature 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).