rcp-protocol 1.0.1

Retrieval Context Protocol — native Rust SDK (zero dependencies)
Documentation
  • Coverage
  • 55.36%
    62 out of 112 items documented4 out of 29 items with examples
  • Size
  • Source code size: 113.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • 1ay1/rcp
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 1ay1

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

[dependencies]
rcp-protocol = { path = "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 rcp::Capability;

fn main() -> Result<(), rcp::RcpError> {
    let mut c = rcp::connect_stdio(&["python3", "my_server.py"])?;
    // or: let mut c = rcp::connect_http("http://127.0.0.1:8000/rcp")?;

    println!("{} (RCP/{})", c.server(), c.protocol_version());

    if c.supports(Capability::Retrieve) {
        for hit in c.retrieve("eiffel tower", 3)? {
            println!("{} {} {}", hit.id, hit.score, hit.text);
        }
    }

    if c.supports(Capability::Embed) {
        let vecs = c.embed(&["hello world"], None)?;
        println!("dim {}", vecs[0].len());
    }

    c.shutdown();
    Ok(())
}

The error carries the wire code and message (Display renders "[RCP <code>] <message>"):

match c.rerank("q", &["a", "b"]) {
    Err(e) => assert_eq!(e.code, rcp::Errc::CAPABILITY_MISSING), // -32003
    Ok(_) => {}
}

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 rcp::{obj, Capability, Json, Method, Server};

fn main() {
    let mut s = Server::new();
    s.set_info("my-engine", "1.0");
    s.advertise(Capability::Retrieve, obj(&[("maxK", 100.into())]));

    s.on(Method::RETRIEVE, |params| {
        let q = params.get_str("query").unwrap_or("");
        Ok(obj(&[("hits", search(q))]))
    });

    s.serve_stdio();          // or: s.serve_http(8000).unwrap();
}

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 = rcp::Selector::load("rcp.json")?;
let mut c = sel.select_capable(rcp::Capability::Retrieve)?;

Examples & tests

cargo run --example example_server            # stdio (default)
cargo run --example example_server -- --http 8000
cargo run --example example_client            # drives the example server

cargo test                                    # incl. Rust client <-> C++ server

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 rcp::{fusion, vectors, obj};
let a = vec![obj(&[("id", "x".into())])];
let b = vec![obj(&[("id", "x".into())]), obj(&[("id", "y".into())])];
let fused = fusion::rrf_fuse(&[("A", &a), ("B", &b)], Some(10), fusion::RRF_K_DEFAULT);

let enc = vectors::encode_f32_base64(&[1.5, -2.25, 0.0]);
let back = vectors::decode_f32_base64(&[enc], Some(3))?;

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.