Skip to main content

MCP Server

paperjam ships with an MCP (Model Context Protocol) server, making it the first document processing library with native AI-agent support. Any MCP-compatible client -- Claude Code, Claude Desktop, Cursor, or custom agents -- can open, extract from, convert, and manipulate documents through a standard tool interface.

What is MCP?

The Model Context Protocol is an open standard for connecting AI models to external tools and data sources. Instead of writing custom glue code for each AI integration, you register an MCP server and the model discovers its capabilities automatically.

Installation

# Run directly (no install needed)
uvx paperjam-mcp

# Or install globally
pip install paperjam-mcp

Verify the installation:

paperjam-mcp --version

Configuration

Claude Code

Add the server to your project's .mcp.json:

{
"mcpServers": {
"paperjam": {
"command": "uvx",
"args": ["paperjam-mcp", "--working-dir", "."]
}
}
}

Claude Desktop

Add to your claude_desktop_config.json:

{
"mcpServers": {
"paperjam": {
"command": "uvx",
"args": ["paperjam-mcp", "--working-dir", "/Users/you/Documents"]
}
}
}

Cursor

Add to .cursor/mcp.json:

{
"mcpServers": {
"paperjam": {
"command": "uvx",
"args": ["paperjam-mcp", "--working-dir", "."]
}
}
}

Server options

FlagDefaultDescription
--working-dir.Base directory for resolving relative file paths. All file access is sandboxed to this directory.
--transportstdioTransport: stdio or sse
--port8080Port for SSE transport
--max-sessions50Maximum concurrent document sessions
--session-ttl3600Session time-to-live in seconds (resets on each access)
--log-levelwarningLogging verbosity: debug, info, warning, error

Available tools

Once connected, the AI model can call these tools through the MCP protocol.

Document management

ToolDescription
open_documentOpen a document by path. Returns a session ID.
get_document_infoGet page count, metadata, format, and structural summary.
save_documentSave the current document state to disk.
close_documentClose a session and free resources.
list_sessionsList all open document sessions.

Extraction

ToolDescription
extract_textExtract plain text from all pages.
extract_tablesExtract tables as structured data (rows, headers, cells).
extract_structureExtract headings, paragraphs, and list items.
to_markdownConvert the document to Markdown.
search_documentFull-text search with regex support (PDF only).
extract_linksExtract all hyperlinks (PDF only).
extract_imagesExtract image metadata from a page (PDF only).
extract_bookmarksExtract bookmark/TOC tree.

Page operations

ToolDescription
page_get_infoPage dimensions and rotation.
page_extract_textText from a specific page.
page_extract_tablesTables from a specific page.
page_extract_structureStructure from a specific page.
page_analyze_layoutDetect columns, headers, footers.
page_to_markdownConvert a page to Markdown.

Manipulation

ToolDescription
split_documentSplit by page ranges into multiple sessions.
merge_documentsMerge multiple PDFs into one session.
reorder_pagesReorder, subset, or duplicate pages.
delete_pagesRemove specific pages.
insert_blank_pagesAdd blank pages at positions.
rotate_pagesRotate specific pages.
optimize_documentCompress and reduce file size.

Annotations & stamps

ToolDescription
add_watermarkApply a text watermark to pages.
add_annotationAdd annotation (text, highlight, stamp, etc.).
remove_annotationsRemove annotations by type or index.
stamp_pagesOverlay a page from another PDF.

Metadata & TOC

ToolDescription
set_metadataUpdate title, author, subject, keywords.
set_bookmarksSet/replace bookmarks.
generate_tocAuto-generate TOC from headings.

Comparison

ToolDescription
diff_documentsText-level diff between two PDFs.
visual_diffPixel-level visual comparison.

Conversion

ToolDescription
convert_documentConvert between formats (PDF, DOCX, XLSX, PPTX, HTML, EPUB, Markdown).
convert_fileDirect file-to-file conversion.
detect_formatDetect document format from path.

Rendering

ToolDescription
render_pageRender a page to PNG/JPEG/BMP. Max 600 DPI.
render_pagesRender multiple pages to images. Max 50 pages per call.

Forms

ToolDescription
has_formCheck if document has a form.
get_form_fieldsList all form fields.
fill_formFill form fields by name/value.
modify_form_fieldModify field properties.
add_form_fieldCreate a new form field.

Security

ToolDescription
sanitize_documentRemove JavaScript, actions, embedded files, and links.
redact_textFind and permanently redact text by query or regex.
redact_regionsRedact rectangular areas.
encrypt_documentPassword-protect a document with AES-128, AES-256, or RC4.

Digital signatures

ToolDescription
get_signaturesExtract signature info.
verify_signaturesVerify all signatures.
sign_documentDigitally sign a PDF.

Validation

ToolDescription
validate_pdf_aCheck PDF/A compliance.
validate_pdf_uaCheck PDF/UA accessibility.
convert_to_pdf_aConvert to PDF/A.

Example interaction

Here is what a typical AI-agent conversation looks like when the MCP server is connected:

User: "Summarize the Q3 financial report and redact all Social Security numbers."

The agent would call the following tools in sequence:

  1. open_document with path: "Q3_report.pdf" -- receives session ID
  2. extract_text with the session ID -- reads the full document text
  3. to_markdown with the session ID -- gets a structured version for summarization
  4. redact_text with query: "\\b\\d{3}-\\d{2}-\\d{4}\\b" and use_regex: true
  5. save_document with path: "Q3_report_redacted.pdf"
  6. close_document to release the session

The agent uses the extracted Markdown to write a summary, while the redacted PDF is saved to disk.

Session management

The MCP server maintains document sessions. When a client calls open_document, the server loads the file into memory and returns a session ID. Subsequent tool calls reference this ID to operate on the same document without re-reading from disk.

Sessions are lightweight -- the document is loaded once and shared across all operations. The server enforces a maximum session count (--max-sessions) to bound memory usage. Sessions expire after the TTL (--session-ttl) of inactivity and are released when the client calls close_document or when the server shuts down.

Multiple documents can be open simultaneously in separate sessions:

  1. open_document("invoice.pdf") -- session s1
  2. open_document("contract.docx") -- session s2
  3. extract_tables on s1
  4. to_markdown on s2
  5. close_document on s1 and s2

Security

The MCP server enforces a working directory sandbox:

  • All file paths are resolved relative to --working-dir
  • Paths that escape the working directory (e.g. ../../etc/passwd) are rejected
  • Absolute paths outside the working directory are rejected

Pipeline tools (run_pipeline, validate_pipeline) are disabled because they perform file I/O with their own path resolution that bypasses the sandbox. Use individual tools instead.

Error handling

Tool calls return structured JSON errors when something goes wrong:

  • File not found -- the path does not exist or is outside the working directory
  • Path escapes working directory -- the resolved path is outside the sandbox
  • Invalid session -- the session ID is expired or unrecognised
  • Unsupported operation -- e.g. calling redact_text on an XLSX document
  • Conversion error -- the requested format conversion is not supported

The AI model receives these errors as tool-call responses and can decide how to proceed (retry, ask the user, or try a different approach).