Skip to main content

trusty_code/jsonrpc/
mod.rs

1//! JSON-RPC 2.0 core: wire types, error codes, and the method router (#2053).
2//!
3//! Why: `tcode serve` must speak the exact same JSON-RPC-over-STDIO contract
4//! as the rest of the trusty-* family so tooling (CLI clients, MCP bridges,
5//! future TUI/GUI frontends) has one dispatch convention to learn. Re-using
6//! `trusty_common::mcp`'s wire types — rather than hand-rolling a second,
7//! structurally-identical `Request`/`Response`/`JsonRpcError` — is the
8//! ecosystem-consistent choice: `trusty-search` (`mcp::stdio::run`) and
9//! `trusty-memory` (`commands::serve_stdio_bridge::run_stdio_bridge`) both
10//! already build on it, and its own module doc explicitly exists to prevent
11//! "bug-fixed-in-one-not-the-other" drift between servers.
12//!
13//! What tcode adds on top is new: a [`Router`] that maps method names to
14//! async handlers via a registry rather than a single hand-written `match`.
15//! trusty-memory/trusty-search dispatch through one large `match` because
16//! their method surface is fixed; tcode's is not — later tickets register
17//! `session.*` (#2054), `task.*` (#2056), and `harness.describe` (#2066)
18//! methods, and a registry lets each land as an isolated `router.register(...)`
19//! call instead of growing one match arm-by-arm. [`RpcError`] is the typed
20//! error a handler returns; the router converts it into the JSON-RPC error
21//! envelope.
22//!
23//! `#2054` adds [`context::ConnectionContext`]: every handler now also
24//! receives the calling connection's context, which is how `session.attach`
25//! pushes server-initiated notifications (session lifecycle events) back to
26//! that connection asynchronously, outside the normal request/response
27//! cycle — see `context`'s module docs for the STDIO-vs-HTTP distinction.
28//!
29//! Test: see `error::tests`, `router::tests`, and `context::tests`.
30
31pub mod context;
32pub mod error;
33pub mod router;
34
35pub use context::{ConnectionContext, NotifySender};
36pub use error::RpcError;
37pub use router::{MethodHandler, Router};
38pub use trusty_common::mcp::{Request, Response, error_codes};