PD

PDF Tools MCP Server: Merge, Split, Encrypt, Optimize

Manage PDFs on an MCP server, merge, split, encrypt, optimize and automate workflows with a fast, comprehensive manipulation toolkit.

Quick Install
npx -y @Sohaib-2/pdf-mcp-server

Overview

This MCP (Model Context Protocol) server provides a focused PDF manipulation toolkit intended for developer workflows and agent integrations. It exposes HTTP endpoints that let you merge, split, encrypt, optimize, and otherwise process PDF files, enabling automated document pipelines, pre-processing for downstream models, or ad-hoc developer tools. Because it follows a simple service interface, it is easy to incorporate into CI jobs, serverless functions, or Model Context Protocol-enabled agents.

The server is designed to be fast and composable: endpoints accept uploaded PDFs (or remote file URLs), run common transformations, and return optimized files or metadata. Typical uses include preparing documents for storage, creating client-ready bundles, and protecting content with encryption. The repo and code are intended for developers who want an extensible PDF service they can host locally or in production.

Features

  • Merge multiple PDFs into a single document
  • Split PDFs by page ranges or extract individual pages
  • Encrypt and decrypt PDFs (password-protect and remove protection)
  • Optimize and compress PDFs for web or archival use
  • Metadata reading and basic validation (page count, size, encryption status)
  • File upload/download endpoints suitable for automation and agent use
  • Docker-friendly and configurable via environment variables

Installation / Configuration

Clone the repository and run using Docker, or install and run locally with Node.js (if a JS implementation is provided). The examples below are generic; consult the repository README for implementation-specific details.

Clone repository:

git clone https://github.com/Sohaib-2/pdf-mcp-server.git
cd pdf-mcp-server

Run with Docker:

# Build (if Dockerfile is present)
docker build -t pdf-mcp-server .

# Run
docker run -d --name pdf-mcp \
  -p 8080:8080 \
  -e PORT=8080 \
  -e UPLOAD_DIR=/data/uploads \
  -v "$(pwd)/data":/data \
  pdf-mcp-server

Run locally (Node.js example):

# Install and run (if package.json exists)
npm install
npm start
# or
node src/server.js

Sample environment file (.env):

PORT=8080
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=50mb
AUTH_TOKEN=your-secret-token
ENABLE_CORS=true

Available Tools / API Endpoints

Below is a representative set of endpoints commonly exposed by this kind of server. Exact endpoints and parameters may vary—check the project repository for full API documentation.

MethodPathPurposeKey parameters
POST/mergeCombine multiple PDFs into onefiles[] (multipart), output_name
POST/splitSplit a PDF by page rangesfile (multipart), ranges (e.g. “1-3,5,7-9”)
POST/encryptAdd password protectionfile, password, algorithm(optional)
POST/decryptRemove password protectionfile, password
POST/optimizeCompress/linearize for webfile, quality (low/medium/high)
GET/infoReturn PDF metadatafile_id or URL
GET/healthHealth check

Example merge request (cURL):

curl -X POST "http://localhost:8080/merge" \
  -H "Authorization: Bearer your-token" \
  -F "files[][email protected]" \
  -F "files[][email protected]" \
  -F "output_name=combined-report.pdf" \
  --output combined-report.pdf

Example split request:

curl -X POST "http://localhost:8080/split" \
  -H "Authorization: Bearer your-token" \
  -F "[email protected]" \
  -F "ranges=1-5,10-12" \
  --output split-results.zip

Use Cases

  • Automating post-processing in document ingestion pipelines: receive uploaded PDFs, run /optimize, extract metadata with /info, then store optimized output in cloud storage.
  • Generating client deliverables: merge multiple generated PDFs into a single package before sending to a customer or for archival.
  • Securing documents before distribution: use /encrypt to password-protect sensitive output produced by other services.
  • Preparing content for LLM agents: split large PDFs into smaller sections with /split, then feed page-level content to a model as part of an MCP context provider.
  • Serverless handlers and webhooks: attach the MCP server to file upload events; when a PDF is uploaded, automatically run /optimize and /encrypt, then return the link to downstream systems.

Concrete workflow example: automated monthly report bundle

  1. Daily jobs generate several PDF reports into a storage folder.
  2. A small orchestrator calls the MCP server /merge endpoint with all daily PDFs.
  3. The merged PDF is passed to /optimize (quality=medium).
  4. The optimized file is encrypted and uploaded to an archive bucket, and a metadata record is written with /info data.

Tips for Developers

  • Secure endpoints with an Authorization token or integrate with your existing auth layer.
  • For large files, ensure your server and reverse proxy (Nginx, Cloud Run) are configured for the appropriate max body size and streaming.
  • Use the /info endpoint to preflight operations (e.g., check page count) before expensive transforms.
  • Consider running optimization as an async job for very large files and return a job ID or webhook callback on completion.

For implementation details, API reference, and advanced configuration options, see the project’s repository: https://github.com/Sohaib-2/pdf-mcp-server