PDF Manipulation MCP Server
š This project is entirely based on
A study project implementing a Model Context Protocol (MCP) server that provides comprehensive PDF manipulation capabilities using the official MCP FastMCP framework. This project focuses on direct PDF editing and manipulation features for learning and experimentation purposes.
Quick Start: Run directly with uv run pdf-manipulation-mcp-server (like npx for Node.js packages)
Features
Text Operations: Add, replace, and manipulate text in PDFs
Image Operations: Add images and extract images from PDFs
Annotations: Add various types of annotations (text, highlight, underline, etc.)
Form Fields: Add and fill form fields
Page Manipulation: Merge, split, rotate, delete, and crop pages
Auto-Crop: Automatically detect and crop content boundaries
Page Combination: Combine multiple pages into single pages with various layouts
Metadata: Get and set PDF metadata
Quick Start
Prerequisites
Python 3.10+
pip (comes with Python)
š For detailed installation instructions, see
Installation
Option 1: Run Directly with UV (Like npx)
Option 2: Install from PyPI
Option 3: Install from GitHub
Option 4: Clone and Install Locally
Option 5: Using UV (Development)
Available Tools (15 Total)
Text Operations
pdf_add_text- Add text to a PDF at specified positionpdf_replace_text- Replace text in a PDF document
Image Operations
pdf_add_image- Add an image to a PDFpdf_extract_images- Extract all images from a PDF
Annotations
pdf_add_annotation- Add annotations to a PDF (text, highlight, underline, strikeout)
Form Fields
pdf_add_form_field- Add form fields to a PDF (text, checkbox, radio, combobox)pdf_fill_form- Fill form fields in a PDF with values
Page Manipulation
pdf_merge_files- Merge multiple PDF files into onepdf_combine_pages_to_single- Combine multiple pages from a PDF into a single pagepdf_split- Split a PDF into individual pages or page rangespdf_rotate_page- Rotate a page in a PDF (90, 180, 270 degrees)pdf_delete_page- Delete a page from a PDFpdf_crop_page- Crop a page in a PDF with coordinate supportpdf_auto_crop_page- Automatically crop pages by detecting content boundaries
Metadata
pdf_get_info- Get metadata and information about a PDFpdf_set_metadata- Set metadata for a PDF
How to Configure with Cursor IDE
Step 1: Install the Server
Follow the installation steps above to set up the MCP server.
Step 2: Configure Cursor IDE
Add this configuration to your Cursor settings:
Option A: Using an MCP config and uvx:
Create ~/.cursor/mcp_config.json:
Option B: Using MCP Config File from a local installation
Create ~/.cursor/mcp_config.json:
Option C: Using Cursor Settings UI
Open Cursor Settings (
Cmd+,on Mac,Ctrl+,on Windows/Linux)Search for "MCP" in settings
Add this configuration:
Step 3: Restart Cursor IDE
After adding the configuration, restart Cursor IDE to load the MCP server.
Step 4: Test the Integration
Open a new chat in Cursor
Try these commands:
"Convert this PDF to Markdown"
"Add text to a PDF"
"Extract images from a PDF"
"Merge multiple PDFs"
Usage Examples
Basic PDF Auto-Crop Workflow
Adding Text to PDF
Working with Images
Page Manipulation
Development
Project Structure
Running Tests
Dependencies
mcp- Official MCP SDK for Pythonpymupdf- Core PDF manipulation librarypytest- Testing framework (dev dependency)pytest-asyncio- Async testing support (dev dependency)
File Safety
All operations create new files with timestamps to avoid overwriting originals. Output files follow the pattern: {original_name}_{operation}_{timestamp}.pdf
Error Handling
The server includes comprehensive error handling:
Validates PDF files before operations
Checks page numbers and coordinates
Provides clear error messages
Handles missing files gracefully
Catches and reports PyMuPDF exceptions
Troubleshooting
Common Issues
"No tools" in Cursor settings: This is normal! Tools appear in the chat interface, not in settings.
UV not found: Install UV first:
curl -LsSf https://astral.sh/uv/install.sh | shPython version error: UV will automatically install Python 3.11+ if needed.
Dependencies not found: Make sure you're using UV:
uv pip install mcp pymupdf
Debug Mode
To run the server in debug mode:
Contributing
This is a study project, but contributions are welcome! If you'd like to contribute:
Fork the repository
Create a feature branch
Make your changes
Test with
uv run pytest tests/ -vSubmit a pull request
Study Project Notes
This project was created as a learning exercise to explore:
Model Context Protocol (MCP) server development
PDF manipulation using PyMuPDF
FastMCP framework implementation
Automated testing with pytest
Content detection and cropping algorithms
License
This project is open source and available under the MIT License.
Support
For issues and questions:
Check the troubleshooting section above
Review the test output:
uv run python test_mcp_server.pyCheck Cursor logs for MCP errors
Open an issue on GitHub
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
Enables comprehensive PDF operations including text/image manipulation, annotations, form fields, page merging/splitting/cropping, and metadata management using PyMuPDF.