Skip to main content
Glama
MBaranekTech

PDF RAG MCP Server

by MBaranekTech

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


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.

Related MCP server: PDF RAG MCP Server

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

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

Available Tools

6 tools
pdf_deleteA

Remove an ingested PDF and all its embeddings from the store.

ParametersJSON Schema
NameRequiredDescriptionDefault
doc_idYesDocument ID returned by pdf_ingest or pdf_list_documents.

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior3/5

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

No annotations are present, so the description carries the full burden. It discloses a key side effect—that embeddings are also removed—which adds value beyond the name. However, it does not mention irreversibility, failure modes, or whether the operation is idempotent. While the destructive nature is clear from 'Remove', more transparency would be expected given zero annotation support.

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 front-loads the action and includes the important side effect. No unnecessary words or fluff; it is optimally sized for the tool's simplicity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple one-parameter schema and the mention of the embedding removal side effect, the description covers the core behavior. The output schema exists (though not shown), so return value details are not required. Minor gaps like error handling or prerequisites are not critical for such a straightforward tool, making it nearly 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?

The schema description for doc_id is complete: 'Document ID returned by pdf_ingest or pdf_list_documents.' Schema coverage is 100%, so the baseline is 3. The tool description adds no additional parameter detail, but the schema already provides sufficient guidance on how to obtain the ID.

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 states a specific verb ('Remove'), a clear resource ('an ingested PDF and all its embeddings'), and the overall action of deletion from the store. It clearly distinguishes from all sibling tools (search, get_page, list, extract_tables, ingest) which perform different operations. No ambiguity or tautology.

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?

The description implies usage (when you want to delete a PDF) but does not explicitly state when to use it versus alternatives, nor any exclusions or prerequisites (e.g., 'must be ingested first'). Because there is no competing delete tool, the distinction is implicit, but no explicit guidance is provided.

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

pdf_extract_tablesA

Extract tables from a specific page of a PDF and return them as markdown.

ParametersJSON Schema
NameRequiredDescriptionDefault
page_numYesPage number to extract tables from (1-indexed).
file_pathYesAbsolute path to the PDF file.

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

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 carries the full burden of behavioral disclosure. It states the read-like action and markdown return format, but does not disclose what happens if the page has no tables, if the page number is out of range, whether the file is modified, or any error behavior. For a tool with no annotation coverage, this is a notable gap.

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 sentence with no filler. It front-loads the primary action and resource, then states the output format. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has a complete input schema and an output schema, so the agent has enough structural information to invoke it correctly. The main missing context is edge-case behavior (no tables found, invalid page number) and explicit usage guidance, but for a simple extraction tool the description is largely sufficient.

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 100%, so both file_path and page_num are already documented in the schema, including page_num being 1-indexed. The description does not add extra parameter meaning beyond mentioning 'specific page', but it does not need to because the schema handles it.

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 ('Extract tables'), identifies the exact resource ('from a specific page of a PDF'), and states the output format ('as markdown'). This clearly distinguishes it from siblings like pdf_get_page or pdf_search, which have 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?

The description implies when to use the tool: when you need tables from a PDF page. However, it provides no explicit guidance about when not to use it or which sibling tool might be better for other PDF-related tasks, such as pdf_search or pdf_get_page.

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

pdf_get_pageA

Get the full extracted text for a specific page of an ingested PDF.

ParametersJSON Schema
NameRequiredDescriptionDefault
doc_idYesDocument ID returned by pdf_ingest or pdf_list_documents.
page_numYesPage number (1-indexed).

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.9/5.0
Behavior3/5

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

No annotations are provided, so the description carries the burden. 'Get' implies a read-only retrieval, but the description does not disclose potential errors for invalid page numbers, missing documents, or whether text extraction requires any additional state. It is not misleading, but it adds limited behavioral depth.

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 sentence with no filler, front-loads the action, and communicates the exact scope in a compact way. Every word earns its place.

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?

For a simple two-parameter retrieval tool with a full input schema and an output schema, the description is sufficient. The agent knows what it returns, on what resource, and how to target a specific page. No critical information is missing.

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 100%, so the parameters doc_id and page_num are already fully documented. The description adds little beyond what the schema provides, which aligns with the baseline score for high schema coverage.

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 ('Get') and a clear resource ('full extracted text for a specific page of an ingested PDF'). It is easily distinguished from siblings like pdf_search, pdf_list_documents, and pdf_delete.

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?

The description implies the tool is for retrieving a single page's text from an already-ingested document, but it does not explicitly state when to prefer it over alternatives like pdf_search. Usage context is inferable rather than directly spelled out.

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

