ocrmypdf-mcp
Provides OCR capabilities to add searchable text layers to scanned PDFs, with tools to check OCR need, process single files or batch folders, and integrate with Zotero attachment storage.
README
ocrmypdf-mcp
A local Model Context Protocol (MCP) server that wraps OCRmyPDF, letting Claude Desktop (or any MCP client) add searchable text layers to scanned PDFs — with first-class support for batch-processing a Zotero library.
Everything runs locally. No documents leave your machine.
⚠️ Important: files are modified in place
By default, the OCR tools overwrite your original PDFs with the OCR'd version. This is intentional (so Zotero re-indexes the same attachment), but it means:
- Back up your PDFs (or your Zotero storage folder) before a large batch run.
- Use
dry_run: true(supported by all three OCR tools) to preview what would be processed. - Use the
limitparameter ofbatch_ocr_folderfor small trial runs before processing an entire library.
⚠️ Risk of PDF damage or data loss
Any tool that rewrites PDFs can, in rare cases, produce a broken or degraded file. Be aware of the following before running OCR over documents you cannot re-download:
- A rewritten PDF is a different file. Even in the safest mode the whole document is re-serialized. A malformed-but-viewable source PDF (some viewers tolerate damage that PDF libraries do not) may fail to convert, or convert with missing content. Files that OCRmyPDF cannot parse are reported as
failedand left untouched — but verify a sample of outputs after a large batch. - Interrupted runs: OCRmyPDF writes to a temporary file and only replaces the original on success, so a crash or forced shutdown mid-run should not corrupt the source — but do not kill the process while it is copying the final output into place.
force=trueis destructive. It rasterizes every page: existing text layers, vector graphics, and annotations are permanently replaced by a flat image plus new OCR text. Use it only on documents whose existing text layer is garbage.- Wrong language = garbage text layer. OCR with a language that doesn't match the document produces nonsense text that then makes the file look "already searchable" to future runs.
- There is no undo. The tools do not keep backups. If the documents are irreplaceable, copy the folder first.
Tools
| Tool | Description | Modifies files |
|---|---|---|
check_needs_ocr |
Report whether a PDF already has a searchable text layer | No |
ocr_pdf |
OCR a single PDF (in place, or to a new output path); supports dry_run |
Yes |
batch_ocr_folder |
Start a background job that OCRs all PDFs under a folder, skipping ones that already have text; supports dry_run and limit |
Yes |
batch_status |
Progress and per-file results of background jobs (or list all jobs) | No |
cancel_batch |
Stop a running background job before its next file | No |
ocr_zotero_attachment |
OCR the PDF(s) under a Zotero storage key, in place; supports dry_run |
Yes |
All tools follow the same rule: a PDF that already has a text layer is never touched. A PDF without one gets a text layer added while the original page images are preserved exactly (no deskew, no rotation, no recompression, no PDF/A conversion — unless you explicitly opt in via the deskew, rotate, or optimize parameters, which do alter the page images).
Prerequisites
| What | Why | How to get it |
|---|---|---|
| Python 3.10+ | Runs the server | python.org |
| Tesseract OCR 5.x | The OCR engine | Windows: winget install UB-Mannheim.TesseractOCR (the UB-Mannheim build); Linux: apt install tesseract-ocr; macOS: brew install tesseract |
| Tesseract language packs for every language you OCR | Wrong/missing packs produce garbage text | Select them in the Windows installer, or drop <lang>.traineddata files from tessdata_fast into Tesseract's tessdata folder (e.g. ces for Czech, deu for German, jpn + jpn_vert for Japanese) |
| Ghostscript | Used by OCRmyPDF for PDF rendering | Windows: winget install ArtifexSoftware.GhostScript |
Python packages (mcp, ocrmypdf, pikepdf) |
Server + PDF processing | pip install -r requirements.txt |
Note: Tesseract cannot auto-detect document language — it only detects script/orientation. Set ocr_default_lang to a +-joined list matching your library (e.g. eng+ces), and pass language explicitly per call for outliers (e.g. jpn+jpn_vert). Keep the list short: every extra language slows OCR and increases misreads.
Tested with Python 3.12, OCRmyPDF 16.x, Tesseract 5.4, Ghostscript 10.x on Windows 11.
Installation
git clone https://github.com/chemysterium/ocrmypdf-mcp.git
cd ocrmypdf-mcp
pip install -r requirements.txt
Verify OCRmyPDF can find its dependencies:
ocrmypdf --version
Configuration
Copy the template and edit it with your paths:
cp config.example.json config.json
config.json (machine-specific, gitignored — never commit it):
{
"zotero_storage": "C:\\Users\\<you>\\Zotero\\storage",
"ocr_default_lang": "eng",
"tesseract_path": "C:\\Program Files\\Tesseract-OCR"
}
| Key | Meaning |
|---|---|
zotero_storage |
Root of your Zotero storage folder. Leave "" to disable the Zotero tool. |
ocr_default_lang |
Tesseract language code(s), +-joined: eng, eng+ces, eng+deu, … Requires matching Tesseract language packs. |
tesseract_path |
Folder containing the Tesseract executable. Leave "" to rely on your system PATH. |
Settings can also be supplied (and are overridden) by environment variables:
ZOTERO_STORAGE, OCR_DEFAULT_LANG, TESSERACT_PATH.
To keep config.json somewhere else, point the OCRMYPDF_MCP_CONFIG env var at it.
Claude Desktop setup
Add to your claude_desktop_config.json (Settings → Developer → Edit Config), inside "mcpServers":
"ocrmypdf": {
"command": "python",
"args": ["C:\\path\\to\\ocrmypdf-mcp\\ocrmypdf_server.py"]
}
If Claude Desktop can't find python, use the full path to your interpreter. Restart Claude Desktop; four new tools should appear.
Usage examples
Ask Claude things like:
- "Check whether
C:\scans\paper.pdfneeds OCR." - "Do a dry run of batch OCR on my Zotero storage folder and tell me how many files would be processed."
- "OCR the first 10 scanned PDFs in
D:\archive, English plus Czech." - "OCR the Zotero attachment
AB12CD34in place."
A sensible workflow for a large Zotero library:
batch_ocr_folderwithdry_run: true, then pollbatch_status→ see the scopebatch_ocr_folderwithlimit: 5→ verify quality on a handful of files- Full run — start the job, then check
batch_statusoccasionally (OCR is CPU-intensive; a large library can take hours)
Long runs and client timeouts
MCP clients abort tool calls that take too long — Claude Desktop's limit is about 60 seconds and is not configurable. Even scanning a large library for text layers can exceed that, let alone OCR-ing it.
batch_ocr_folder therefore returns immediately with a job_id while the work continues inside the server process. Poll batch_status for counters (scanned, processed, skipped, failed), the file currently being OCR'd, and recent per-file results. cancel_batch stops a job cleanly between files.
Notes:
- Jobs live in server memory. If the MCP client (and thus the server) restarts, the job stops — files already OCR'd keep their text layer, no file is left half-written (OCRmyPDF replaces files atomically on success), and you can simply start the batch again: already-processed files are skipped.
ocr_pdfandocr_zotero_attachmentrun synchronously. For a single normal-sized document they finish well within the timeout; a very large single PDF (hundreds of scanned pages) may exceed it — the client shows an error, but the OCR still completes in the background and the file gets its text layer.
How it decides what to skip
A PDF is considered "already searchable" if its content streams (including Form XObjects) contain a meaningful number of PDF text-show operators. This is a fast heuristic — a stray stamp, watermark, or publisher header won't count as a real text layer.
Files that pass the check are never opened for writing. Files that fail it are OCR'd in OCRmyPDF's redo_ocr mode, which handles mixed pages correctly: existing real text (e.g. a journal header on a scanned page) is kept, image regions get OCR text, and nothing is rasterized. If you enable deskew or rotate (incompatible with redo_ocr), the tool falls back to skip_text mode, which skips any page already containing text.
License
MIT — see LICENSE. OCRmyPDF itself is licensed under MPL-2.0 and is used here as an unmodified dependency.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。