MCP-based Academic Paper Retrieval RAG System
Enables AI coding assistants to query private academic paper collections via standard MCP tools, with hybrid retrieval, reranking, and inline citations.
README
MCP-based Academic Paper Retrieval RAG System
A production-oriented, fully pluggable Retrieval-Augmented Generation (RAG) system exposed as an MCP (Model Context Protocol) server — enabling AI coding assistants like GitHub Copilot and Claude Desktop to query private knowledge bases via standard Tool Calling.
Overview
Engineers on R&D teams frequently search academic literature for technical research, but papers are scattered across internal file systems and keyword search fails to understand semantic intent — or integrate with AI coding assistant workflows.
This project solves that by building an MCP-based academic paper retrieval RAG system: ingest your PDFs once, then ask questions directly from GitHub Copilot or Claude Desktop via standard Tool Calling. Responses include inline citations and are grounded in your private document collection. The system supports both API-based LLM backends and fully local Ollama deployment. When configured with local embedding and local LLM backends, it can run without external network dependency, making it suitable for privacy-sensitive or air-gapped environments.
Benchmark results (10 papers, 1,104 chunks, 100 Golden QA pairs):
| Metric | Hybrid Search (baseline) | + BGE Reranker v2-m3 |
|---|---|---|
| Hit Rate@10 | 89% | 89% |
| MRR | 0.61 | 0.83 (+36%) |
| NDCG@10 | 0.68 | 0.84 (+24%) |
Ablation: replacing BGE Reranker v2-m3 with a general-purpose MS MARCO Cross-Encoder degraded MRR on academic text — domain-aligned reranking matters.
Architecture
PDF Documents
↓
┌─────────────────────────────────────┐
│ Ingestion Pipeline │
│ Load → Split → Transform → Embed │
│ → Upsert │
└──────────────────┬──────────────────┘
│
┌─────────┴──────────┐
│ │
ChromaDB (Dense) BM25 Index (Sparse)
BGE-M3 vectors Term frequencies
│ │
└─────────┬──────────┘
│ RRF Fusion
↓
BGE Reranker v2-m3
↓
┌─────────────────────────────────────┐
│ MCP Server │
│ JSON-RPC 2.0 + Stdio Transport │
│ │
│ • query_knowledge_hub │
│ • list_collections │
│ • get_document_summary │
└─────────────────────────────────────┘
↓ ↓
GitHub Copilot Claude Desktop
Key Features
Two-Stage Hybrid Retrieval
- Coarse ranking: BGE-M3 dense vectors + BM25 sparse retrieval run in parallel, fused via Reciprocal Rank Fusion (RRF)
- Fine ranking: BGE Reranker v2-m3 (same model family as the embedder) re-scores the top candidates — domain-aligned reranking for academic text
- Graceful fallback: reranker failure automatically falls back to fusion order with
fallback=Truemetadata
MCP-Compliant RAG Server
- Full JSON-RPC 2.0 protocol over stdio transport
- Three tools available to any MCP client:
query_knowledge_hub— semantic search with inline citationslist_collections— enumerate available knowledge basesget_document_summary— retrieve title, summary, tags for a document
- Structured multi-modal responses with citation blocks
Intelligent Ingestion Pipeline
- 5 stages: Load → Split → Transform → Embed → Upsert
- pdfplumber PDF parsing with image extraction and
[IMAGE: id]placeholder injection - Optional LLM-driven chunk refinement and metadata enrichment (Title / Summary / Tags)
- SHA-256 content hashing for idempotent incremental ingestion — re-running on unchanged files is a no-op
Fully Pluggable Architecture
Every core component is swappable via config/settings.yaml with zero code changes:
| Component | Supported Backends |
|---|---|
| LLM | OpenAI / Azure / DeepSeek / Ollama |
| Embedding | OpenAI / Azure / Ollama (BGE-M3, nomic-embed-text, …) |
| Vector Store | ChromaDB (local persistence) |
| Reranker | BGE / Cross-Encoder / LLM / None |
| Splitter | Fixed / Recursive / Semantic (TODO) |
| Evaluator | Custom (Hit Rate / MRR / NDCG) / Ragas |
When configured with Ollama-based local LLM and embedding backends, the system can run fully locally with no data leaving the environment.
Observability Dashboard
6-page Streamlit management platform:
| Page | Function |
|---|---|
| System Overview | Live component configuration view |
| Data Browser | Browse documents and chunks with metadata |
| Ingestion Manager | Upload PDFs, monitor real-time progress, delete documents |
| Ingestion Traces | Per-run stage timing (load / split / transform / embed / upsert) |
| Query Traces | Per-query stage breakdown (dense / sparse / fusion / rerank) |
| Evaluation | Run Golden QA evaluation and view Hit Rate / MRR / NDCG results |
Evaluation Framework
- Custom evaluator: Hit Rate@K, MRR, NDCG@10
- Ragas integration (Faithfulness / Answer Relevancy / Context Precision) — optional, requires API key
- Golden Test Set regression pipeline — every retrieval strategy change produces quantified before/after metrics
Quick Start
Prerequisites
- Python 3.10+
- Ollama (for local embedding) or an OpenAI-compatible API key
git clone <repo-url>
cd Modular-RAG-MCP-Server
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
Configure
Edit config/settings.yaml to set your embedding provider and model:
embedding:
provider: ollama # or openai / azure
model: bge-m3
rerank:
backend: cross_encoder # or none / llm
model: BAAI/bge-reranker-v2-m3
Set API keys if using cloud providers:
export OPENAI_API_KEY="sk-..."
Ingest Documents
python scripts/ingest.py --path /path/to/papers/ --collection research
Query
python scripts/query.py --query "How does RRF fusion work?" --verbose
Launch Dashboard
streamlit run src/observability/dashboard/app.py
# Open http://localhost:8501
Run Evaluation
python scripts/evaluate.py --collection research --output results/eval.json
MCP Integration
GitHub Copilot (VS Code)
Create .vscode/mcp.json:
{
"servers": {
"modular-rag": {
"type": "stdio",
"command": "python",
"args": ["src/mcp_server/server.py", "--config", "config/settings.yaml"],
"env": {
"OPENAI_API_KEY": "${env:OPENAI_API_KEY}"
}
}
}
}
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"modular-rag": {
"command": "python",
"args": ["/absolute/path/to/src/mcp_server/server.py"],
"env": {
"OPENAI_API_KEY": "your-api-key"
}
}
}
}
Running Tests
pytest -q # full suite (649 tests)
pytest -q tests/unit/ # unit tests only
pytest -q tests/integration/ # integration tests
pytest -q tests/e2e/ # E2E: MCP client, dashboard smoke, recall regression
Tech Stack
- Retrieval: BGE-M3 · BM25 · RRF · BGE Reranker v2-m3
- Storage: ChromaDB · SQLite · JSON Lines
- Protocol: MCP / JSON-RPC 2.0 / Stdio Transport
- LLM Backends: OpenAI · Azure OpenAI · Ollama · DeepSeek
- Evaluation: Custom (Hit Rate / MRR / NDCG) · Ragas
- Dashboard: Streamlit
- Testing: Pytest · 638 tests across Unit / Integration / E2E
- Design Patterns: Abstract Base Class · Factory Pattern · Dependency Injection · TDD
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。