PDF RAG MCP Server

PDF RAG MCP Server

Enables RAG over messy PDFs — extract, chunk, embed, and search scanned, multi-column, and table-heavy documents.

Category
访问服务器

README

PDF RAG MCP Server

MCP server for RAG over messy PDFs — extract, chunk, embed, and search scanned, multi-column, and table-heavy documents.

Python 3.12+ License: MIT MCP


<p align="center"> <img src="docs/images/inspector-tools.png" alt="MCP Inspector — Tools" width="800"/> <br/> <em>All 6 tools running in the MCP Inspector</em> </p>

What is RAG?

RAG (Retrieval-Augmented Generation) is a technique that makes AI assistants smarter by giving them access to your own documents. Instead of relying only on training data, the AI first retrieves relevant chunks from your files, then uses them as context to generate accurate, grounded answers.

Traditional AI:  User Question → LLM → Answer (may hallucinate)
RAG:             User Question → Search Your Docs → LLM + Context → Accurate Answer

This MCP server is the "Search Your Docs" part — it ingests PDFs, breaks them into searchable chunks, and lets any MCP-compatible AI assistant find the right information instantly.

Why This Server?

Most PDF tools choke on real-world documents — scanned pages, multi-column layouts, embedded tables. This MCP server handles them all:

  • Scanned PDFs — Automatic OCR via Tesseract when text extraction fails
  • Multi-column layouts — Layout-preserving block sorting with PyMuPDF
  • Tables — Detected and extracted as clean markdown via pdfplumber
  • Semantic search — Find information by meaning, not just keywords
  • 100% local — Embeddings run on your machine. No data leaves your system.

Demo

Ingest a PDF and search it

<p align="center"> <img src="docs/images/inspector-ingest.png" alt="PDF Ingest" width="800"/> <br/> <em>Ingesting a PDF — extracts text, chunks it, generates embeddings</em> </p>

<p align="center"> <img src="docs/images/inspector-search.png" alt="Semantic Search" width="800"/> <br/> <em>Semantic search returns ranked results with page numbers and similarity scores</em> </p>

Tool Examples

1. Ingest a PDF

Tool: pdf_ingest
Input: { "file_path": "/home/user/reports/ai-healthcare-2026.pdf" }
{
  "doc_id": "a1b2c3d4e5f6",
  "filename": "ai-healthcare-2026.pdf",
  "total_pages": 4,
  "total_chunks": 12,
  "scanned_pages": [],
  "status": "ingested"
}

2. Search across documents

Tool: pdf_search
Input: { "query": "drug discovery timelines", "limit": 3 }
{
  "query": "drug discovery timelines",
  "total_results": 3,
  "results": [
    {
      "text": "Drug discovery timelines shortened by 30% using generative AI models...",
      "score": 0.8742,
      "page_num": 1,
      "source_filename": "ai-healthcare-2026.pdf"
    },
    {
      "text": "The healthcare AI market is experiencing rapid growth... Drug Discovery 8.7B...",
      "score": 0.6521,
      "page_num": 3,
      "source_filename": "ai-healthcare-2026.pdf"
    }
  ]
}

3. Extract tables as markdown

Tool: pdf_extract_tables
Input: { "file_path": "/home/user/reports/ai-healthcare-2026.pdf", "page_num": 3 }
{
  "page_num": 3,
  "tables_found": 1,
  "markdown": "| Application | Market 2025 | Market 2030 |\n|---|---|---|\n| Diagnostic Imaging | $12.4B | $45.2B |\n| Drug Discovery | $8.7B | $32.1B |"
}

4. Get a specific page

Tool: pdf_get_page
Input: { "doc_id": "a1b2c3d4e5f6", "page_num": 1 }
{
  "doc_id": "a1b2c3d4e5f6",
  "page_num": 1,
  "text": "Artificial Intelligence in Healthcare\nA Comprehensive Report - 2026\n\nExecutive Summary\nArtificial intelligence is transforming healthcare delivery..."
}

5. List & manage documents

Tool: pdf_list_documents
{
  "total_documents": 2,
  "documents": [
    { "doc_id": "a1b2c3d4e5f6", "source_filename": "ai-healthcare-2026.pdf", "total_chunks": 12, "total_pages": 4 },
    { "doc_id": "f6e5d4c3b2a1", "source_filename": "quarterly-report.pdf", "total_chunks": 45, "total_pages": 18 }
  ]
}
Tool: pdf_delete
Input: { "doc_id": "f6e5d4c3b2a1" }
→ { "doc_id": "f6e5d4c3b2a1", "chunks_deleted": 45, "status": "deleted" }

