Skip to main content
Glama
chetan1521

grounded-rag-mcp

by chetan1521

grounded-rag-mcp

An MCP server that gives any LLM host grounded, cited retrieval over your own documents — hybrid retrieval (BM25 + dense), cross-encoder reranking, citations, and a built-in eval harness.

Point it at a folder of documents. Your MCP host (Claude Desktop, an IDE, a custom agent) can then search and answer over them — grounded in the real text, with citations, and an honest "not in the documents" path.

CI


Why

Most RAG-over-MCP examples are toys. This one is built production-flavored:

  • Hybrid retrieval — BM25 (exact terms) + dense (semantics), fused with Reciprocal Rank Fusion.

  • Cross-encoder reranking — precision on the top candidates without blowing latency.

  • Grounding + citations — answers cite their sources; if the answer isn't in the docs, it says so.

  • Built-in eval — measure retrieval quality (recall@k, MRR, hit-rate), not just vibes.

  • Local-first — the default path runs with no external services or API keys.

  • Both transports — stdio and Streamable HTTP.

Related MCP server: insight-mcp

Status

🚧 Early development. Building in public, phase by phase (see PROJECT_REQUIREMENTS.md).

  • Phase 0 — scaffold, packaging, CI

  • Phase 1 — core retrieval (chunk → embed → BM25 + dense → RRF)

  • Phase 2 — MCP server (stdio) with ingest / search

  • Phase 3 — rerank + grounding + answer (via MCP sampling)

  • Phase 4 — tests, types, docs, resource + prompt

  • Phase 5 — Streamable HTTP transport + evaluate_retrieval

  • Phase 6 — publish to PyPI

Install

pip install grounded-rag-mcp            # lean, local-first default (no torch)
pip install "grounded-rag-mcp[st]"      # + sentence-transformers for semantic embeddings & reranking

Tools

Tool

What it does

ingest_documents

Chunk, embed, and index files or raw text into a named collection

search

Hybrid / dense / bm25 retrieval, optional rerank, per-stage scores

answer

Grounded, cited answer via MCP sampling; refuses when nothing is found

list_collections

List collections and chunk counts

evaluate_retrieval

hit_rate / MRR / recall@k on labeled cases

