Skip to main content
Glama

📄 MCP PDF

用于 PDF 处理的 FastMCP 服务器

47 种工具,支持文本提取、OCR、表格、表单、注释、Markdown↔PDF 转换等

Python 3.11+ FastMCP License: MIT PyPI

可与 MCP Office Tools 完美配合使用


功能概述

MCP PDF 通过多种库自动回退机制从 PDF 中提取内容。如果一种方法失败,它会自动尝试另一种。

核心能力:

  • 文本提取:通过 PyMuPDF、pdfplumber 或 pypdf(自动回退)

  • 表格提取:通过 Camelot、pdfplumber 或 Tabula(自动回退)

  • OCR:通过 Tesseract 处理扫描文档

  • 表单处理 - 提取、填写和创建 PDF 表单

  • 文档组装 - 合并、拆分、重排页面

  • 注释 - 便签、高亮、印章

  • 矢量图形 - 提取为 SVG 以用于原理图和技术绘图

  • 格式转换 - PDF ↔ Markdown(PDF→MD 通过 PyMuPDF,MD→PDF 通过 pandoc)


Related MCP server: PDF MCP Flow

快速开始

# Run from PyPI (one-shot, no permanent install)
uvx mcp-pdf

# Add to Claude Code — note the `--` separator before uvx
claude mcp add pdf-tools -- uvx mcp-pdf

# Include the markdown_to_pdf tool (requires pandoc on host)
claude mcp add pdf-tools -- uvx --from "mcp-pdf[markdown]" mcp-pdf

uvx 会积极缓存工具安装。升级到新版本后,请使用 uvx --refresh mcp-pdf 强制刷新(如果使用了扩展功能,请使用 uvx --refresh --from "mcp-pdf[markdown]" mcp-pdf)。

git clone https://github.com/rsp2k/mcp-pdf
cd mcp-pdf
uv sync

# System dependencies (Ubuntu/Debian)
sudo apt-get install tesseract-ocr tesseract-ocr-eng poppler-utils ghostscript

# For markdown_to_pdf — pick one PDF-engine route:
sudo apt-get install pandoc tectonic                                          # recommended (small)
# or:  sudo apt-get install pandoc texlive-xetex texlive-latex-extra          # full TeX
# or:  sudo apt-get install pandoc && pip install weasyprint                  # skip TeX

# Verify
uv run python examples/verify_installation.py

工具

内容提取

工具

功能

extract_text

从 PDF 页面提取文本,支持大文件自动分块

extract_tables

将表格提取为 JSON、CSV 或 Markdown

extract_images

提取嵌入的图像

extract_links

获取所有超链接,支持页面过滤

ocr_pdf

使用 Tesseract 对扫描文档进行 OCR

extract_vector_graphics

将矢量图形导出为 SVG(原理图、图表、绘图)

格式转换

工具

功能

pdf_to_markdown

将 PDF 转换为 Markdown 并保留结构;将图像和 SVG 矢量图提取到磁盘

markdown_to_pdf

通过 pandoc 将 .md 文件(或内联文本)转换为 PDF,并自动检测引擎

markdown_to_pdf 要求: pip install mcp-pdf[markdown] 以及 pandoc 二进制文件和至少一个 PDF 引擎(xelatexpdflatextectonicweasyprintwkhtmltopdf)在 PATH 中。该工具会自动检测可用引擎并使用质量最高的一个。传入 pdf_engine= 可覆盖默认设置,或使用 extra_args= 传入原始 pandoc 参数。

文档分析

工具

功能

extract_metadata

获取标题、作者、创建日期、页数等

get_document_structure

提取目录和书签

analyze_layout

检测列、页眉、页脚

is_scanned_pdf

检查 PDF 是否需要 OCR

compare_pdfs

通过文本、结构或元数据对比两个 PDF

analyze_pdf_health

检查损坏情况及优化机会

analyze_pdf_security

报告加密、权限、签名情况

表单

工具

功能

extract_form_data

获取表单字段名称和值

fill_form_pdf

从 JSON 填充表单字段

create_form_pdf

创建带有文本字段、复选框、下拉菜单的新表单

add_form_fields

向现有 PDF 添加字段

许可表单(基于坐标)

适用于扫描版 PDF 或没有交互式字段的表单。在 (x, y) 坐标处绘制文本。

工具

功能

fill_permit_form

通过在坐标处绘制内容来填充任何 PDF(适用于扫描表单)

get_field_schema

获取字段定义以进行验证或 UI 生成

validate_permit_form_data

在填充前根据字段模式验证数据

preview_field_positions

生成显示字段边界的 PDF(用于调试)

insert_attachment_pages

插入带有“见第 X 页”引用的图像/文本页面

要求: pip install mcp-pdf[forms](添加 reportlab 依赖)

文档组装

工具

功能

merge_pdfs

合并多个 PDF 并保留书签

split_pdf_by_pages

按页面范围拆分

split_pdf_by_bookmarks

按章节/部分边界拆分

reorder_pdf_pages

按自定义顺序重排页面

注释

工具

功能

add_sticky_notes

添加评论注释

add_highlights

高亮文本区域

add_stamps

添加“已批准/草稿/机密”印章

extract_all_annotations

将注释导出为 JSON


回退机制的工作原理

服务器为每个操作尝试多个库:

文本提取:

  1. PyMuPDF(最快)

  2. pdfplumber(更适合复杂布局)

  3. pypdf(兼容性最好)

表格提取:

  1. Camelot(精度最高,需要 Ghostscript)

  2. pdfplumber(无依赖)

  3. Tabula(需要 Java)

