agentic-rag-mcp

Semantic search over your own documents, for agents that search more than once.

PyPI version CI status Python 3.11+ MCP 2.3 MIT licence

Start in one line

uvx agentic-rag-mcp serve --docs ~/notes

Or add it to Claude Code:

claude mcp add notes -- uvx agentic-rag-mcp serve --docs /absolute/path/to/notes

Or to Claude Desktop, in claude_desktop_config.json:

{
  "mcpServers": {
    "notes": {
      "command": "uvx",
      "args": ["agentic-rag-mcp", "serve", "--docs", "/absolute/path/to/notes"]
    }
  }
}

It indexes every .md, .txt and .rst file under the folder and hands the client three search tools. Leave out --docs and it serves a small bundled demo corpus, so you can try it before pointing it at anything of yours.

The first search downloads a 90 MB embedding model once. To do that, and build the index, before a client is waiting on it:

uvx agentic-rag-mcp index --docs ~/notes

Why agentic retrieval

Naive RAG searches once: embed the question, take the top few chunks, answer. That works until a question has two parts living in two places. "How do I authenticate after the 3.0 change, and is the old way still supported?" needs the migration guide and the changelog, and a single top-k search often returns one and misses the other.

Agentic RAG gives the model the search tool instead. It searches, reads what came back, notices that half the question is still open, and searches again with a sharper query.

The client is the agent

Through MCP, Claude does the searching itself. This server needs no API key: it answers searches and nothing else.

Indexing stays local

Embeddings run on your machine through ONNX Runtime. No document is uploaded to build or search the index.

No PyTorch

The same all-MiniLM-L6-v2 model, with vectors identical to sentence-transformers, at a fraction of the install. The whole environment measures 308 MB.

Fast to restart

Embeddings are cached on disk, keyed by a hash of every chunk, so a stale vector is never served and an unchanged corpus loads instantly.

Indexing is local, but answering is not: the chunks an agent reads become part of its conversation, and so reach whichever model provider the client uses.

Measured, not asserted

Does one search actually miss things? Nine questions over the demo documents, each listing the facts a complete answer needs. A fact counts as retrieved if its phrase appears in a retrieved chunk from the right document. Whether a question needs more than one chunk is computed from the real chunking, not declared.

At two chunks per search, over the 10-chunk index:

StrategyRecall2+ chunk questions 1 chunk questionsCompleteChunks read
One search79.6%79.2%80.0%5/92.0
One search, twice the chunks85.2%79.2%90.0%6/94.0
Question split at commas79.6%79.2%80.0%5/93.0
Planned sub-queries88.9%87.5%90.0%7/92.8

What it shows

Small numbers. Nine questions over a 10-chunk corpus show the method, not a benchmark. At 4 chunks per search a single query already reads 40% of the corpus, so the strategies stop being distinguishable.

Run it yourself. CI reruns it on every push and posts the table to the run summary.

agentic-rag-mcp eval -k 2
agentic-rag-mcp eval -k 2 --agent    # also score a real agent's searches (makes API calls)

Three tools, all read-only

ToolWhat it returns
kb_search(query, k=4) The chunks closest in meaning to the query, each with a cosine score, its source document and a chunk_id to cite.
kb_fetch(chunk_id)The full text of one chunk.
kb_sources()The indexed documents and the size of the index.

Every tool publishes an output schema, so clients get validated structured results rather than a string to parse. Mistakes an agent can fix, such as an empty query or an unknown chunk id, come back with an explanation it can act on instead of a bare "error executing tool".

Built-in agents, if you want them

The package also runs the agents itself, with an Anthropic API key:

pip install "agentic-rag-mcp[agents]"

agentic-rag-mcp ask "How do I authenticate a SqlSource after 3.0, and is the old way still supported?"
agentic-rag-mcp ask --naive "..."      # one search, one model call: the fair baseline
agentic-rag-mcp ask --pipeline "..."   # retriever, synthesizer, verifier

The agent loop is one short function, written by hand so the control flow can be read. It runs Claude Opus 5.5 with adaptive thinking and an explicit effort level, caches the growing conversation, and stops loudly: a refusal, running out of tokens or hitting the turn limit raises an error rather than handing on a placeholder as if it were an answer.

The pipeline is a fixed workflow, not a swarm: a retriever gathers evidence, a synthesizer drafts, and a verifier with structured output sends unsupported claims back for revision. For a task this well shaped, a script is more predictable and cheaper than agents spawning agents.

Honest limitations

Documentation