Skip to main content

rcp — Retrieval Context Protocol, Python SDK

A native, pure-standard-library Python SDK for RCP — the open, versioned JSON-RPC protocol that lets any RAG engine expose embed / rerank / retrieve / graph / index / catalog, and any client consume it uniformly.

No dependencies, no compiler, no build step — just subprocess, http, socket, and json from the standard library. It speaks the exact same wire format as the C++, Node.js, and Rust SDKs, so a Python client and a C++/Node/Rust server (or vice-versa) interoperate byte-for-byte.

Install

pip install rcp-protocol

Requires Python ≥ 3.9. The import name is rcp:

import rcp

Client

Connect to any RCP server over a subprocess (stdio) or HTTP, then make typed, capability-gated calls.

import rcp

c = rcp.connect_stdio(["python3", "my_server.py"])
# or: c = rcp.connect_http("http://127.0.0.1:8000/rcp")

print(c.server(), c.protocol_version(), list(c.capabilities()))

if c.supports(rcp.Capability.Retrieve):
    for hit in c.retrieve("eiffel tower", k=3):
        print(hit["id"], hit["score"], hit["text"])

if c.supports(rcp.Capability.Embed):
    (vec,) = c.embed(["hello world"])
    print("dim", len(vec))

c.shutdown()

A call to a capability the server never advertised raises before any I/O:

try:
    c.rerank("q", ["a", "b"])
except rcp.RcpError as e:
    # e.code == rcp.Errc.CAPABILITY_MISSING  (-32003)
    ...

Client methods: embed, embed_sparse, embed_multi, rerank, retrieve, search (returns hits + usage + nextCursor), graph, transform, index_add, index_delete, catalog, info, ping, call, shutdown.

Server

Expose a Python RAG engine as an RCP server.

import rcp

s = rcp.Server()
s.set_info("my-engine", "1.0")
s.advertise(rcp.Capability.Retrieve, {"maxK": 100, "modes": ["hybrid"]})

@s.on(rcp.Method.RETRIEVE)
def _(params):
    hits = my_index.search(params["query"], params.get("k", 10))
    return {"hits": [{"id": h.id, "score": h.score, "text": h.text} for h in hits]}

s.serve_stdio()          # or: s.serve_http(8000)

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

Pick one engine from a registry — by id, by required capability, or by priority with liveness fallback. Connection is lazy.

sel = rcp.Selector.loads('''{
  "engines": [
    {"id": "docs", "transport": "stdio", "command": ["python3", "server.py"], "priority": 10},
    {"id": "web",  "transport": "http",  "url": "http://127.0.0.1:8000/rcp",   "priority": 5}
  ]
}''')

c = sel.select_capable(rcp.Capability.Retrieve)

Examples & tests

python3 examples/example_server.py            # stdio (default)
python3 examples/example_server.py --http 8000
python3 examples/example_client.py            # drives the example server

python3 test_bindings.py                      # smoke test incl. Python client ↔ C++ server

License

MIT © 2026 Ayush Bhat.

Metadata

Release files for rcp-protocol 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rcp-protocol 1.0.0
File Size Uploaded
rcp_protocol-1.0.0.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rcp-protocol 1.0.0
File Interpreter ABI Platform
rcp_protocol-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 kB

Release files / rcp_protocol-1.0.0.tar.gz

Download URL rcp_protocol-1.0.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
99ab282465be5f8a83a17a7c0c232116ded2fda0109f0292f65e1a38a1c9f706
BLAKE2b-256 checksum
How to use checksums
fc3927d2f3d75c16626e618505cdf33d332687828da6126b2374d8f6c70d5fa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / rcp_protocol-1.0.0-py3-none-any.whl

Download URL rcp_protocol-1.0.0-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10a6356aca85b3e9bfc31891ce20367e19a24ff72820f3dc8db833ca95ea445a
BLAKE2b-256 checksum
How to use checksums
f2478dbf0e41293ec31f79f7be1ceac975102e676655dd21efae64d2e658921f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.0.1

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page