Skip to main content
Glama

mcp-rag: Semantic RAG served over the Model Context Protocol

A semantic Retrieval-Augmented Generation engine, exposed as an MCP server so any MCP client (Claude Desktop, an IDE agent, …) can search and question a knowledge base as a native tool.

 documents ─▶ chunk ─▶ embed ─▶ index ─┐
                                        ├─▶ hybrid retrieval ─▶ grounded answer
 query ─────────────────────────────────┘   (semantic + BM25,     with citations
                                              fused by RRF)              │
                                                                         ▼
                                                    MCP server ─▶ any MCP client

The whole thing runs offline out of the box, local LSA embeddings + an extractive, citation-grounded answerer, with zero API keys or model downloads. Production backends (Voyage / OpenAI / sentence-transformers for embeddings, Anthropic / OpenAI for generation) are a one-line config switch.

Demo corpus: a self-contained fictional SaaS knowledge base ("Nimbus", a cloud data platform): authentication, billing, rate limits, data retention, security, incident runbook, webhooks, SDK. Nothing copyrighted; every answer is traceable to a source.


What it does

Ask a question phrased in your own words and get an answer grounded in the docs:

$ python scripts/demo_query.py "what happens if I go over my included usage?"

A: When you exceed your included quota, Nimbus does not cut off your service;
   instead, additional usage is billed as overage at the metered rate
   ($0.50 per extra 10k calls, $0.10 per extra GB). [1]
Sources:
   [1] billing.md, Billing and quotas

Note there's no keyword overlap between "go over my included usage" and "exceed your quota / overage", that match is semantic, which is the point.


Related MCP server: GraphRAG Llama Index MCP Server

MCP tools exposed

Tool

Purpose

search_documents(query, top_k, method)

Return the most relevant passages (semantic / lexical / hybrid).

answer_question(question, top_k)

A grounded answer with citations.

list_sources()

Documents currently indexed.

get_stats()

Index size + active backends.

Verified end-to-end over the real MCP stdio protocol (see tests/). Register it in a client with mcp.json.


Retrieval ablation (computed by make eval)

17 gold questions, deliberately paraphrased away from the documents' wording. hit@k = correct document in the top-k; MRR = how highly it's ranked.

Method

hit@4

MRR

Lexical (BM25)

0.941

0.873

Semantic (LSA)

0.941

0.912

Hybrid (RRF fusion)

0.941

0.941

All three usually find the right document on this clean corpus, but hybrid ranks it highest most consistently, fusing dense (semantic) and sparse (keyword) retrieval is a tuning-free win, and the paraphrased questions are exactly where pure keyword search ranks worse.

With a neural embedding backend (Voyage/OpenAI/ST) on a larger, noisier corpus the gap between lexical and semantic widens further; the local LSA backend keeps the demo runnable anywhere while preserving the same ranking behaviour.


Quickstart

pip install -r requirements.txt && pip install -e .

make demo     # ask a question from the CLI
make eval     # retrieval ablation → reports/eval_results.json
make server   # run the MCP server (stdio)
make test     # 10 tests, incl. an end-to-end MCP protocol check

Use it from Claude Desktop

Copy mcp.json into your client config (set the absolute cwd), restart the client, and the four tools appear. Ask "search the Nimbus docs for how failover works" and the model calls search_documents / answer_question.

Switch to production backends

pip install -r requirements-prod.txt
export MCPRAG_EMBEDDING_BACKEND=voyage   VOYAGE_API_KEY=...
export MCPRAG_GENERATOR_BACKEND=anthropic ANTHROPIC_API_KEY=...

No code changes, the retriever and server are backend-agnostic.


Layout

src/mcprag/
  ingest.py            markdown loading + section-aware chunking w/ overlap
  embeddings/          Embedder protocol · local LSA (offline) · neural backends
  index/vector_store.py  cosine + BM25 + hybrid RRF retrieval
  generator/           extractive (offline, cited) · LLM backends
  rag.py               RAGEngine (ingest→embed→index→retrieve→generate)
  evaluation.py        hit@k / MRR
  server.py            FastMCP server exposing the tools
data/corpus/           the Nimbus knowledge base (8 markdown docs)
eval/qa_gold.json      paraphrased gold questions
scripts/               demo_query · run_eval
tests/                 retrieval, answers, evaluation, MCP protocol

Design notes

  • Grounded by construction. The offline generator only emits sentences taken verbatim from retrieved chunks, each with a citation, it cannot hallucinate.

  • Hybrid retrieval. Reciprocal Rank Fusion of dense + sparse rankings needs no weight tuning and is robust across query types.

  • Backend-agnostic. Embeddings and generation are pluggable Protocols; offline and production share identical retrieval/serving code.

See docs/ARCHITECTURE.md, docs/RESULTS.md, and docs/IMPROVEMENTS.md.

Tech stack

Python · MCP SDK (FastMCP) · scikit-learn (TF-IDF + LSA) · rank_bm25 · numpy · pydantic. Optional: Voyage / OpenAI / sentence-transformers / Anthropic.

License

MIT. The demo corpus is fictional.

Available Tools

4 tools
answer_questionA

Answer a question grounded in the knowledge base, with citations.

Args: question: the user's question. top_k: how many passages to ground the answer in.

ParametersJSON Schema
NameRequiredDescriptionDefault
top_kNo
questionYes

TDQS

