mcp-rag-service

mcp-rag-service

A production-minded RAG service for MCP that answers questions over your documents with hybrid retrieval, PII redaction, and source citations, packaged for Docker/Kubernetes.

Category
Visit Server

README

mcp-rag-service

A production-minded Retrieval-Augmented Generation (RAG) service you can plug into any LLM through the Model Context Protocol (MCP) — with PII redaction guardrails and a retrieval-first evaluation harness, packaged for Docker and Kubernetes.

I built this because I wanted a single, safe "answer questions over my documents" tool that any MCP-aware assistant (Claude, an IDE agent, my own scripts) could call — without leaking personal data and without me having to trust the answers blindly. So it answers only from retrieved passages, cites its sources, redacts PII before anything touches the model, and ships with an eval script that measures retrieval quality rather than vibes.

Why it exists (the real problem)

An LLM on its own hallucinates and can't see your private documents. Wrapping retrieval around it fixes both — but three things are usually missing from demo RAG:

  1. It isn't callable from other tools. Here it's exposed as an MCP server, so any MCP client can use it as a first-class tool.
  2. It leaks PII. Emails, phone numbers, IBANs and card-like numbers are redacted before retrieval and before the prompt (asymmetric-cost thinking: a redaction is cheap, an accidental leak into a model/log is expensive).
  3. Nobody measures it. A hit@k + grounded-answer eval harness makes quality a number, not a feeling. Most "RAG hallucination" is really a retrieval miss, so I measure retrieval first.

Architecture

MCP client (Claude / agent)
        │  tool: rag_query(question)
        ▼
   MCP server  (src/mcp_rag/server.py)
        │
   RAG pipeline (rag.py)
        │  1. redact PII        (guardrails.py)
        │  2. hybrid retrieve   (retriever.py: dense + BM25, score-fused)
        │  3. generate grounded, cited answer  (LLM, or extractive fallback)
        ▼
   {answer, citations[], redactions[]}
  • Hybrid retrieval: dense embeddings (meaning) fused with BM25 (exact terms like IDs and names). Runs fully offline with a hashing embedder + pure-Python BM25 fallback, so there is no API key required for development — the paid LLM is used only for the final wording.
  • Guardrails: guardrails.py redacts PII with well-tested patterns (and optionally Microsoft Presidio if installed).
  • Grounding: answers are built only from retrieved chunks and carry [n] citations; if nothing relevant is retrieved it says so instead of guessing.

Run it

pip install -r requirements.txt
python -m mcp_rag.ingest data/            # index your documents
python -m mcp_rag.server                  # start the MCP server (stdio)

Query it directly (no MCP client needed):

python -m mcp_rag.rag "What are the payment terms in the Nordwind contract?"

Evaluate retrieval quality:

python eval/run_eval.py                   # prints hit@k and grounded-answer rate

Deploy (Docker + Kubernetes)

docker build -t mcp-rag-service -f deploy/Dockerfile .
kubectl apply -f deploy/k8s.yaml          # Deployment + Service, readiness/liveness probes

Tech

Python · MCP (FastMCP) · FAISS / hashing-embedder fallback · BM25 · FastAPI (HTTP mode) · Presidio-optional PII redaction · pytest · Docker · Kubernetes.

Status

Working core (retrieval, guardrails, MCP tool, eval) + container/K8s manifests. Corpus in data/ is a small sample; point ingest at your own documents to use it for real.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured