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
访问服务器

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选