pdf-edit-mcp
CLAUDE.md1 starsChanged 6 months agoMITView on GitHub
MCP server for format-preserving PDF text editing, powered by pdf-edit-engine (Python). As of v0.2.0 this is a single-process Python (FastMCP) server — the engine is imported in-process. (The v0.1.x TypeScript server + bridge.py subprocess are gone; see git history / CHANGELOG.) Import-cycle rule: mcp and engine_lock live in app.py (a leaf). Tool modules import them from app, never from server. server imports the tool modules at the bottom for decorator side-effects. Do not move mcp/engine_lock back into server — that…
- Installs packages
The file
We split this CLAUDE.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 50
Never accept a bare str for a path.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
pdf-edit-mcp
MCP server for format-preserving PDF text editing, powered by
pdf-edit-engine (Python). As of
v0.2.0 this is a single-process Python (FastMCP) server — the engine is
imported in-process. (The v0.1.x TypeScript server + bridge.py subprocess are
gone; see git history / CHANGELOG.)
Architecture
Claude / AI Agent
↓ MCP protocol (stdio)
pdf_edit_mcp (FastMCP server, this package)
↓ in-process import
pdf-edit-engine (Python library: pikepdf + fonttools + pdfminer)Module layout (dependency order)
__init__.py __version__
app.py FastMCP `mcp` instance + `engine_lock` ← dependency LEAF
constants.py input bounds (single source of truth)
validation.py path_safety_error + PdfPath/OutputPath/DirPath + BBox/EditItem/BlockReplacement
serialize.py serialize_edit_result + aggregate_fidelity (exact wire shapes)
_runtime.py engine_guard (lock + error translation), READ_ONLY/WRITE annotations, page_count
tools_read.py 9 read tools tools_edit.py 7 edit tools
tools_sections.py 3 section tools tools_document.py 15 document tools
tools_annotations.py 5 annotation tools prompts.py 3 prompts
server.py version gate + main(); imports the tool/prompt modules to register themImport-cycle rule: mcp and engine_lock live in app.py (a leaf). Tool
modules import them from app, never from server. server imports the tool
modules at the bottom for decorator side-effects. Do not move mcp/engine_lock
back into server — that reintroduces the server → tools_* → _runtime → server
cycle.
Critical rules
- stdout is the MCP transport — never
print()to stdout; diagnostics go tostderr(the engine version gate already does this). - The engine is NOT thread-safe — every engine call goes through
_runtime.engine_guard(), which holds the module-levelengine_lock. New tools must wrap their engine work inwith engine_guard():. - Path validation is a security boundary — path parameters use the
PdfPath/OutputPath/DirPathvalidated types fromvalidation.py(absolute,.pdf, no..traversal, no control chars, no Windows reserved/truncated basenames). Never accept a barestrfor a path. - Error model — engine
PDFEditErrorsubclasses are translated byengine_guardintoToolErrorwith a classified message + recovery hint. RaisePDFEditErrorfor in-tool validation; do not leak raw pikepdf exceptions. - Engine version gate —
server._check_engine_version()exits non-zero if the installedpdf-edit-engine < 0.2.0(relies on thepassword=kwargs,fit=, and the 30-kind degradation taxonomy). - mypy --strict + ruff clean —
mypy src/pdf_edit_mcpandruff check src/ tests/must pass.server.pyhas a per-file E402 ignore (intentional bottom-of-file registration imports).
Conventions
- Tool function names ARE the wire names —
pdf_*exactly (e.g.pdf_delete_annotation_v2). Prompts use@mcp.prompt(name="...")for the hyphenated wire names. - Page parameters are named
page, 0-indexed.pdf_batch_replace_blockkeepspage_numberas a deprecated alias (preferpage; both → error if neither set). - Bounds come from
constants.py— never inline a magic number. password=is exposed only on the direct-verb read/edit tools whose engine call accepts it — NOT on composite tools (pdf_inspect, the section tools) or the document wrappers (the engine wrapper functions don't take it).- Return shapes are pinned by the test suite — preserve
serialize_edit_result's exact dict shape and each tool's documented return keys.
Section detection lives in tools_sections.py
_detect_sections / _swap_sections / _replace_section are an MCP-side
font-hierarchy heuristic + orchestration ported verbatim from the old bridge.py
(detect output is byte-identical, verified by differential). This logic could move
into pdf_edit_engine.structural so non-MCP callers reuse it; tracked for a future
release. Do not extend the MCP-side detector with significant new logic — push new
work into the engine first.
Development
pip install -e ".[dev]"
ruff check src/ tests/
mypy src/pdf_edit_mcp
pytest tests/ -q # fixtures auto-generated via reportlab (tests/conftest.py)Distribution: PyPI (uvx pdf-edit-mcp). Build with python -m build; publish with
twine (manual, mirroring the engine's release process).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