MCP Tools

Tool Description
pdf_ingest Ingest a PDF: extract text (with OCR fallback), chunk, embed, and store
pdf_search Semantic search across all ingested PDFs with similarity scores
pdf_get_page Get full extracted text for a specific page
pdf_list_documents List all ingested documents with metadata
pdf_delete Remove a document and its embeddings from the store
pdf_extract_tables Extract tables from a page as markdown

Installation

Prerequisites

  • Python 3.12+
  • Tesseract OCR (for scanned PDF support)
# Ubuntu/Debian
sudo apt install tesseract-ocr

# macOS
brew install tesseract

Install from source

git clone https://github.com/MBaranekTech/pdf-rag-mcp.git
cd pdf-rag-mcp
uv venv .venv && source .venv/bin/activate
uv pip install -e .

Install from PyPI

pip install pdf-rag-mcp

Configuration

Claude Desktop

Add to ~/.config/Claude/claude_desktop_config.json (Linux) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "pdf-rag": {
      "command": "/path/to/pdf-rag-mcp/.venv/bin/pdf-rag-mcp"
    }
  }
}

Claude Code

claude mcp add pdf-rag -- /path/to/pdf-rag-mcp/.venv/bin/pdf-rag-mcp

Cursor / VS Code

Add to .cursor/mcp.json or VS Code MCP settings:

{
  "mcpServers": {
    "pdf-rag": {
      "command": "/path/to/pdf-rag-mcp/.venv/bin/pdf-rag-mcp"
    }
  }
}

Docker

docker build -t pdf-rag-mcp .
docker run -v /path/to/pdfs:/pdfs pdf-rag-mcp

Architecture

PDF File
  │
  ▼
┌─────────────────────────────────────────┐
│  pdf_extractor.py                       │
│  ┌───────────┐   ┌──────────────────┐   │
│  │  PyMuPDF  │──▶│ Text extraction  │   │
│  └───────────┘   │ (layout-aware)   │   │
│  ┌───────────┐   ├──────────────────┤   │
│  │ Tesseract │──▶│ OCR fallback     │   │
│  └───────────┘   │ (scanned pages)  │   │
│  ┌───────────┐   ├──────────────────┤   │
│  │pdfplumber │──▶│ Table detection  │   │
│  └───────────┘   └──────────────────┘   │
└──────────────────┬──────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────┐
│  chunker.py                             │
│  Split into ~500-word overlapping       │
│  chunks with page number metadata       │
└──────────────────┬──────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────┐
│  vector_store.py                        │
│  ┌────────────────────┐  ┌───────────┐  │
│  │ sentence-transformers│  │ ChromaDB  │  │
│  │ (all-MiniLM-L6-v2) │─▶│ (cosine)  │  │
│  └────────────────────┘  └───────────┘  │
└──────────────────┬──────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────┐
│  server.py (FastMCP)                    │
│  6 tools exposed via MCP protocol       │
└─────────────────────────────────────────┘

How It Works

  1. Ingest — PyMuPDF extracts text blocks sorted by position. Pages with < 50 characters of text are automatically OCR'd via Tesseract.
  2. Chunk — Text is split into ~500-word overlapping chunks (50-word overlap), preserving page number metadata.
  3. Embed — Chunks are embedded using all-MiniLM-L6-v2 (~80MB, runs locally, no API keys).
  4. Store — Embeddings and metadata are persisted in ChromaDB at ~/.pdf-rag-mcp/chroma_db/.
  5. Search — Queries are embedded and matched against stored chunks using cosine similarity.

Development

# Setup
uv venv .venv && source .venv/bin/activate
uv pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Test with MCP Inspector (requires Node.js)
fastmcp dev inspector src/pdf_rag_mcp/server.py:mcp --with-editable .
# Opens browser UI at http://localhost:6274

Tech Stack

Component Technology
MCP Framework FastMCP
PDF Extraction PyMuPDF
Table Extraction pdfplumber
OCR Tesseract via pytesseract
Embeddings sentence-transformers (all-MiniLM-L6-v2)
Vector Store ChromaDB

Privacy

All processing happens locally:

  • Embedding model runs on your machine
  • PDF content is never sent to external APIs
  • Data stored at ~/.pdf-rag-mcp/chroma_db/

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选