Skip to main content

Module rpc

Module rpc 

Source
Expand description

JSON-RPC 2.0 / MCP tools/call parsing. Total: never panics on arbitrary bytes (property-tested), returns typed errors for every malformed shape.

Structs§

ToolCallRequest
A parsed MCP tool-call request.

Enums§

RpcError
Parse failures.

Constants§

MAX_JSON_DEPTH
Depth bound applied post-parse (deeply nested JSON as a DoS vector).
MAX_PAYLOAD_BYTES
Hard byte bound applied before parsing (attacker-controlled input).

Functions§

authorization_error
Build the JSON-RPC error response for a blocked call (the “immediate authorization error back to the agent loop” from the brief).
denial_error
authorization_error plus the machine-readable denial code in error.data.code, so an agent can branch on the code without parsing the reason text.
depth_of
Compute the maximum nesting depth of a JSON value. Exposed so callers outside this crate (chat-completions ingress and any admin body parser) can apply the same trust-boundary depth cap without duplicating logic.
detectable_error_id
Recover the request id for an error response, per JSON-RPC 2.0 §5: the response id MUST echo the request’s when it is detectable, and be null only “if there was an error in detecting the id” (parse error / invalid request). RpcError::NotToolCall and RpcError::BadParams both mean the envelope parsed as a well-formed JSON-RPC 2.0 object, so the id IS detectable — replying null broke client correlation (a pending initialize call hung until timeout because its error response carried id: null). Parse-class failures (invalid JSON, duplicate keys, oversize, non-2.0 envelope) keep null: the id is absent, ambiguous, or untrustworthy there.
parse_tool_call
Parse raw bytes as an MCP tools/call.
protocol_error
JSON-RPC 2.0 reserves -32700 (parse error), -32600 (invalid request), and -32602 (invalid params) for requests that never reached application logic. Reporting those as -32001 “blocked by policy” (with HTTP 403) falsely told clients an authorization decision was made about a request that never parsed.
refuse_duplicate_json_keys
The general-purpose duplicate-key rejection primitive, exposed for callers outside this crate (chat completions ingress, admin body parsers) that want the same trust-boundary “refuse ambiguous JSON” semantics without pulling in RpcError.