A3.6/5.0
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It mentions answering with citations but does not specify output format, error handling (e.g., no answer found), authentication requirements, or whether it's read-only. This is insufficient for a tool with no annotations.

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

Conciseness4/5

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

The description is short and front-loaded, stating the purpose in the first sentence. The args section is clear but repetitive. No extraneous words. Could be slightly more structured, but overall efficient.

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 no output schema, the description should explain return values (e.g., format of citations). It mentions citations but not their structure. For a simple tool with 2 parameters, it is adequate 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 add meaning. It explains 'question: the user's question' and 'top_k: how many passages to ground the answer in,' which adds value beyond the schema names but remains minimal. It does not elaborate on valid values or constraints.

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 tool's purpose: 'Answer a question grounded in the knowledge base, with citations.' It specifies the verb (answer), resource (question grounded in knowledge base), and distinguishes from sibling tools like search_documents (document search) and get_stats (statistics).

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 implies usage for fact-based questions requiring citations, but does not explicitly state when not to use or suggest alternatives. The context is clear, but explicit when-not-to-use guidance is missing.

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

get_statsA

Return index size and the active embedding/generation backends.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A3.7/5.0
Behavior2/5

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

With no annotations, the description carries full burden for behavioral disclosure, but it only states what is returned, not whether the tool is read-only, requires authentication, or any side effects. This is insufficient for a tool with no safety annotations.

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 a single, concise sentence that directly conveys the tool's purpose without any extraneous words, perfectly front-loaded and efficient.

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?

Given no output schema, the description could provide more details about return format or whether stats are cached/real-time. It covers the basic purpose but lacks completeness for a rich contextual understanding.

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?

No parameters exist, so schema coverage is 100% by default. The description adds no parameter-specific info, but as baseline for zero parameters, it is adequate.

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?

Description clearly states the tool returns index size and active backends, distinguishing it from sibling tools like answer_question or search_documents which serve different purposes.

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?

No explicit when-to-use or when-not-to-use guidance is provided. The description implies usage context (retrieving stats) but lacks exclusions or alternatives, which is adequate but not helpful.

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

list_sourcesA

List the documents available in the knowledge base.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.1/5.0
Behavior3/5

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

Without annotations, the description carries full burden but only states the basic action; it does not disclose read-only nature, authorization needs, or output format, though the output schema may compensate.

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?

Single sentence of 8 words, perfectly concise and front-loaded with the core action.

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?

Given zero parameters and an existing output schema, the description is fully complete for this simple listing tool.

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?

Zero parameters, so baseline is 4; no additional parameter info needed as schema coverage is 100%.

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 a specific verb 'list' and resource 'documents available in the knowledge base', clearly distinguishing it from sibling tools (answer_question, get_stats, search_documents) by focusing on enumeration of all sources.

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?

No explicit guidance on when to use this tool vs alternatives; usage is implied by the purpose of listing all documents, but no when-not or exclusion criteria are provided.

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

search_documentsB

Search the knowledge base for passages relevant to a query.

Args: query: natural-language search query. top_k: number of passages to return. method: retrieval strategy — "semantic", "lexical", or "hybrid".

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes
top_kNo
methodNohybrid

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior2/5

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

No annotations exist, and the description does not disclose behaviors such as read-only status, authorization needs, or side effects. It only states the search functionality.

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

Conciseness4/5

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

The description is concise with a clear purpose sentence followed by parameter list. It is front-loaded and contains no unnecessary text, though could be slightly more structured.

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?

The output schema exists, so return values need not be covered. However, missing details like maximum top_k, ordering of results, or clarification of 'hybrid' method make it adequate but not complete.

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?

Despite 0% schema description coverage, the description explains all three parameters (query, top_k, method) with clear semantics, going beyond the schema's titles and defaults.

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 tool searches the knowledge base for passages relevant to a query, distinguishing it from siblings like answer_question (answering) and get_stats (statistics).

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives (e.g., answer_question). The description only lists parameters without context.

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

TDQS

A4/5.0
Disambiguation5/5

Each tool has a clear, distinct purpose: answer_question for generating answers, search_documents for retrieving passages, list_sources for enumerating documents, and get_stats for server metadata. No functional overlap.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case (answer_question, get_stats, list_sources, search_documents), making the API predictable.

Tool Count5/5

With 4 tools, the server is well-scoped for its RAG purpose. Each tool covers a core operation (search, answer, list sources, stats) without unnecessary bloat.

Completeness5/5

The tool surface covers all essential tasks for a knowledge base query system: searching, answering with citations, listing available documents, and retrieving system stats. No obvious gaps for the stated purpose.

Maintenance

ActivitySlowing
ResponsivenessSyncing

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

  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables semantic search over local Markdown documentation using hybrid retrieval combining embeddings, keyword search, and graph traversal with automatic file watching and zero-configuration setup.
    2
    MIT
  • F
    license
    A
    quality
    D
    maintenance
    Enables AI agents to query a local knowledge graph built from document collections using hybrid search (BM25 + vector fusion) and entity-relationship extraction. Supports privacy-first, offline operation with tools for semantic search, entity graph exploration, and corpus statistics.
    3
  • F
    license
    A
    quality
    D
    maintenance
    Enables indexing local documents (PDF, Markdown, text, code) into a knowledge base and querying them via semantic search using local embeddings, all running privately on your machine.
    4

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/elhassane1230/mcp-rag'

If you have feedback or need assistance with the MCP directory API, please join our Discord server