rlm-mcp-server
v0.1.3
Published
Recursive Language Model as an MCP server: recursive long-context Q&A and a persistent Python kernel.
Maintainers
Readme
rlm-mcp-server
The Recursive Language Model as an MCP server. It answers a question over a context far larger than a model window by binding the context as a variable in a persistent Python kernel and letting the model decompose it with code, rather than following a fixed chunker.
Part of the harness monorepo.
Installation
npm install rlm-mcp-serverUsage
Run it over stdio, the transport a local host spawns:
RLM_MODEL=anthropic/claude-sonnet-5 RLM_SANDBOX=local npx rlm-mcp-serverSet RLM_MODEL to a provider/model string, with the matching provider key in the
environment. Any provider the Vercel AI SDK supports works. Without it, rlm_query
returns a stub answer so the server runs offline. RLM_SANDBOX=local (or docker)
enables the Python kernel; it runs code, so it stays off by default.
The same binary is a CLI, so a person or a shell-driven model can use it directly.
The installed command is rlm:
rlm store "a very large document ..." # prints a handle
rlm query "who led it?" --file report.txt # prints the answer
RLM_SANDBOX=local rlm exec "sum(range(100))" # runs Python in the kernel
rlm query "summarize" --file big.txt --deep # the kernel-backed RLMAny subcommand runs the CLI; no subcommand starts the MCP server, so hosts are unaffected.
The package is also a library:
import { Rlm, AiCompletion, FileContextStore, resolveModel, uuidGen } from 'rlm-mcp-server';
const rlm = new Rlm(new AiCompletion({ model: resolveModel('anthropic/claude-sonnet-5') }), new FileContextStore('.contexts', uuidGen));
const { answer } = await rlm.query({ question: 'who led it?', context: veryLargeText });Tools
| Tool | Purpose |
| ------------------- | ------------------------------------------------------------ |
| rlm_store_context | Store a large context and get a handle |
| rlm_query | Answer a question over a context by chunking and synthesizing |
| python_exec | Run Python in a persistent kernel (needs RLM_SANDBOX) |
| rlm_deep_query | Answer by exploring the context as a variable in the kernel (needs RLM_SANDBOX and a model) |
Two ways to recurse
rlm_query chunks the context by size and synthesizes, which needs no sandbox. It is
the map-reduce baseline, useful when no kernel is available.
rlm_deep_query is the RLM. It binds the context as PROMPT in a live kernel and the
model decides how to decompose it, following three mechanisms from the paper:
python_execreturns only a bounded prefix of stdout plus its length, so reading a large slice never floods the model window. The value stays in the kernel.- A sub-call at depth
dspawns a child RLM at depthd+1, down to a flat model call at the ceiling. Set the ceiling withRLM_MAX_DEPTH(default 1). - The model can assign its answer to a
FINALvariable in the kernel, so the answer can exceed the model's output window.
On the local adapter an in-kernel rlm(question, text) calls back to the model over a
loopback socket. Isolated adapters (docker, Cloudflare) use the recurse tool
instead, which reaches the model from the host.
Structure
The RLM code depends only on the contracts in each domain, so the pieces that differ between local and Cloudflare sit behind one seam.
src/
rlm/ recursive query over a large context
completion/ Completion port, AiCompletion (Vercel AI SDK), StubCompletion
storage/ ContextStore port, FileContextStore (local), R2ContextStore (Cloudflare)
sandbox/ SandboxProvider: local process, docker, Cloudflare
server.ts builds the MCP server and tools, transport agnostic
local.ts stdio entrypoint remote.ts http entrypoint
index.ts public API