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, feedback, memory_build,
memory_recall, catalog, info, ping, call, shutdown.
Agentic & frontier RAG
The full 2024–2026 RAG surface is typed. retrieve opts carry unit / level
(granularity), tokenBudget (long-context packing), and sessionId (agentic
trajectories); each Hit surfaces confidence, unit, level, scores,
provenance, and trust (plus raw for anything else). feedback sends
RL / corrective / integrity signals back to the retriever (spec §7.16), and
memory_build / memory_recall drive MemoRAG / HippoRAG memory → clues
(spec §7.17). All three are capability-gated (Capability::Feedback,
Capability::Memory, Capability::Session).
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
Federation fusion & the vector codec
The reference Reciprocal Rank Fusion (spec §16.3) and the compact f32-base64
embedding codec (§7.3.1) are standalone, tested modules — byte-for-byte identical
to the Python / Node / C++ SDKs:
use ;
let a = vec!;
let b = vec!;
let fused = rrf_fuse;
let enc = encode_f32_base64;
let back = decode_f32_base64?;
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.