Skip to main content
Glama
renvk

pdf-search-mcp

by renvk

pdf-search-mcp

MCP server for full-text search across PDF document collections. Built for AI agents — index once, search instantly from any MCP client.

  • Search entire collections — pre-indexes all PDFs for instant ranked results with snippets, not one file at a time

  • Fully offline — no API keys, no cloud services, just SQLite FTS5 and PyMuPDF

  • Page rendering — render pages as PNG for formulas, diagrams, and tables; crop to a region with auto-DPI scaling for detail shots

  • Dual renderer — CoreGraphics on macOS (sharper math fonts), PyMuPDF on Linux/Windows

  • German-aware — automatic expansion of ß↔ss, ä↔ae, ö↔oe, ü↔ue so both spellings match

  • stdio or HTTP — per-client subprocess by default, or a standalone shared server for trusted networks (Dockerfile included)

Installation

From PyPI

pip install pdf-search-mcp

From source

git clone https://github.com/renvk/pdf-search-mcp.git
cd pdf-search-mcp
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

Requires Python 3.10+. On macOS, pyobjc-framework-Quartz is installed automatically for native CoreGraphics PDF rendering (sharper formula and math font output). On Linux/Windows, PyMuPDF is used as the renderer.

Related MCP server: mcp-pdf-tools

Quick Start

1. Index your PDFs

PDF_SEARCH_DIR=/path/to/your/pdfs python -m pdf_search_mcp.pdf_search index

2. Register with your MCP client

The server runs over stdio. Example for Claude Code:

# project-scoped (only available in the current directory)
claude mcp add pdf-search -- pdf-search-mcp

# or global (available in all projects)
claude mcp add --scope global pdf-search -- pdf-search-mcp

For other MCP clients, add to your MCP config:

{
  "mcpServers": {
    "pdf-search": {
      "command": "pdf-search-mcp"
    }
  }
}

Ask your AI agent to search your PDFs — it will use the search, read_page, and read_page_image tools automatically.

Configuration

Environment Variable

Default

Description

PDF_SEARCH_DIR

(none)

Path to your PDF directory (required for first index, remembered after)

PDF_SEARCH_DB

~/.local/share/pdf-search-mcp/pdf_index.db

Path to the SQLite database file

Self-Hosted Server (HTTP)

The server has two transports:

  • stdio (default, no flags): each MCP client launches its own server subprocess on the same machine. Use this for single-machine setups.

  • http: one standalone server shares one indexed PDF collection with multiple clients over a trusted network:

pdf-search-mcp --transport http --host 0.0.0.0 --port 8000

The MCP endpoint is http://<server>:8000/mcp. Connecting from Claude Code:

claude mcp add --transport http --scope user pdf-search http://<server>:8000/mcp

Security: the HTTP transport has no authentication or TLS. Run it only on trusted networks (LAN, VPN) and never expose it to the internet. The default --host 127.0.0.1 keeps it local to the machine; binding 0.0.0.0 is an explicit opt-in.

Note: over HTTP, read_page_image returns the rendered PNG as inline MCP image content, so page rendering works for clients on other machines (including clients without filesystem access, such as Claude Desktop). Over stdio it returns a file path for the client to open, as before.

Docker

The repository includes a Dockerfile for container hosts (home servers, NAS devices). On startup the container runs an incremental index sync against the mounted PDF directory (only new, changed, and deleted files are processed) and then serves on port 8000:

git clone https://github.com/renvk/pdf-search-mcp.git
cd pdf-search-mcp
docker build -t pdf-search-mcp .
docker run -d --name pdf-search \
  -p 8000:8000 \
  -v /path/to/pdfs:/pdfs:ro \
  -v pdf-index:/data \
  pdf-search-mcp

Or with Docker Compose:

services:
  pdf-search:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - /path/to/pdfs:/pdfs:ro
      - pdf-index:/data
    restart: unless-stopped

volumes:
  pdf-index:

New PDFs in the mounted directory are picked up on container restart, or immediately with:

docker exec pdf-search python -m pdf_search_mcp.pdf_search index

Set PDF_SEARCH_INDEX_ON_START=0 in the container environment to skip the index sync (e.g. when the index is maintained by an external job).