Also exposes a resource (rag://collections) and a prompt (grounded_answer).

Use it with an MCP host (e.g. Claude Desktop)

Add to your host's MCP config:

{
  "mcpServers": {
    "grounded-rag": {
      "command": "grounded-rag-mcp"
    }
  }
}

Or run it directly:

grounded-rag-mcp            # stdio (default, for local hosts)
grounded-rag-mcp --http     # Streamable HTTP on 127.0.0.1:8000 (remote / multi-client)

Use the retrieval engine as a Python library

from grounded_rag_mcp.collection import Collection
from grounded_rag_mcp.embeddings import HashingEmbedder
from grounded_rag_mcp.ingest import load_texts
from grounded_rag_mcp.config import RetrievalConfig

col = Collection("kb", HashingEmbedder(dim=512))
col.add(load_texts(["The refund policy allows returns within 30 days of purchase."]))

for hit in col.retrieve("refund policy", RetrievalConfig(top_k=1)):
    print(hit.chunk.source, hit.score, hit.stage_scores)

Development

pip install -e ".[dev]"
ruff check . && ruff format --check . && mypy src && pytest -q

See docs/ARCHITECTURE.md, docs/BUILD_STORY.md, and PUBLISHING.md.

License

MIT © Chetan C

Available Tools

5 tools
answerA

Answer a question grounded in a collection, with citations.

Retrieves the most relevant passages and asks the host's model (via MCP sampling) to answer using ONLY those passages, citing them. Returns {grounded, answer, citations}. If nothing relevant is found, grounded is false and no answer is invented. If the host does not support sampling, the grounded context is returned for the host to compose the answer itself.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes
top_kNo
collectionNodefault

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does so admirably. It discloses the MCP sampling mechanism, the exact return shape (`{grounded, answer, citations}`), the no-invention behavior when nothing relevant is found, and the fallback to returning grounded context when sampling is unsupported.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded, stating the core purpose first, then explaining the mechanism, return format, and fallbacks. Every sentence adds meaningful information with no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description thoroughly covers the tool's behavior, return values, and edge cases, making it largely complete for selection and invocation. It is missing parameter-level explanation for `top_k` and `collection`, but the presence of an output schema and the tool's relatively focused scope keep the gap minor.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description does not explain the `top_k` or `collection` parameters at all. While `query` is self-evident from the description's reference to a question, the other two parameters are left undocumented in both the schema and the description, so the description fails to compensate for the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Answer a question grounded in a collection, with citations.' It clearly differentiates itself from sibling tools like `search` by emphasizing grounded, citation-backed answers rather than raw retrieval.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly implies when to use the tool—when a grounded, cited answer is needed—and explains fallback behavior when sampling is unsupported. It does not explicitly name alternatives or exclusion criteria, but the behavioral context is strong enough for an agent to select it appropriately.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

evaluate_retrievalA

Measure retrieval quality on labeled cases: hit_rate, MRR, and recall@k.

Each case is {query, relevant_sources}. Use this to quantify quality and catch regressions — e.g. before and after changing chunking or switching embedders.

ParametersJSON Schema
NameRequiredDescriptionDefault
modeNohybrid
casesYes
top_kNo
collectionNodefault

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry behavior disclosure. It conveys that the tool measures/evaluates rather than mutates, but it does not explicitly state whether it runs live retrievals against a collection, requires an existing collection, or has side effects. This is adequate but leaves some operational behavior implicit.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two compact sentences: the first states purpose and metrics, the second defines the case structure and provides usage context. Every sentence earns its place with no redundancy or filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With an output schema present, return values do not need to be described. The description covers purpose, case format, and usage context, but leaves mode/top_k/collection semantics and behavioral details to the schema or inference. This is adequate for a moderately complex tool, but not fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains the shape of cases as `{query, relevant_sources}` and implicitly connects top_k to recall@k, but it does not explain mode (hybrid/dense/bm25) or collection beyond their enum/default values. The partial compensation keeps it at an adequate 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Measure retrieval quality on labeled cases' and names the concrete metrics hit_rate, MRR, and recall@k. This clearly distinguishes the tool from sibling tools like search (actual retrieval) or answer (generation), establishing it as an evaluation utility.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says when to use it: 'Use this to quantify quality and catch regressions — e.g. before and after changing chunking or switching embedders.' It provides clear context and examples, though it does not mention when not to use it or name alternative tools explicitly.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

ingest_documentsA

Ingest documents into a named collection so they can be searched.

Provide paths (files or directories of .txt/.md) and/or texts (raw strings). Documents are chunked, embedded, and indexed for both semantic and keyword search. Returns how many chunks were added and the collection's new total.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathsNo
textsNo
chunk_sizeNo
collectionNodefault
chunk_overlapNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and discloses the main behavioral pipeline: chunking, embedding, and indexing for semantic and keyword search. It also states the return value (chunks added and new total), which adds useful non-obvious information.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four short, front-loaded sentences with no filler. The key action and purpose appear first, followed by the input options, processing behavior, and return value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the main inputs, processing steps, and return output, and an output schema exists for return details. It could mention collection creation behavior or defaults for chunking parameters, but it is sufficiently complete for an agent to call this tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description compensates partially for 0% schema coverage by explaining paths and texts, including allowed file extensions and directories. However, it does not explain the semantics of chunk_size, chunk_overlap, or collection beyond vague references to chunking and a named collection.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (ingest), the resource (documents into a named collection), and the purpose (so they can be searched). It distinguishes this tool from sibling read/search tools by framing it as the ingestion-side counterpart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives clear context for when to use this tool: before searching, by adding documents to a collection. It also explains the two accepted input modes (paths and/or texts), but it does not explicitly name alternatives or say when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_collectionsA

List all ingested collections and how many chunks each contains.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the transparency burden, and 'List' plus 'how many chunks each contains' conveys a read-only aggregation-style operation with no side effects. It does not explicitly mention caveats like ordering or rate limits, but for a parameterless listing tool the core behavior is clear.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Exactly one sentence with no filler; the key verb, scope, and output are front-loaded. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is a simple parameterless listing operation with an output schema available, and the description specifies both the scope and the per-item chunk count. No prerequisite or return-shape detail is missing for an agent to invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero properties and 100% coverage, so there are no parameter semantics to document. The description adds useful scope information ('ingested,' 'each') that clarifies what the empty parameter list returns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the specific verb 'List' with a clear resource, 'all ingested collections,' and specifies the returned information ('how many chunks each contains'). This is unambiguous and distinguishes it from sibling tools like ingest_documents and search.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for inspecting ingested collections, but it does not explicitly state when to choose it over alternatives. The phrase 'ingested collections' signals it is relevant after ingestion, but there is no direct when/when-not guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 5 tool updatesv0.1.0
    • First observedanswer
    • First observedevaluate_retrieval
    • First observedingest_documents
    • First observedlist_collections
    • First observedsearch

TDQS

A4.2/5.0

Scored across 5 tools

Disambiguation5/5

Each tool targets a distinct operation: ingestion, search, grounded answering, collection listing, and retrieval evaluation. There is no overlap in purpose, and descriptions clearly delineate when to use each.

Naming Consistency4/5

Tool names follow a clear imperative, snake_case style. Most use verb_noun (ingest_documents, list_collections, evaluate_retrieval), though search and answer are bare verbs rather than verb_noun, creating a minor inconsistency.

Tool Count5/5

Five tools is well-scoped for a grounded RAG server: ingest, search, answer, list collections, and evaluate retrieval. Each tool covers a necessary part of the workflow without redundancy or bloat.

Completeness4/5

Core RAG workflows are covered end-to-end, including ingestion, retrieval, grounded answering, and quality evaluation. The main gap is lifecycle management: there is no way to delete or update documents or collections once ingested.

Maintenance

ActivityNo data
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    B
    maintenance
    Enables any MCP-compatible AI assistant to search, filter, and retrieve information from a local document collection using a hybrid search pipeline with vector, BM25, reranking, and LLM enrichment.
    4
    -
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables hybrid document search (BM25 and dense) over a configurable corpus via MCP tools, returning passages and sources for AI agents to cite in answers.
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables agent tools like Claude Code and GitHub Copilot to perform knowledge retrieval using hybrid search (BM25 + dense) with reranking, via MCP protocol.
    -