PDF Tools MCP Server
pdf-tools-mcp is a FastAPI-based server for reading and manipulating PDF documents. It provides a RESTful API for common PDF operations like splitting, merging, extracting pages, adding content, watermarking, converting, compression, and OCR. The current version is 0.1.4, and its release cadence is irregular, driven by feature additions and maintenance.
Warnings
- gotcha pdf-tools-mcp is primarily designed as a standalone FastAPI server, not a Python library for direct function calls. Its core functionality is exposed via HTTP endpoints. Attempting to import and use internal modules directly without running the server might lead to unexpected behavior or incomplete functionality.
- gotcha Several advanced features like OCR, HTML to PDF conversion, and advanced PDF generation depend on optional 'extras' dependencies. If you don't install these, the corresponding API endpoints or features will not work and might return HTTP 500 errors or validation failures.
- breaking The library explicitly requires Python 3.12 or newer. Running it with older Python versions (e.g., 3.11 or 3.10) will result in installation failures or runtime errors due to syntax or dependency incompatibilities.
- gotcha When interacting with file upload endpoints (e.g., for splitting or merging PDFs), ensure you correctly format your `multipart/form-data` request. For Python's `requests` library, use the `files` parameter with a tuple `('filename', file_object, 'content_type')`.
Install
-
pip install pdf-tools-mcp -
pip install pdf-tools-mcp[ocr,weasyprint,reportlab]
Imports
- app
from pdf_tools_mcp.main import app
Quickstart
# 1. Install the library
pip install pdf-tools-mcp
# 2. Run the PDF tools server
# In your terminal, run:
# python -m pdf_tools_mcp.main
# 3. Access the API (e.g., using curl in another terminal)
# curl http://127.0.0.1:8000/api/v1/health
# Expected output for health check (after server starts):
# {"status":"ok"}
# Example Python client interaction (requires 'requests')
import requests
BASE_URL = "http://127.0.0.1:8000/api/v1"
try:
response = requests.get(f"{BASE_URL}/health")
response.raise_for_status() # Raise an exception for HTTP errors
print(f"Health check: {response.json()}")
# Example: Upload a PDF (assuming you have 'example.pdf' locally)
# with open('example.pdf', 'rb') as f:
# files = {'file': ('example.pdf', f, 'application/pdf')}
# upload_response = requests.post(f"{BASE_URL}/pdf/split", files=files,
# params={'pages': '1'})
# upload_response.raise_for_status()
# print(f"Upload/Split response: {upload_response.json()}")
except requests.exceptions.ConnectionError:
print("Error: Could not connect to the pdf-tools-mcp server. Is it running?")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")