pdf_ingestA

Ingest a PDF file: extract text (with OCR fallback for scanned pages), split into chunks, generate embeddings, and store for search.

ParametersJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute path to the PDF file to ingest.

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior4/5

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

With no annotations provided, the description carries full responsibility for behavioral disclosure. It does well by revealing multi-step behavior, including OCR fallback for scanned pages, chunking, embedding generation, and persistent storage—all meaningful side effects beyond the simple input schema.

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?

A single, tightly packed sentence that front-loads the core action and then enumerates the pipeline efficiently. Every clause earns its place with no filler or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a one-parameter tool with an output schema, the description covers the essential workflow: extraction, OCR fallback, chunking, embeddings, and storage. Minor gaps such as file size limits, overwrite behavior, or asynchronous execution are not mentioned, but nothing critical is missing for correct invocation.

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?

The schema already fully documents the single parameter file_path with a clear description and 100% coverage. The tool description adds no new parameter-level semantics, so baseline 3 is appropriate.

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 names a specific verb ('Ingest'), a resource ('PDF file'), and the full pipeline (extract text, OCR fallback, chunk, embed, store). This clearly distinguishes it from siblings like pdf_search, pdf_get_page, pdf_delete, and pdf_extract_tables, 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 Guidelines2/5

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

The description implies this tool is for adding PDFs to a searchable store, but it never explicitly states when to use it versus alternatives, nor does it name sibling tools or exclusions. An agent must infer the intended context from the sibling list and the word 'for search.'

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

pdf_list_documentsA

List all ingested PDF documents with their metadata.

Returns: List of documents with doc_id, filename, page count, chunk count, and ingest date.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.3/5.0
Behavior3/5

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

No annotations are provided, so the description carries the burden. It states it returns metadata, implying a read-only operation, but it does not explicitly state that it does not modify data or what happens with no documents. The basic behavior is clear, but additional context like idempotence or safety is missing.

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 concise with two short sentences. The purpose is front-loaded, and the return fields are listed efficiently. No wasted words.

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 the tool's simplicity (no parameters) and the presence of an output schema, the description is complete. It states what it lists and the key metadata fields. Nothing critical is missing for an agent to understand and call it.

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?

There are 0 parameters, so the baseline is 4. The description doesn't need to explain any parameter semantics, and it appropriately omits them. No additional meaning is needed.

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 verb 'List' and the resource 'all ingested PDF documents with their metadata'. It distinguishes itself from siblings like pdf_search (search) and pdf_delete (delete) by being a listing operation. The purpose is unambiguous.

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 context is clear: use when you need an overview of all available PDFs. However, it does not explicitly mention alternatives or when not to use it, leaving some inference to the agent. Given the straightforward nature, a 4 is appropriate.

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedpdf_delete
    • First observedpdf_extract_tables
    • First observedpdf_get_page
    • First observedpdf_ingest
    • First observedpdf_list_documents
    • First observedpdf_search

TDQS

A4.1/5.0

Scored across 6 tools

Disambiguation5/5

Each tool targets a distinct operation: ingest, search, page retrieval, table extraction, listing, and deletion. There is no meaningful overlap between tool purposes, so an agent can clearly select the right tool.

Naming Consistency5/5

All tools follow a consistent pdf_ prefix with verb-first naming, such as pdf_ingest, pdf_search, and pdf_get_page. The pattern is predictable and uniformly snake_case throughout.

Tool Count5/5

Six tools is well-scoped for a PDF RAG server, covering ingestion, retrieval, and document management without unnecessary redundancy. Each tool earns its place in the set.

Completeness5/5

The tool surface covers the full PDF RAG lifecycle: ingest, search, retrieve page context, extract tables, list documents, and delete. There are no obvious dead ends or missing core operations for the stated purpose.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables processing and analysis of large PDF files through text extraction, search functionality, and intelligent chunking strategies. Provides comprehensive PDF operations including metadata retrieval, page-range text extraction, and content search with contextual results.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables intelligent search and question-answering over PDF documents using semantic similarity and keyword search. Supports OCR for scanned PDFs, persistent vector storage with ChromaDB, and maintains source tracking with page numbers.
    6
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI-powered querying of PDF documents using hybrid retrieval (BM25 + vector search) and retrieval-augmented generation, returning structured answers with source citations and confidence scores.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI-driven PDF document processing including PDF to Markdown conversion, intelligent text and table extraction, image extraction, format conversion between PDF/Word/Markdown, batch processing, and fuzzy search - optimized for LLM context and RAG workflows.
    2
    MIT