RAGDial MCP

RAGDial MCP is a RAG retrieval ablation & chunking lab, packaged as an MCP server. It turns an AI coding assistant (Claude Code, Cursor, Claude Desktop) into a systematic retrieval tuner. Instead of guessing chunk sizes and overlaps, the agent runs controlled experiments, looks at exactly which tables and code blocks got cut in half, and picks a pipeline using Recall@k, MRR, nDCG@k and p95 latency.
ingest_corpus → run_chunking_ablation → inspect_boundary_splits → benchmark_retrieval → diff_experiment_runs
Everything runs locally: no API keys and no paid services. On the bundled benchmark pack, the full loop takes about 4 seconds on a laptop.
A real run of ragdial-demo, captured with its colours and rendered by scripts/make_demo_gif.py. Orange = fixed-size chunking, blue = header-aware chunking.
Quick start (under 2 minutes)
You need uv and nothing else; uv fetches Python 3.11+ if it's missing.
Add it to Claude Code:
claude mcp add ragdial -- uvx ragdial-mcp
Then ask: "Ingest @sample, ablate fixed vs markdown chunking at 256/512 tokens, show me which tables got split, and benchmark against @sample." The @sample shortcut points the tools at the bundled 13-document benchmark pack and its 30 golden questions. Point ingest_corpus at your own docs folder when you're ready.
See the whole loop in your terminal, no agent needed:
uvx --from ragdial-mcp ragdial-demo
Work on the code:
git clone https://github.com/Salman-khann/RAGDial-MCP.git
cd RAGDial-MCP
uv sync # core deps: MCP SDK, tiktoken, rank-bm25, numpy
uv run ragdial-demo # full before/after loop on sample_data/ (about 4 s)
uv run pytest # 32 deterministic tests, no downloads
To run the latest unreleased main instead of the PyPI release, use uvx --from git+https://github.com/Salman-khann/RAGDial-MCP ragdial-mcp.
What the demo shows (the numbers in the GIF above):
| Chunker |
Tables cut in half |
Damage |
Best search |
Recall@5 |
MRR |
nDCG@5 |
| fixed-256 (every 256 tokens) |
12 of 14 |
0.30 |
BM25 |
0.82 |
0.73 |
0.742 |
| markdown-256 (header-aware) |
5 of 14, header row repeated |
0.04 |
BM25 |
0.98 |
0.91 |
0.926 |
Header-aware chunking answers 5 more of the 30 questions (q01, q06, q10, q12, q19) and breaks none.
To use real models (BAAI/bge-small-en-v1.5, the BAAI/bge-reranker-base cross-encoder, and ChromaDB):
uvx --from "ragdial-mcp[ml]" ragdial-demo --embedder bge-small --reranker bge-reranker-base
The same before/after comparison with real models (measured on a laptop CPU, no GPU):
| Variant |
Recall@5 |
MRR |
nDCG@5 |
p95 per query |
| markdown-256, dense + bge reranker |
0.983 |
0.950 |
0.950 |
13.2 s |
| fixed-256, dense + bge reranker |
0.833 |
0.767 |
0.779 |
16.8 s |
Five queries flip from miss to hit and none regress. Note the latency: the cross-encoder reranker is very slow on CPU. That's exactly the trade-off generate_rag_spec weighs against a latency budget.
Connect it to an agent
Claude Code:
claude mcp add ragdial -- uvx ragdial-mcp
# with real models:
claude mcp add ragdial -- uvx --from "ragdial-mcp[ml]" ragdial-mcp
Inside a clone, the project-scoped .mcp.json also offers the ragdial server automatically, running your local checkout.
Cursor / Claude Desktop (mcpServers entry):
{ "ragdial": { "command": "uvx", "args": ["ragdial-mcp"] } }
Remote / container (Streamable HTTP on http://localhost:8000/mcp):
uv run ragdial-mcp --transport streamable-http --port 8000
# or
docker build -t ragdial-mcp . && docker run --rm -p 8000:8000 -v ragdial:/data ragdial-mcp
Inspect the schemas with the MCP Inspector:
npx @modelcontextprotocol/inspector uv run ragdial-mcp
Then ask the agent something like: "Ingest sample_data/corpus, ablate fixed/recursive/markdown/semantic at 128/256/512 with 0 and 64 overlap, show me the worst table splits, benchmark against sample_data/golden_qa.jsonl and tell me which config to ship."
Local or hosted?
RAGDial does its work (parsing, chunking, embedding, ranking) in its own process, so whoever runs that process supplies the CPU, RAM and disk. The AI model only receives the compact JSON results.
Run it locally (the default, recommended for most people). Your MCP client starts ragdial-mcp on your machine over stdio, as set up in .mcp.json and the quick start.
- Your documents never leave your machine. Only metric summaries and short excerpts reach the model.
ingest_corpus reads any folder on your disk directly, with no upload step.
- There's no server to pay for and no account or API key to manage.
- The core mode is light: the full sample loop runs in seconds. Expect real CPU and RAM use only with the
ml extra. Its models total about 1.3 GB on disk, and the cross-encoder reranker is slow on CPU but uses an NVIDIA GPU automatically if PyTorch finds one.
Host it as a shared server when one of these applies:
- Heavy models on weak laptops: a GPU server runs
bge-reranker-base many times faster than a laptop CPU.
- Teams: everyone shares one experiment history and can diff each other's runs.
- Large corpora: tens of thousands of documents need more memory and time than a laptop comfortably gives.
- Zero install for users: people connect with a URL instead of installing uv and Python.
docker build -t ragdial-mcp:ml --build-arg EXTRAS=ml .
docker run -d -p 8000:8000 --gpus all \
-v ragdial:/data \
-v /srv/corpora:/corpora:ro \
ragdial-mcp:ml
# clients connect to http://<host>:8000/mcp and ingest e.g. folder_path="/corpora/my-docs"
Drop --gpus all on a machine without an NVIDIA GPU.
Keep in mind when hosting:
- Paths are server paths.
ingest_corpus reads folders on the server, so mount the document folders into the container (read-only, as above).
- There is no built-in authentication. Anyone who can reach the port can run experiments and read any folder the container can see. Keep it on a private network or behind a reverse proxy that handles auth and TLS. Never expose it directly to the internet.
- Data in
/data is shared by all users of that server: corpora, runs and reports.
|
Local (stdio) |
Hosted (Streamable HTTP) |
| Who pays for compute |
Each user's machine |
The server |
| Where documents live |
User's disk |
Mounted on the server |
| Setup per user |
Install uv, clone or uvx |
Paste a URL |
| Experiment history |
Per user (~/.ragdial) |
Shared (/data) |
| GPU for reranking |
Only if the user has one |
Provision once on the server |
| Access control |
Your OS account |
Your network or reverse proxy (none built in) |
MCP surface
Tools (model-driven actions)
| Tool |
Key parameters |
Returns |
ingest_corpus |
folder_path, corpus_id |
File count, total tokens, detected headers/tables/nested tables/code/lists, document IDs |
run_chunking_ablation |
corpus_id, strategies[], chunk_sizes[], overlaps[], embedder |
Per config: chunk count, token p50/p95/max, boundary-damage score, severed/total per structure kind |
inspect_boundary_splits |
run_id, limit=5, config_id, kinds[] |
Excerpts of about 110 characters on each side of every cut through a table, code fence, list or paragraph |
benchmark_retrieval |
run_id, dataset_path, retrievers[], reranker, top_k, configs[], embedder, vector_store |
Recall@k, MRR, nDCG@k, hit rate, p50/p95 latency per chunk config × retriever, plus the 3 worst queries |
diff_experiment_runs |
run_a, run_b, variant_a, variant_b |
Metric deltas (B − A), query IDs that flipped miss→hit or regressed, and rank-movement counts |
Resources (read-only context)
| URI |
Content |
ragdial://experiments |
Index of corpora and runs with configs, timestamps and headline metrics |
ragdial://experiments/{run_id}/report |
Full JSON: every variant and the per-query hit/miss table with top chunk IDs |
ragdial://corpus/{corpus_id}/stats |
Document metadata, token counts and structural breakdown |
Prompts (user-triggered workflows)
| Prompt |
What it makes the agent do |
diagnose_retrieval_failures(run_id) |
Pull the worst queries from the report, run inspect_boundary_splits, classify each miss (boundary damage / ranking / vocabulary / dilution), test one targeted fix and confirm it with diff_experiment_runs |
generate_rag_spec(corpus_id, latency_budget_ms) |
Drop variants over the p95 budget, rank the rest by nDCG → recall → damage → latency, and emit a YAML production spec that cites the supporting run IDs |
Context-window discipline, by design
Each tool returns a typed Pydantic model (exposed as an MCP outputSchema with structuredContent) holding metric tables, IDs and a next_step hint. No tool returns chunk text. The only text that reaches the model is the clipped excerpts from inspect_boundary_splits, at most 25 of them. Full per-query detail sits behind ragdial://experiments/{run_id}/report, and the agent reads it only for the queries it is investigating. A 48-config ablation costs a few KB of context, not a few MB.
How it measures things
Chunkers (chunking/strategies.py)
Each chunker records the exact source span (start/end character offsets) of every chunk, which is what makes the boundary audit exact.
| Strategy |
Behaviour |
fixed |
Sliding windows of exactly size tiktoken tokens, overlap tokens shared |
recursive |
Recursive splitting on paragraph → line → sentence → clause → word, greedily merged up to size |
markdown |
Header-aware: never crosses a section, keeps tables/code/lists atomic when they fit, splits oversized tables by rows with the header row replicated, prefixes every chunk with its breadcrumb (Doc > Section > Subsection) |
semantic |
Embeds sentences/blocks and breaks where adjacent similarity falls in the bottom quartile, capped at size |
Boundary damage (chunking/boundary_audit.py)
A structure is severed when no single chunk contains it whole, so overlap that keeps a full copy somewhere rescues it. The damage score is the weighted share of severed structures (tables and code ×3, lists ×1.5, paragraphs ×1). A severed table whose pieces all carry the header row counts as mitigated at half weight. Every severed item also records whether it was oversized, meaning bigger than the chunk size and so impossible to keep intact.
Retrieval (retrieval/hybrid.py)
bm25: Okapi BM25 via rank-bm25
dense: cosine similarity in an ephemeral ChromaDB collection per experiment (or an in-memory NumPy index without the ml extra)
hybrid: Reciprocal Rank Fusion (k = 60) of the top 50 from BM25 and the top 50 from dense
- optional cross-encoder reranking (
bge-reranker-base) of the top 20 fused candidates
Latency is measured per query (query embedding + search + rerank) after a warm-up query, and reported as p50/p95.
Ground truth that can't be fooled by chunking (retrieval/metrics.py)
Golden queries reference evidence snippets quoted verbatim from the corpus, not chunk IDs. Chunk IDs change with every config, so they can't serve as ground truth. A chunk is relevant only if it contains every snippet of an evidence group:
{"id": "q09", "question": "What does extra storage cost per GB-month on the Business plan?",
"evidence": ["| Feature | Developer | Starter | Growth | Business | Enterprise |",
"| Storage overage per GB-month | n/a | $0.10 | $0.08 | $0.05 | custom |"]}
A chunk holding the price row without the column header can't say which plan $0.05 belongs to, and the metric scores it as a miss. Splitting a table therefore shows up as a measurable retrieval failure. Queries can also carry several evidence_groups, for answers that span documents. Recall@k is then the share of groups covered.