mcp-pdf
v1.1.0
Published
A Model Context Protocol server for PDF manipulation and operations
Maintainers
Readme
PDF MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with comprehensive PDF manipulation capabilities. This server enables natural language interactions with PDF documents through powerful editing, form filling, page manipulation, and security tools.
🚀 Quick Install
For Claude Desktop Users
Quick Setup (NPX - No Installation Required):
- Add to Claude Desktop config (see Installation section below)
- Restart Claude Desktop
- Start using PDF tools!
Or Install Globally:
npm install -g mcp-pdf
# Then configure Claude Desktop (see Installation section)For Cursor IDE Users
- Configure Cursor MCP settings (see Installation section below)
- Restart Cursor IDE
- PDF tools will be available in chat!
✨ Tip: Use NPX method - no installation required! The package downloads automatically when needed.
✨ Features
📄 Document Operations
- Open PDFs - Load and read PDF files with session management
- Create PDFs - Generate new blank PDF documents
- Save PDFs - Save modified PDFs to file system
- Get Info - Retrieve metadata, page count, size, encryption status
📝 Form Operations
- List Form Fields - Discover all form fields with types and values
- Fill Form Field - Populate a single form field (text, checkbox, radio, dropdown)
- Fill Form Fields - Fill multiple form fields at once with a single operation
- Get Form Values - Export all form data
- Flatten Forms - Make form fields non-editable
✏️ Editing Operations
- Add Text - Insert text at specific coordinates with styling
- Add Images - Embed images into PDF pages
- Add Annotations - Create comments, highlights, and notes
- Add Watermarks - Apply text or image watermarks to all pages
- Modify Metadata - Update title, author, subject, keywords
📑 Page Operations
- List Pages - Get page dimensions and information
- Merge PDFs - Combine multiple PDF documents
- Split PDFs - Split PDF into separate files (one per page)
- Rotate Pages - Rotate specific pages
- Delete Pages - Remove pages from PDF
- Extract Pages - Extract pages to new PDF file
✍️ Signature Operations
- Visual Signatures - Add image-based signatures
- Signature Fields - Create signature fields in forms
- Digital Signatures - Apply digital signatures with certificates (requires implementation)
- Verify Signatures - Check existing digital signatures
🔒 Security Operations
- Encrypt PDFs - Add password protection (limited support)
- Set Permissions - Control printing, copying, editing permissions
- Get Security Info - Check encryption and permission status
📤 Export Operations
- Extract Text - Extract all text content (requires additional implementation)
- Extract Images - Extract embedded images (requires additional implementation)
- Export Form Data - Export form data to JSON or CSV
- Compress PDFs - Optimize PDF file size
🛠️ Installation
Prerequisites
- Node.js (v18 or higher) - Download Node.js
- Cursor IDE or Claude Desktop installed
📱 Installation for Cursor IDE
Cursor IDE supports MCP servers through its configuration. Follow these steps:
Step 1: Install Node.js
Ensure Node.js (v18 or higher) is installed:
node --version # Should be v18.0.0 or higherStep 2: Configure Cursor IDE
Open Cursor Settings:
- Press
Cmd+,(macOS) orCtrl+,(Windows/Linux) to open settings - Or go to
Cursor→Settings→Features→Model Context Protocol
- Press
Add MCP Server Configuration:
The configuration file location depends on your OS:
- macOS:
~/Library/Application Support/Cursor/User/globalStorage/mcp.json - Windows:
%APPDATA%\Cursor\User\globalStorage\mcp.json - Linux:
~/.config/Cursor/User/globalStorage/mcp.json
- macOS:
Edit the Configuration File:
Create or edit the
mcp.jsonfile and add:{ "mcpServers": { "mcp-pdf": { "command": "npx", "args": ["-y", "mcp-pdf"] } } }Alternative (if using global installation):
{ "mcpServers": { "mcp-pdf": { "command": "pdf-mcp" } } }Restart Cursor IDE:
- Completely quit Cursor (not just close the window)
- Reopen Cursor to apply the changes
Verify Installation:
- Open a chat in Cursor
- The PDF tools should now be available in the MCP tools menu
🖥️ Installation for Claude Desktop
Claude Desktop uses a configuration file to connect to MCP servers.
Step 1: Install Node.js
Ensure Node.js (v18 or higher) is installed:
node --version # Should be v18.0.0 or higherStep 2: Install the Package (Optional but Recommended)
Option A: Use NPX (No Installation Required)
# No installation needed - npx will download and run automaticallyOption B: Install Globally
npm install -g mcp-pdfStep 3: Configure Claude Desktop
Locate the Configuration File:
The configuration file location depends on your OS:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
Create or Edit the Configuration File:
If the file doesn't exist, create it. Then add or update the
mcpServerssection:{ "mcpServers": { "mcp-pdf": { "command": "npx", "args": ["-y", "mcp-pdf"] } } }If you installed globally, use:
{ "mcpServers": { "mcp-pdf": { "command": "pdf-mcp" } } }If you have multiple MCP servers, merge them:
{ "mcpServers": { "mcp-pdf": { "command": "npx", "args": ["-y", "mcp-pdf"] }, "other-server": { "command": "npx", "args": ["-y", "other-package"] } } }Restart Claude Desktop:
- Completely quit Claude Desktop (not just close the window)
- Reopen Claude Desktop to apply the changes
Verify Installation:
- Open Claude Desktop
- Start a conversation
- The PDF tools should be available - try asking: "What PDF tools are available?"
Quick Setup Script (macOS/Linux)
You can use this command to quickly add the configuration:
# For Claude Desktop (macOS)
mkdir -p ~/Library/Application\ Support/Claude
cat > ~/Library/Application\ Support/Claude/claude_desktop_config.json << 'EOF'
{
"mcpServers": {
"mcp-pdf": {
"command": "npx",
"args": ["-y", "mcp-pdf"]
}
}
}
EOF🔧 Troubleshooting
Common Issues
1. MCP server not appearing:
- Verify Node.js is installed:
node --version - Check the configuration file syntax (must be valid JSON)
- Ensure you completely restarted the application (quit and reopen)
- Check application logs for errors
2. "Command not found" errors:
- If using global installation, ensure npm global bin is in your PATH
- Try using
npxmethod instead (no installation required) - Verify the package name:
mcp-pdf(notpdf-mcp)
3. Configuration file not found:
- Create the directory if it doesn't exist
- Ensure you're using the correct path for your OS
- Check file permissions
4. Tools not working:
- Verify the MCP server is running (check application logs)
- Ensure you're using absolute paths for PDF files
- Check that PDF files exist and are readable
Verify Installation
Test the installation:
# Test CLI (if installed globally)
pdf-mcp --version
# Test with npx
npx mcp-pdf --version📦 Alternative Installation Methods
Install from source:
git clone https://github.com/nitaiaharoni1/pdf-mcp.git
cd pdf-mcp
npm install
npm run build
npm start🎯 Available Tools
The PDF MCP server provides 30+ powerful tools for PDF manipulation:
Document Tools
open_pdf- Open and read PDF file informationcreate_pdf- Create new blank PDF or from templatesave_pdf- Save PDF to file systemclose_pdf- Close PDF and cleanup resourcesget_pdf_info- Get metadata, page count, size, encryption status
Form Tools
list_form_fields- List all form fields with types and valuesfill_form_field- Fill a specific form field (text, checkbox, radio, dropdown)fill_form_fields- Fill multiple form fields at once (batch operation)get_form_values- Get all current form valuesflatten_form- Flatten form to make fields non-editable
Editing Tools
add_text- Add text to PDF at coordinates with stylingadd_image- Insert image into PDFadd_annotation- Add comments, highlights, notesadd_watermark- Add text or image watermarkmodify_metadata- Update title, author, subject, keywords
Page Tools
get_pages- List all pages with dimensionsmerge_pdfs- Combine multiple PDFssplit_pdf- Split PDF into separate filesrotate_page- Rotate specific pagesdelete_pages- Remove pages from PDFextract_pages- Extract pages to new PDF
Signature Tools
add_visual_signature- Add image-based signaturecreate_signature_field- Create signature field in formsign_pdf_digital- Apply digital signature with certificateverify_signature- Verify existing digital signatures
Security Tools
encrypt_pdf- Add password protection and permissionsdecrypt_pdf- Remove password protectionset_permissions- Set printing, copying, editing permissionsget_security_info- Check encryption and permissions
Export Tools
extract_text- Extract all text contentextract_images- Extract embedded imagesexport_form_data- Export form data to JSON/CSVcompress_pdf- Optimize PDF file size
🖥️ CLI Commands
The pdf-mcp package provides several command-line tools:
Setup Commands
pdf-mcp init [directory]- Initialize PDF working directorypdf-mcp init ~/my-pdfs pdf-mcp init # Uses default: ~/pdf-mcp
Management Commands
pdf-mcp status- Show current configuration and active sessionspdf-mcp status
Testing Commands
pdf-mcp test [pdf_path]- Test PDF operations with a sample PDFpdf-mcp test /path/to/sample.pdf
Information Commands
pdf-mcp --help/-h- Show help informationpdf-mcp --version/-v- Show version information
💡 Usage Examples
Basic PDF Operations
"Open the PDF at /path/to/document.pdf"
"Create a new PDF document"
"Save the PDF to /path/to/output.pdf"
"Get information about the current PDF"Form Operations
"List all form fields in this PDF"
"Fill the 'name' field with 'John Doe'"
"Fill multiple form fields: name='John Doe', email='[email protected]', agree=true"
"Get all form values"
"Flatten the form to make it non-editable"Editing Operations
"Add text 'DRAFT' at coordinates 100, 100 on page 1"
"Add an image from /path/to/image.png to page 1"
"Add a watermark 'CONFIDENTIAL' to all pages"
"Update the PDF title to 'My Document'"Page Operations
"List all pages with their dimensions"
"Merge /path/to/file1.pdf and /path/to/file2.pdf"
"Split this PDF into separate files"
"Rotate page 2 by 90 degrees"
"Delete pages 3 and 4"
"Extract pages 1-5 to a new PDF"Signature Operations
"Add a visual signature from /path/to/signature.png to page 1"
"Create a signature field named 'signature' on page 1"Export Operations
"Export form data to /path/to/output.json as JSON"
"Export form data to /path/to/output.csv as CSV"
"Compress this PDF and save to /path/to/compressed.pdf"🔧 Configuration
Environment Variables
PDF_WORKING_DIR- Working directory for PDF operations (default:~/pdf-mcp)TEMP_DIR- Temporary directory for PDF operations (default:/tmp/pdf-mcp)
File Paths
All file paths must be absolute paths. Relative paths are not supported for security reasons.
Session Management
PDF documents are managed through sessions. Each opened or created PDF gets a unique session ID that is used for subsequent operations. Sessions are automatically cleaned up after 1 hour of inactivity.
🧪 Testing
The PDF MCP server includes testing capabilities:
# Test PDF operations
pdf-mcp test /path/to/sample.pdf
# Run unit tests (if available)
npm test🏗️ Development
Local Development Setup
Clone the repository:
git clone https://github.com/nitaiaharoni1/pdf-mcp.git cd pdf-mcpInstall dependencies:
npm installBuild the project:
npm run buildTest locally:
npm run dev
📋 Technical Details
Primary Library
- pdf-lib - Comprehensive PDF operations (forms, editing, page manipulation)
Storage
- Local file system only with absolute path support
Session Management
- Maintains open PDF documents in memory with unique IDs
- Automatic cleanup of inactive sessions
Error Handling
- Graceful handling of corrupted PDFs
- Permission error handling
- Unsupported feature detection
Limitations
- Digital Signatures: Requires additional implementation with node-forge
- Text Extraction: Requires pdfjs-dist or similar library
- Image Extraction: Requires PDF parsing library
- Encryption: pdf-lib has limited encryption support
📄 License
MIT License - See the LICENSE file for complete terms and conditions.
🙋♂️ Support
- GitHub Issues: Report bugs or request features
- Documentation: This README and inline code documentation
- Community: Contributions and discussions welcome!
Made with ❤️ for the AI and PDF processing community
