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§
- Tool
Call Request - 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_errorplus the machine-readable denial code inerror.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
idfor an error response, per JSON-RPC 2.0 §5: the responseidMUST echo the request’s when it is detectable, and benullonly “if there was an error in detecting the id” (parse error / invalid request).RpcError::NotToolCallandRpcError::BadParamsboth mean the envelope parsed as a well-formed JSON-RPC 2.0 object, so the id IS detectable — replyingnullbroke client correlation (a pendinginitializecall hung until timeout because its error response carriedid: null). Parse-class failures (invalid JSON, duplicate keys, oversize, non-2.0 envelope) keepnull: 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.