rcp — Retrieval Context Protocol, Rust SDK
A native, zero-dependency Rust SDK for RCP —
the open, versioned JSON-RPC protocol that lets any RAG engine expose embed,
rerank, retrieve, graph, index, and catalog, and any client consume it
uniformly.
Built entirely on the Rust standard library — no dependencies (like the C++
SDK vendors json.hpp, this crate vendors a minimal JSON value type). It speaks
the exact same wire format as the C++, Python, and
Node.js SDKs, so a Rust client and a C++/Python/Node server (or
vice-versa) interoperate byte-for-byte. Synchronous and blocking; every call
returns Result<_, RcpError>.
Add it
[]
= { = "sdk/rust" } # or a git/version dependency
The crate is imported as rcp. Requires Rust 1.70+.
Client
Connect over a subprocess (stdio) or HTTP, then make typed, capability-gated
calls. A call to a capability the server never advertised returns
Err(CapabilityMissing) before any round-trip.
use Capability;
The error carries the wire code and message (Display renders "[RCP <code>] <message>"):
match c.rerank
Client methods: embed, embed_sparse, embed_multi, rerank, retrieve,
search (returns SearchResult { hits, usage, next_cursor }), graph,
transform, index_add, index_delete, catalog, info, ping, call,
shutdown.
Server
Handlers are FnMut(&Json) -> Result<Json, RcpError>.
use ;
The Server owns the initialize handshake, capability gating, JSON-RPC framing
and batching, and error mapping. It answers initialize / info / ping /
shutdown itself; a gated call before initialize is -32001, an unadvertised
or unimplemented method is -32003, an unknown method is -32004.
Selecting a backend
let sel = load?;
let mut c = sel.select_capable?;
Examples & tests
The JSON value type
rcp::Json is a small, ordered JSON value with parse, Display/dump,
get/get_str/as_* accessors, insert/push, and From impls, plus the
rcp::obj(&[(key, value)]) builder. It exists so the SDK stays dependency-free;
you never need serde to speak RCP.
License
MIT © 2026 Ayush Bhat.