CLI Usage

The pdf_search.py module doubles as a CLI for indexing and direct search:

# Build index (first time — PDF_SEARCH_DIR required)
PDF_SEARCH_DIR=/path/to/pdfs python -m pdf_search_mcp.pdf_search index

# Subsequent syncs (path remembered from first index)
python -m pdf_search_mcp.pdf_search index

# Search from command line
python -m pdf_search_mcp.pdf_search search "query terms"

# Read a specific page
python -m pdf_search_mcp.pdf_search read filename.pdf 5

# Show index statistics
python -m pdf_search_mcp.pdf_search stats

# Report extraction-quality problems (scanned files needing OCR,
# stale normalization, broken font mappings, near-empty pages)
python -m pdf_search_mcp.pdf_search quality

# Rebuild index from scratch (path remembered)
python -m pdf_search_mcp.pdf_search reindex

Search Syntax

Uses SQLite FTS5 query syntax:

Syntax

Example

Description

Terms

distributed consensus

Both terms must appear (implicit AND)

Phrase

"garbage collection"

Exact phrase match

OR

mutex OR semaphore

Either term

NOT

cache NOT redis

Exclude term

Prefix

concur*

Prefix matching

NEAR

NEAR(load balancer, 10)

Terms within 10 tokens of each other

Auto-quoting: Terms containing any special character (dots, hyphens, commas, slashes, colons, ...) are automatically quoted (e.g., ISO-27001 becomes "ISO-27001", 1:100 becomes "1:100") because FTS5 treats these as token separators or operators. Query preparation guarantees valid FTS5 syntax — stray quotes are dropped, unbalanced parentheses are repaired, and dangling AND/OR operators are trimmed. The one exception is NOT without a left operand (FTS5's NOT is binary): it is passed through and returns a clear error, because silently searching the excluded term would invert the query's meaning.

German expansion: Umlauts and eszett are automatically expanded to their digraph equivalents and vice versa (ß↔ss, ä↔ae, ö↔oe, ü↔ue). Searching for Größe also finds Groesse, and Weißbuch also finds Weissbuch. Reverse expansion (ssß) replaces one position at a time. Expansion also applies inside NEAR() expressions.

Auto-relaxation: When a multi-term query returns no results (all terms must appear on the same page), the search automatically relaxes: first by dropping the term least represented in the corpus (chosen by uncapped match counts), then by OR-ing all terms. A note in the output explains what was actually searched. Structured queries (explicit AND, OR, NOT, NEAR, parentheses) are not relaxed.

MCP Tools

Tool

Parameters

Description

search

query, limit=10

Full-text search with ranked results and snippets (limit range 1-50)

read_page

filename, page, subfolder=None

Read the full text of a specific page

read_page_image

filename, page, dpi=140, region=None, subfolder=None

Render a page (or cropped region) as PNG. region=[x1,y1,x2,y2] with 0.0–1.0 fractional coords to crop; DPI auto-scales for the cropped area

stats

(none)

Show index statistics (file count, pages, DB size, renderer)

When the same filename exists in several subfolders, read_page and read_page_image require the subfolder parameter ("" selects the root folder); an unspecified subfolder returns an error listing the candidates instead of picking one arbitrarily.

Python API

from pdf_search_mcp import (
    search_with_relaxation, search_pdfs, prepare_query,
    read_pdf_page, render_pdf_page, index_pdfs,
)

# Index PDFs
index_pdfs("/path/to/pdfs")

# Search with the full pipeline (auto-quoting, German expansion,
# relaxation) — same behavior as the MCP search tool and the CLI
results, note = search_with_relaxation("ISO-27001 Anhang", limit=5)
for r in results:
    print(f"{r['subfolder']}/{r['file']} p.{r['page']}: {r['snippet']}")

# Low-level: search_pdfs takes a RAW FTS5 MATCH string (no preparation).
# Run user input through prepare_query first.
results = search_pdfs(prepare_query("garbage collection"), limit=5)

# Read full page text
text = read_pdf_page("document.pdf", 42)

# Render full page as PNG
png_path = render_pdf_page("document.pdf", 42)

# Render cropped region (DPI auto-scales to maximize detail)
png_path = render_pdf_page("document.pdf", 42, region=[0.0, 0.5, 1.0, 0.8])

How It Works

  1. Indexing incrementally syncs your PDF directory into a SQLite FTS5 virtual table — on first run all PDFs are indexed; afterwards only new, changed (by mtime/size), and deleted files are processed, each committed individually so an interrupted run resumes where it stopped. Only page content is searchable; filenames, subfolders, and page numbers are stored as unindexed metadata so query terms cannot match them. Directories starting with _ are skipped. Extracted text is normalized before indexing — typographic ligatures are decomposed (efficiencyefficiency), words split by line-break hyphenation are rejoined, and invisible soft hyphens are removed — so words that would otherwise never match a query do. read_page applies the same normalization, so the text you read is exactly the text that was searched.

Upgrading: a pre-0.3 index (searchable metadata columns) is refused with a clear error; an index built before text normalization keeps working but stores unnormalized text. In either case, run python -m pdf_search_mcp.pdf_search reindex once to rebuild.

  1. Searching runs FTS5 MATCH queries and re-ranks results by combining BM25 relevance with match density — pages where search terms cluster together score higher than pages with the same terms scattered throughout. The density signal blends term concentration (matches per character) and spatial clustering (how tightly grouped the matches are).

  2. Reading re-opens the original PDF file on disk (path resolved via the stored pdf_dir metadata) for full page text or image rendering. Region crops auto-scale DPI to fill a 1568 px long-edge budget, maximizing detail without producing oversized images.

The database stores the text content only — original PDFs are accessed on disk for read_page and read_page_image. Rendering uses CoreGraphics on macOS and PyMuPDF elsewhere.

License

MIT

Available Tools

4 tools
read_pageA

Read the full text of a specific page from an indexed PDF.

Use after search() to read the complete page content around a match. If the result contains garbled text, broken symbols, or unreadable formulas, use read_page_image() instead — it renders the page as a PNG that preserves formulas, diagrams, and tables exactly. For tables and dense data, crop to the relevant region to read values reliably.

Args: filename: PDF filename exactly as shown in search results. page: 1-based page number. subfolder: Subfolder as shown in search results. Required when duplicate filenames exist; pass "" for the root folder.

Returns: Full extracted text of the page.

ParametersJSON Schema
NameRequiredDescriptionDefault
filenameYes
pageYes
subfolderNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.8/5.0
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses that the tool returns full extracted text and notes when output may be garbled, advising an alternative. Does not mention error cases or side effects, but for a simple read tool this is adequate.

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 well-structured: a one-sentence summary, usage guidelines, parameter details, and return value. Each sentence is informative and concise, with no redundant or 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?

Despite having an output schema (not shown), the description states 'Returns: Full extracted text of the page,' which is sufficient. It also covers practical context (when to use image version, subfolder handling). The tool is simple, and the description covers all necessary aspects.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description adds detailed meaning: filename must be exact from search results, page is 1-based, subfolder is required when duplicates exist and empty string means root. This fully clarifies parameter usage beyond the schema types.

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 'Read the full text of a specific page from an indexed PDF,' which is a specific verb+resource pair. It distinguishes itself from sibling tools like read_page_image (renders as PNG) and search (used before reading).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

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

Explicitly says 'Use after search() to read the complete page content around a match' and 'If the result contains garbled text... use read_page_image() instead — it renders the page as a PNG.' Also explains when subfolder parameter is required, providing clear use vs. non-use conditions.

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

read_page_imageA

Render a PDF page (or cropped region) as a PNG for visual inspection.

Use instead of read_page() when text extraction misses formulas, diagrams, or tables.

Workflow:

  1. First call: render the full page (no region, default dpi) to orient yourself. Do NOT raise dpi — default 140 already fills the vision model's 1568 px input limit. Higher DPI just gets downscaled.

  2. ALWAYS crop before reading values. Tables, formulas, and dense data are NOT reliably readable at full-page scale. Call again with region to crop the area of interest. DPI auto-scales to fill 1568 px for the crop — do NOT set dpi manually, it is computed automatically.

Args: filename: PDF filename exactly as shown in search results. page: 1-based page number. dpi: Render resolution (default 140, range 1-600). Leave at default for full-page renders. Ignored when region is set (auto-scaled to fill 1568 px). region: Crop box [x1, y1, x2, y2], each value 0.0–1.0, top-left origin. Required for reading values from tables, formulas, or figures — full-page scale is not reliable for these. Example: [0.0, 0.5, 1.0, 0.8] = band from 50–80% down the page. subfolder: Subfolder as shown in search results. Required when duplicate filenames exist; pass "" for the root folder.

Returns: stdio transport: the PNG file path on the first line — open it with your file-reading tool to view. Full-page renders append a crop-advisory line after the path; when passing the result to a file reader, use only the first line. http transport: the rendered PNG as inline image content (no file access needed). Full-page renders include the crop advisory as an additional text item. On error: a plain-text message describing the problem.

ParametersJSON Schema
NameRequiredDescriptionDefault
filenameYes
pageYes
dpiNo
regionNo
subfolderNo

TDQS

A4.9/5.0
Behavior5/5

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

No annotations provided, so description fully carries transparency. It discloses return behavior for both stdio and HTTP transports, error handling, DPI auto-scaling when region is set, and the crop advisory line appended to full-page renders.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections (purpose, workflow, args, returns) and front-loaded with key info. Though lengthy, every sentence adds value; minor redundancy could be trimmed.

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?

Despite no output schema, description fully covers return types for both transports, error messages, and the crop advisory. It addresses all edge cases: DPI auto-scaling, region usage, subfolder handling, and duplicate filenames.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, yet the description explains each parameter in detail: filename source, 1-based page, DPI range and default with behavior when region is set, region format and example, subfolder usage. Adds constraints and usage tips beyond schema.

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 tool renders a PDF page or cropped region as PNG for visual inspection, and explicitly distinguishes it from read_page() for cases where text extraction misses formulas, diagrams, or tables.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

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

The description provides a detailed workflow: first render full page to orient, then crop for reading values. It warns against raising DPI, explains when cropping is mandatory, and addresses duplicate filenames with subfolder. It directly recommends using this tool instead of read_page() for specific contexts.

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

statsA

Show PDF search index statistics (file count, page count, DB size, renderer).

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

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

The description indicates a read-only operation with no side effects, aligning with the lack of annotations. While no additional behavioral traits are disclosed, nothing is hidden; the tool is straightforward.

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 includes all necessary information without extraneous words. It is front-loaded with the verb 'Show' and key object.

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 no parameters, no annotations, and an existing output schema, the description is sufficiently complete. It explains what the tool returns without needing to document return values.

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 no parameters, so the description correctly avoids parameter details. The baseline for zero parameters is 4, and the description adds no confusion.

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 tool's purpose: showing PDF search index statistics with specific metrics (file count, page count, DB size, renderer). It effectively distinguishes from sibling tools like read_page and search.

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 purpose is clear and the sibling context implies when to use (for aggregate stats vs. individual pages). However, no explicit guidance on when not to use or alternatives is provided.

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. 4 tool updatesv0.4.0
    • First observedread_page
    • First observedread_page_image
    • First observedsearch
    • First observedstats

TDQS

A4.5/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a distinct purpose: search for discovering matches, read_page for text extraction, read_page_image for visual rendering of problematic content, and stats for index overview. No functional overlap.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case: read_page, read_page_image, search, stats. The two 'read' tools are clearly differentiated by their object (page vs page_image).

Tool Count5/5

Four tools is well-scoped for a PDF search MCP: search, two complementary view methods (text and image), and index statistics. No tool is superfluous, and the count aligns with typical server sizes.

Completeness4/5

Covers the core workflow of searching and viewing PDFs with both text and image fallbacks. A minor gap is the lack of a tool to list all indexed files or manage the index, but for search-oriented usage it is sufficient.

Maintenance

ActivityStale
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that provides comprehensive PDF processing capabilities including text extraction, image extraction, table detection, annotation extraction, metadata retrieval, page rendering, and document structure analysis.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    MCP server for documentation search that automatically indexes web documentation sites and provides semantic, full-text, or hybrid search capabilities.
    5
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A read-only MCP server for PDF analysis that enables text extraction, image extraction, metadata retrieval, and text search via natural language.
    MIT