如果 PDF 在一个库中处理失败,会自动尝试下一个。


Token 管理

大型 PDF 可能会超出 MCP 响应限制。服务器处理方式如下:

  • 自动分块:将大型文档拆分为页面组

  • 表格行限制:防止超大表格导致响应溢出

  • 摘要模式:返回结构而不返回完整内容

# Get first 10 pages
result = await extract_text("huge.pdf", pages="1-10")

# Limit table rows
tables = await extract_tables("data.pdf", max_rows_per_table=50)

# Structure only
tables = await extract_tables("data.pdf", summary_only=True)

URL 处理

PDF 可以直接从 HTTPS URL 获取:

result = await extract_text("https://example.com/report.pdf")

文件会在本地缓存以供后续操作使用。


系统依赖

某些功能需要系统包:

功能

依赖

OCR

tesseract-ocr

Camelot 表格

ghostscript

Tabula 表格

default-jre-headless

PDF 转图像

poppler-utils

markdown_to_pdf

pandoc + 以下之一:tectonic, texlive-xetex (+ texlive-latex-extra), weasyprint, wkhtmltopdf

markdown_to_pdf 选择 PDF 引擎

Pandoc 将 Markdown → HTML 或 LaTeX → PDF。LaTeX 路径生成的输出最精美,但需要 TeX 安装。权衡如下:

引擎

磁盘占用

说明

tectonic

~30 MB

推荐用于新安装。 单个静态二进制文件。按需下载 LaTeX 包 — 无需预先安装大量内容。

xelatex + texlive-latex-extra

~500 MB

安装后效果最好。如果您已经运行 TeX,请使用此项。-extra 包很重要:pandoc 的默认模板需要 lastpagexcolorframedfancyhdr 等 — 所有这些都在该包中,而不是texlive-xetex 中。

xelatex 单独使用 (仅 texlive-xetex)

~200 MB

经常出错。 在真实文档上可能会遇到 ! LaTeX Error: File 'X.sty' not found

weasyprint

~40 MB

纯 Python (pip install weasyprint) + cairo/pango 系统库。HTML/CSS 路径 — 无需 LaTeX。适合简单文档;在数学公式、脚注、引用方面较弱。

wkhtmltopdf

~40 MB

较旧的 HTML 转 PDF 工具。可用但维护较少。

Ubuntu/Debian:

sudo apt-get install tesseract-ocr tesseract-ocr-eng poppler-utils ghostscript default-jre-headless

# For markdown_to_pdf — pick one engine route:

# Option A — tectonic (smallest, downloads packages on demand)
sudo apt-get install pandoc
# tectonic isn't in apt — install via cargo or download static binary:
#   https://tectonic-typesetting.github.io/en-US/install.html

# Option B — full TeX (best quality, large download)
sudo apt-get install pandoc texlive-xetex texlive-latex-extra texlive-fonts-extra

# Option C — weasyprint (skip TeX entirely)
sudo apt-get install pandoc
pip install weasyprint

Arch Linux:

sudo pacman -S tesseract tesseract-data-eng poppler ghostscript jre-openjdk-headless

# For markdown_to_pdf — pick one engine route:

# Option A — tectonic (recommended for new installs, in official repo)
sudo pacman -S pandoc tectonic

# Option B — full TeX (best output, ~500 MB)
sudo pacman -S pandoc texlive-xetex texlive-latexextra texlive-fontsextra

# Option C — weasyprint (skip TeX)
sudo pacman -S pandoc
pip install weasyprint   # or: uv pip install weasyprint

# Option D — wkhtmltopdf (from AUR)
yay -S wkhtmltopdf-static

macOS (Homebrew):

brew install tesseract poppler ghostscript

# For markdown_to_pdf — pick one engine route:

# Option A — tectonic (recommended)
brew install pandoc tectonic

# Option B — full TeX (mactex-no-gui includes the latex-extra equivalent)
brew install pandoc
brew install --cask mactex-no-gui

# Option C — weasyprint
brew install pandoc weasyprint

可选扩展

基础安装保持精简。繁重或小众的依赖项被放在扩展中:

扩展

添加内容

何时安装

mcp-pdf[forms]

reportlab

表单创建工具 (create_form_pdf, 许可表单)

mcp-pdf[tables]

camelot-py, tabula-py

高精度表格提取(还需要 Java + Ghostscript)

mcp-pdf[markdown]

pypandoc

markdown_to_pdf 工具(还需要 pandoc 二进制文件)

mcp-pdf[all]

以上所有

需要全部功能


配置

可选环境变量:

变量

用途

MCP_PDF_ALLOWED_PATHS

用于文件输出的冒号分隔目录

PDF_TEMP_DIR

处理时的临时目录(默认:/tmp/mcp-pdf-processing

TESSDATA_PREFIX

Tesseract 语言数据位置


开发

# Run tests
uv run pytest

# With coverage
uv run pytest --cov=mcp_pdf

# Format
uv run black src/ tests/

# Lint
uv run ruff check src/ tests/

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

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

Related MCP Servers

  • 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
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides intelligent OCR and PDF processing capabilities that automatically detect whether PDFs contain digital text or scanned images and apply appropriate extraction methods. Supports text extraction, OCR processing, structure analysis, and batch operations.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI applications to read and process PDF files with intelligent file search, text extraction, image processing, and optional OCR support for scanned documents.
    MIT

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rsp2k/mcp-pdf'

If you have feedback or need assistance with the MCP directory API, please join our Discord server