PDF MCP Server

PDF MCP Server

An MCP server for PDF form filling, basic editing, and OCR text extraction. It enables users to merge, rotate, annotate, and sign PDFs, while also supporting text extraction from both searchable and scanned image-based documents.

Category
访问服务器

README

PDF MCP Server

MCP server for PDF form filling, basic editing (merge, extract, rotate, flatten), and OCR text extraction. Built with Python, pypdf, fillpdf, and pymupdf (AGPL).

Goal: Extract 99% of information from any PDF file, including scanned/image-based documents, and fill any PDF forms.

Status

CI CodeQL

CI notes

  • Dependency Review requires GitHub Dependency Graph to be enabled in the repository settings.
  • AI Review is optional and only runs if you add the OPENAI_API_KEY repository secret.

Setup (uv)

  1. Install uv if not present:
curl -Ls https://astral.sh/uv/install.sh | sh
  1. Install dependencies (project root is this folder):
cd /path/to/pdf-mcp-server
uv pip install -r requirements.txt

Or use the Makefile:

cd /path/to/pdf-mcp-server
make install

For best flatten support, install Poppler:

sudo apt-get install poppler-utils

OCR Support (Optional)

For OCR capabilities on scanned/image-based PDFs, install Tesseract:

macOS:

brew install tesseract
pip install pytesseract pillow

Linux (Ubuntu/Debian):

sudo apt-get install tesseract-ocr
pip install pytesseract pillow

Or install with the ocr extra:

pip install -e ".[ocr]"

Run the MCP server

python -m pdf_mcp.server

(It runs over stdio by default.)

Register with Cursor

Edit ~/.cursor/mcp.json:

{
  "mcpServers": {
    "pdf-handler": {
      "command": "/path/to/pdf-mcp-server/.venv/bin/python",
      "args": ["-m", "pdf_mcp.server"],
      "description": "Local PDF form filling and editing (stdio)"
    }
  }
}

Restart Cursor after saving.

Available tools (initial)

  • get_pdf_form_fields(pdf_path): list fields and count.
  • fill_pdf_form(input_path, output_path, data, flatten=False): fill fields; optional flatten (uses fillpdf if available, else pypdf fallback).
  • clear_pdf_form_fields(input_path, output_path, fields=None): clear (delete) values for selected form fields while keeping fields fillable.
  • flatten_pdf(input_path, output_path): flatten forms/annotations.
  • merge_pdfs(pdf_list, output_path): merge multiple PDFs.
  • extract_pages(input_path, pages, output_path): 1-based pages, supports negatives (e.g., -1 = last).
  • rotate_pages(input_path, pages, degrees, output_path): degrees must be multiple of 90.
  • add_text_annotation(input_path, page, text, output_path, rect=None, annotation_id=None): add a FreeText annotation (managed text insertion).
  • update_text_annotation(input_path, output_path, annotation_id, text, pages=None): update an annotation by id.
  • remove_text_annotation(input_path, output_path, annotation_id, pages=None): remove an annotation by id.
  • remove_annotations(input_path, output_path, pages, subtype=None): remove annotations on pages, optionally filtered by subtype (example FreeText).
  • insert_pages(input_path, insert_from_path, at_page, output_path): insert all pages from another PDF before at_page (1-based).
  • remove_pages(input_path, pages, output_path): remove specific 1-based pages.
  • insert_text(input_path, page, text, output_path, rect=None, text_id=None): insert text via a managed FreeText annotation.
  • edit_text(input_path, output_path, text_id, text, pages=None): edit managed inserted text.
  • remove_text(input_path, output_path, text_id, pages=None): remove managed inserted text.
  • get_pdf_metadata(pdf_path): return basic PDF document metadata.
  • set_pdf_metadata(input_path, output_path, title=None, author=None, subject=None, keywords=None): set basic metadata fields.
  • add_text_watermark(input_path, output_path, text, pages=None, rect=None, annotation_id=None): add a simple text watermark or stamp via FreeText annotations.
  • add_comment(input_path, output_path, page, text, pos, comment_id=None): add a PDF comment (Text annotation, sticky note).
  • update_comment(input_path, output_path, comment_id, text, pages=None): update a PDF comment by id.
  • remove_comment(input_path, output_path, comment_id, pages=None): remove a PDF comment by id.
  • add_signature_image(input_path, output_path, page, image_path, rect): add a signature image to a page (returns signature_xref).
  • update_signature_image(input_path, output_path, page, signature_xref, image_path=None, rect=None): update or resize a signature image.
  • remove_signature_image(input_path, output_path, page, signature_xref): remove a signature image.
  • encrypt_pdf(input_path, output_path, user_password, owner_password=None, ...): encrypt (password-protect) a PDF (use after add_signature_image to protect a signed PDF).

OCR and Text Extraction Tools

  • detect_pdf_type(pdf_path): analyze PDF to classify as "searchable", "image_based", or "hybrid"; returns page-by-page metrics and OCR recommendation.
  • extract_text_native(pdf_path, pages=None): extract text using native PDF text layer only (fast, no OCR).
  • extract_text_ocr(pdf_path, pages=None, engine="auto", dpi=300, language="eng"): extract text with OCR fallback; engine options: "auto" (native→OCR), "native", "tesseract", "force_ocr".
  • get_pdf_text_blocks(pdf_path, pages=None): extract text blocks with bounding box positions (useful for form field detection).

Conventions

  • Paths should be absolute; outputs are created with parent directories if missing.
  • Inputs must exist and be files; errors return { "error": "..." }.
  • Form flattening prefers fillpdf+poppler; falls back to a pypdf-only flatten (removes form structures).
  • Text insert/edit/remove is implemented via managed FreeText annotations, not by editing PDF content streams.

Smoke tests (manual)

python - <<'PY'
from pdf_mcp import pdf_tools
sample = "/path/to/sample.pdf"
out = "/tmp/out.pdf"
print(pdf_tools.get_pdf_form_fields(sample))
print(pdf_tools.fill_pdf_form(sample, out, {"Name": "Test"}, flatten=True))
PY

Automated tests

cd /path/to/pdf-mcp-server
make test

Development workflow

  • Use feature branches off main and open a PR for review.
  • Keep each PR focused on a single tool or capability with tests.
  • For larger features, split into small PRs (tool surface, core implementation, tests, docs).
  • After merging a PR, delete the feature branch and run git fetch --prune locally to keep branch state clean.
  • Portability/migration notes: see PROJECT_MEMO/.

License

GNU AGPL-3.0, see LICENSE.

Changelog

See CHANGELOG.md.

推荐服务器

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

官方
精选