localpdf-mcp
v0.1.6Local PDF tools for AI agents: inspect, merge, split, compress, OCR.
Local, offline PDF engine for AI agents, exposed as an MCP server. The agent decides, the document stays put: every tool runs in this process on your machine, makes no network requests at all, and returns metadata — paths, sizes, sha256, counts — instead of document bytes or document text. Status: 0.1.6, published on npm as localpdf-mcp. Requires Node 22+. No hosted service and no phone-home: nothing in this package calls localpdf.online or any other server.
Summary extracted from the README.
localpdf-mcp
Local, offline PDF engine for AI agents, exposed as an MCP server.
The agent decides, the document stays put: every tool runs in this process on your machine, makes no network requests at all, and returns metadata — paths, sizes, sha256, counts — instead of document bytes or document text.
Status: 0.1.6, published on npm as localpdf-mcp. Requires Node 22+. No hosted service and no phone-home:
nothing in this package calls localpdf.online or any other server.
Why this exists and where it stops: https://localpdf.online/pdf-mcp-server. The browser workspace that shares the same approach is at https://localpdf.online/app.
Tools
| Tool | What it does | Returns |
|---|---|---|
pdf_inspect |
page count, size, encryption flag, producer | metadata only |
pdf_merge |
concatenate 2+ PDFs in order | out path, pages, sha256 |
pdf_split |
each requested page into its own file | file list with per-file sha256 |
pdf_compress |
structural resave with object streams | before/after bytes + honest % |
pdf_extract_text |
text layer → .txt on disk | per-page char counts; text only with inline: true |
pdf_replace_text |
find a string, draw white patch + replacement | matches, bbox, page; mode: "overlay" |
pdf_ocr |
invisible text layer for scans (tesseract, local traineddata) | per-page lines/chars/confidence |
Page numbers are 1-based. The input file is never overwritten — out must differ.
Install
Zero-install (npx fetches the package and its deps once):
npx -y localpdf-mcp # speaks MCP on stdio; nothing on stdout except protocol
From a checkout, if you want to hack on it:
git clone https://github.com/ulinycoin/localpdf-mcp && cd localpdf-mcp
npm install
node src/server.mjs
OCR is an optional extra: npm i tesseract.js @tesseract.js-data/eng @napi-rs/canvas
(plus @tesseract.js-data/rus for Russian). Without them the other six tools work and
pdf_ocr returns a clear "dependencies not installed" error.
The invisible OCR layer embeds a bundled Roboto subset that covers Latin,
Cyrillic and Greek — Russian text used to fail with WinAnsi cannot encode "П".
A line in another script (CJK, Arabic) has no glyphs in that font, so it is
skipped and counted in lines_skipped instead of being written with holes.
Claude Code
claude mcp add localpdf -- npx -y localpdf-mcp
Claude Desktop / Cursor / other JSON-config clients
{
"mcpServers": {
"localpdf": {
"command": "npx",
"args": ["-y", "localpdf-mcp"]
}
}
}
Verify
node test/mcp-client.mjs # real MCP handshake: initialize, tools/list, tools/call
node test/smoke.mjs # 12 checks on real generated PDFs
What "offline" is proven by, not promised
Two independent gates, both run in CI-able form:
# 1. every socket/DNS/fetch attempt throws (also inherited by the tesseract child process)
NODE_OPTIONS="--import ./test/deny-net.mjs" node test/smoke.mjs
# 2. the OS denies the network for the whole process tree
sandbox-exec -p '(version 1)(allow default)(deny network*)' node test/smoke.mjs
Both pass with OCR enabled. The things that would otherwise phone home are pinned locally:
- pdfjs standard fonts →
node_modules/pdfjs-dist/standard_fonts/(standardFontDataUrl) - tesseract traineddata → staged from
node_modules/@tesseract.js-data/*into~/.localpdf-mcp/tmp/tessdata(by default tesseract.js fetches from jsDelivr — seetesseract.js/src/worker-script/index.js) - no analytics, no version check, no network reporting: a local usage count
(
~/.localpdf-mcp/usage.jsonl: tool, outcome, version) stays on disk and is never sent
Local usage count
The server appends one line per tool call to ~/.localpdf-mcp/usage.jsonl:
tool name, outcome (ok/error) and version. No arguments, paths, file names or
document contents, and nothing leaves the machine — this package has no network
code, and the gates above deny it.
Print the aggregate yourself:
npx localpdf-mcp usage
Nothing is sent automatically; share the output only if you choose to.
Privacy boundary — read this before quoting anything
This server keeps the engine and the files local. It cannot keep your agent local:
- What the model reads is gone. If your agent opens the PDF and reasons about its contents, that text goes to the model provider's context and logs. Nothing in this package changes that.
- Tool results are metadata on purpose. Returning document bytes in a tool result
would ship the whole file into the model context — the classic MCP data leak. Tools
return paths;
pdf_extract_textreturns text only with an explicitinline: true, and says so in the result. - Local is not the same as unsynced. Scratch files live in
~/.localpdf-mcp/tmp(mode 0700) and are pruned after an hour, precisely because~/Desktopand~/Documentsmay be synced to iCloud Drive — a document leak with no HTTP request involved. PointLOCALPDF_MCP_WORKDIRsomewhere unsynced if you disagree.
So the honest claim is: the engine and the files stay on your machine; whatever your agent reads itself goes to its provider. "No leak at all" is only true when the model is local too (Ollama, LM Studio), not when it is a cloud agent.
Known limitations
pdf_replace_textis an overlay, not a content-stream edit: a white patch and new drawn text on top. The original text layer survives, so search and copy-paste return the old string as well as the new one. Fine for cosmetic fixes; not for redaction.- Fonts are substituted with Helvetica → correct for Latin-1, wrong for Cyrillic/CJK.
pdf_compressdoes no image recompression. Text-only PDFs may not shrink at all, and already-optimised files can grow — the tool reports the real numbers instead of guessing.- OCR languages installed offline:
eng,rus. Add more withnpm i @tesseract.js-data/<lang>and one line insrc/engine.mjs. - Encrypted PDFs are reported by
pdf_inspectbut not decrypted.
Layout
src/server.mjs MCP surface (zod schemas, 7 tools)
src/engine.mjs tool implementations, pdf-lib + pdfjs + tesseract, zero network
src/workdir.mjs scratch dir (~/.localpdf-mcp/tmp), input/out collision guard
test/ smoke, MCP client, network-deny preload
get-started.md the playbook you hand to an agent (Vercel-style onboarding)