MCP PDF Reader

by labeveryday

Not rated
GitHub

About

Extract text, images, and perform OCR on PDF documents using Tesseract OCR.

Details

Author
labeveryday
Categories
File Management, Other

Setup

Install MCP PDF Reader in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/labeveryday/mcp_pdf_reader

Follow the installation instructions in the repository README, then restart your MCP client.

MCP PDF Reader Server (Python + FastMCP)

A powerful Model Context Protocol (MCP) server built with FastMCP that provides comprehensive PDF processing capabilities including text extraction, image extraction, and OCR for reading text within images.

- Text Extraction: Extract text content from PDF pages
- Image Extraction: Extract all images from PDF files
- OCR Capabilities: Read text from images using Tesseract OCR
- Comprehensive Analysis: Get detailed PDF structure and metadata
- Page Range Support: Process specific page ranges
- Multiple Languages: OCR support for multiple languages

You need to install Tesseract OCR on your system:

sudo apt update sudo apt install tesseract-ocr tesseract-ocr-eng

- Download from:https://github.com/UB-Mannheim/tesseract/wiki
- Install and add to PATH
- Or use:conda install -c conda-forge tesseract

# For multiple languages sudo apt install tesseract-ocr-fra tesseract-ocr-deu tesseract-ocr-spa
# macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh # Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
mkdir mcp-pdf-reader-server cd mcp-pdf-reader-server
# Copy the files (pdf_reader_server.py and pyproject.toml) # Then install dependencies uv sync
uv run python -c "import pytesseract; print(pytesseract.get_tesseract_version())"
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install fastmcp PyMuPDF pytesseract Pillow

Or if you have the environment activated:

The server will start and listen for MCP requests on stdin/stdout.

- file_path(string, required): Path to the PDF file
- page_range(object, optional): Dict withstartandendpage numbers

{ "file_path": "/path/to/document.pdf", "page_range": {"start": 1, "end": 5} }

- file_path(string, required): Path to the PDF file
- output_dir(string, optional): Directory to save images
- page_range(object, optional): Page range to process

{ "file_path": "/path/to/document.pdf", "output_dir": "/path/to/images/", "page_range": {"start": 1, "end": 3} }

Extract text from both regular text and images using OCR.

- file_path(string, required): Path to the PDF file
- page_range(object, optional): Page range to process
- ocr_language(string, optional): OCR language code (default: "eng")

{ "file_path": "/path/to/document.pdf", "ocr_language": "eng+fra", "page_range": {"start": 1, "end": 10} }

- eng- English
- fra- French
- deu- German
- spa- Spanish
- eng+fra- Multiple languages

Get comprehensive metadata and statistics about a PDF.

- file_path(string, required): Path to the PDF file

Analyze the structure and content distribution of a PDF.

- file_path(string, required): Path to the PDF file

Add this to yourclaude_desktop_config.json:

{ "mcpServers": { "pdf-reader": { "command": "uv", "args": ["run", "python", "/path/to/your/pdf_reader_server.py"], "cwd": "/path/to/your/mcp-pdf-reader-server" } } }
{ "mcpServers": { "pdf-reader": { "command": "/path/to/your/.venv/bin/python", "args": ["/path/to/your/pdf_reader_server.py"] } } }
{ "mcpServers": { "pdf-reader": { "command": "python", "args": ["/path/to/your/pdf_reader_server.py"], "env": { "PYTHONPATH": "/path/to/your/.venv/lib/python3.x/site-packages" } } } }
{ "success": true, "file_path": "/path/to/document.pdf", "pages_processed": "1-3", "total_pages": 10, "pages_text": [ { "page_number": 1, "text": "Page 1 content...", "word_count": 125 } ], "combined_text": "All text combined...", "total_word_count": 1250, "total_character_count": 8750 }
{ "success": true, "file_path": "/path/to/document.pdf", "pages_processed": "1-2", "ocr_language": "eng", "pages_data": [ { "page_number": 1, "text": "Regular text from PDF...", "ocr_text": "Text extracted from images...", "images_with_text": [ { "image_index": 1, "ocr_text": "Text from image 1", "confidence": "high" } ], "combined_text": "Combined text and OCR...", "text_word_count": 100, "ocr_word_count": 25 } ], "summary": { "total_text_word_count": 200, "total_ocr_word_count": 50, "combined_word_count": 250, "images_processed": 3 }, "all_text_combined": "All extracted text..." }

- OCR processing can be slow for large images
- Consider processing smaller page ranges for faster results
- Images smaller than 50x50 pixels are automatically skipped

- Large PDFs with many images may consume significant memory
- The server processes pages sequentially to manage memory usage
- Extracted images are saved to disk to reduce memory pressure
- Use page rangesfor large documents
- Specify output directoriesfor image extraction to avoid temp file buildup
- Choose appropriate OCR languagesto improve accuracy and speed
- Preprocess imagesif OCR quality is poor (consider adding OpenCV)

TesseractNotFoundError: tesseract is not installed

- Install Tesseract OCR system package
- Ensure it's in your PATH

- Ensure the Python process has read access to PDF files
- Ensure write access to output directories

- Try different OCR language codes
- Consider image preprocessing
- Check if images are high enough resolution

- Process smaller page ranges
- Close other applications
- Consider increasing available RAM

PYTHONUNBUFFERED=1 uv run python pdf_reader_server.py
PYTHONUNBUFFERED=1 python pdf_reader_server.py
tesseract --list-langs tesseract image.png output.txt

- fastmcp: Modern MCP server framework
- PyMuPDF: Fast PDF processing and rendering
- pytesseract: Python wrapper for Tesseract OCR
- Pillow: Image processing library
- tesseract-ocr: System OCR engine

You can modify the OCR configuration in the code:

ocr_text = pytesseract.image_to_string( pil_image, lang=ocr_language, config='--psm 6 -c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ' )

For better OCR results, consider adding image preprocessing:

# Add to requirements: opencv-python, numpy import cv2 import numpy as np # Preprocessing example def preprocess_image(image): gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1] return Image.fromarray(thresh)

- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request

MIT License - see LICENSE file for details.

Document conversion MCP server — PDF, DOCX, HTML, EPUB to Markdown with 6 tools and Docker support

Rust-powered PDF toolkit over MCP: create, read, and analyze PDFs; extract text and entities for RAG; convert to Markdown; split/merge/rotate/reorder pages; manage form fields and annotations; encrypt documents. Runs locally via uvx oxidize-mcp.

A server for AI agents to selectively process and extract content from PDF documents.

A server that converts PDF files to PNG images. Requires the poppler library to be installed.

Universal document generation and conversion MCP. Generate PDF/DOCX/XLSX from templates+JSON (invoices, contracts, reports), batch generation, 100+ format conversions.

A server for reading and converting documents between PDF, DOCX, and Markdown formats using marker-pdf and pandoc.

Convert, compress, merge and OCR PDFs and 100+ file formats from any AI agent — 126 tools via the GuruPDF API.

Converts LaTeX source code into professionally formatted PDF documents.

Convert PDF bank statements to checked Excel, CSV, or JSON with balance validation.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.