Logo de PDF Manipulation

PDF Manipulation

Comunidade
andr3medeiros

A study project: MCP server for direct PDF manipulation and editing

Publicado porandr3medeiros
Repositóriopdf-manipulation-mcp-server
IdiomaPython
Forks
3
Estrelas
9
Ferramentas disponíveis
16
Tipo de transportestdio
Categorias
LicençaMIT
Links
  • Conecte ferramentas a fluxos de trabalho de IA

    PDF Manipulation disponibiliza recursos MCP que podem ser usados por clientes e agentes de IA compatíveis.

  • 16 ferramentas disponíveis

    Confira abaixo as ações que podem ser chamadas, incluindo nomes e descrições quando fornecidos pelo servidor.

  • Configuração pronta para copiar

    Use os exemplos de instalação para configurar este servidor no seu cliente MCP preferido.

  • Indicadores da comunidade de código aberto

    9 estrelas e 3 forks no repositório vinculado.

PDF Manipulation MCP Server

📚 This project is entirely based on PyMuPDF - a powerful Python library for PDF manipulation. Please check out the official PyMuPDF documentation to learn more about its extensive capabilities!

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 INSTALL.md

Installation

Option 1: Run Directly with UV (Like npx)

bash
# Run without installation (fastest)
uv run pdf-manipulation-mcp-server

Option 2: Install from PyPI

bash
# Install the package
pip install pdf-manipulation-mcp-server

# Run the server
pdf-mcp-server

Option 3: Install from GitHub

bash
# Install directly from GitHub
pip install git+https://github.com/yourusername/pdf-manipulation-mcp-server.git

# Run the server
pdf-mcp-server

Option 4: Clone and Install Locally

bash
# Clone the repository
git clone https://github.com/yourusername/pdf-manipulation-mcp-server.git
cd pdf-manipulation-mcp-server

# Install in development mode
pip install -e .

# Run the server
pdf-mcp-server

Option 5: Using UV (Development)

bash
# Clone the repository
git clone https://github.com/yourusername/pdf-manipulation-mcp-server.git
cd pdf-manipulation-mcp-server

# Install dependencies with UV
uv pip install mcp pymupdf

# Test the server
uv run pytest tests/ -v

# Run the server
uv run python server.py

Available Tools (15 Total)

Text Operations

  • pdf_add_text - Add text to a PDF at specified position
  • pdf_replace_text - Replace text in a PDF document

Image Operations

  • pdf_add_image - Add an image to a PDF
  • pdf_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 one
  • pdf_combine_pages_to_single - Combine multiple pages from a PDF into a single page
  • pdf_split - Split a PDF into individual pages or page ranges
  • pdf_rotate_page - Rotate a page in a PDF (90, 180, 270 degrees)
  • pdf_delete_page - Delete a page from a PDF
  • pdf_crop_page - Crop a page in a PDF with coordinate support
  • pdf_auto_crop_page - Automatically crop pages by detecting content boundaries

Metadata

  • pdf_get_info - Get metadata and information about a PDF
  • pdf_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:

json
{
  "mcpServers": {
    "pdf-manipulation": {
      "command": "uvx",
      "args": ["--from", "pdf-manipulation-mcp-server", "pdf-mcp-server"]
    }
  }
}

Option B: Using MCP Config File from a local installation

Create ~/.cursor/mcp_config.json:

json
{
  "mcpServers": {
    "pdf-manipulation": {
      "command": "uv",
      "args": ["run", "python", "server.py"],
      "cwd": "/path/to/pdf-manipulation-mcp-server"
    }
  }
}

Option C: Using Cursor Settings UI

  1. Open Cursor Settings (Cmd+, on Mac, Ctrl+, on Windows/Linux)
  2. Search for "MCP" in settings
  3. Add this configuration:
json
{
  "mcp.servers": {
    "pdf-manipulation": {
      "command": "uv",
      "args": ["run", "python", "server.py"],
      "cwd": "/path/to/pdf-manipulation-mcp-server"
    }
  }
}

Step 3: Restart Cursor IDE

After adding the configuration, restart Cursor IDE to load the MCP server.

Step 4: Test the Integration

  1. Open a new chat in Cursor
  2. 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

python
# Automatically crop PDF pages to remove margins
result = await pdf_auto_crop_page(
    pdf_path="document.pdf",
    padding=10.0
)

# Crop specific page with coordinates
result = await pdf_crop_page(
    pdf_path="document.pdf",
    page_number=0,
    x0=50, y0=50, x1=400, y1=300,
    coordinate_mode="bbox"
)

Adding Text to PDF

python
result = await pdf_add_text(
    pdf_path="document.pdf",
    page_number=0,
    text="New text content",
    x=100,
    y=100,
    font_size=14,
    color=[1, 0, 0]  # Red color
)

Working with Images

python
# Add image to PDF
result = await pdf_add_image(
    pdf_path="document.pdf",
    page_number=0,
    image_path="image.png",
    x=100,
    y=200,
    width=200,
    height=150
)

# Extract all images from PDF
result = await pdf_extract_images(
    pdf_path="document.pdf",
    output_dir="extracted_images"
)

Page Manipulation

python
# Merge multiple PDFs
result = await pdf_merge_files(
    pdf_paths=["doc1.pdf", "doc2.pdf", "doc3.pdf"]
)

# Combine pages from a single PDF
result = await pdf_combine_pages_to_single(
    pdf_path="document.pdf",
    page_numbers=[0, 1, 2],
    layout="vertical"
)

# Split PDF into individual pages
result = await pdf_split(
    pdf_path="document.pdf",
    output_dir="split_pages"
)

# Rotate a page
result = await pdf_rotate_page(
    pdf_path="document.pdf",
    page_number=0,
    rotation=90
)

Development

Project Structure

pdf-manipulation-mcp-server/
├── pdf_server.py          # Main MCP server implementation
├── server.py              # Entry point for UV
├── test_mcp_server.py     # Test script
├── pyproject.toml         # Project configuration
├── install.sh             # Installation script (Mac/Linux)
├── install.bat            # Installation script (Windows)
└── README.md              # This file

Running Tests

bash
# Test the MCP server
uv run python test_mcp_server.py

# Run the server
uv run python server.py

Dependencies

  • mcp - Official MCP SDK for Python
  • pymupdf - Core PDF manipulation library
  • pytest - 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

  1. "No tools" in Cursor settings: This is normal! Tools appear in the chat interface, not in settings.

  2. UV not found: Install UV first:

    bash
    curl -LsSf https://astral.sh/uv/install.sh | sh
  3. Python version error: UV will automatically install Python 3.11+ if needed.

  4. Dependencies not found: Make sure you're using UV:

    bash
    uv pip install mcp pymupdf

Debug Mode

To run the server in debug mode:

bash
uv run python server.py --debug

Contributing

This is a study project, but contributions are welcome! If you'd like to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test with uv run pytest tests/ -v
  5. Submit 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:

  1. Check the troubleshooting section above
  2. Review the test output: uv run python test_mcp_server.py
  3. Check Cursor logs for MCP errors
  4. Open an issue on GitHub

Instalação

TypingMind
Pré-requisitos:

Node.js 18+

{
  "mcpServers": {
    "pdf-manipulation": {
      "command": "uvx",
      "args": [
        "--from",
        "pdf-manipulation-mcp-server",
        "pdf-mcp-server"
      ]
    }
  }
}

Ferramentas disponíveis

  • pdf_add_text

    Add text to a PDF at a specified position.

  • pdf_replace_text

    Replace text in a PDF document.

  • pdf_add_image

    Add an image to a PDF.

  • pdf_extract_images

    Extract all images from a PDF.

  • pdf_add_annotation

    Add an annotation to a PDF.

  • pdf_add_form_field

    Add a form field to a PDF.

  • pdf_fill_form

    Fill form fields in a PDF with values.

  • pdf_merge_files

    Merge multiple PDF files into one combined PDF.

  • pdf_combine_pages_to_single

    Combine multiple pages from a PDF into a single page with specified layout.

  • pdf_split

    Split a PDF into individual pages or page ranges.

  • pdf_rotate_page

    Rotate a page in a PDF.

  • pdf_delete_page

    Delete a page from a PDF.

  • pdf_crop_page

    Crop a page in a PDF.

  • pdf_auto_crop_page

    Automatically crop a PDF page to remove blank margins by detecting content boundaries.

  • pdf_get_info

    Get metadata and information about a PDF.

  • pdf_set_metadata

    Set metadata for a PDF.

Use o MCP de PDF Manipulation com vários modelos de IA

O TypingMind conecta as ferramentas MCP no nível do espaço de trabalho. Assim, após conectar PDF Manipulation, é possível usá-lo com diferentes modelos de IA no TypingMind, em vez de configurá-lo separadamente para cada modelo. Este MCP é executado localmente no seu dispositivo por meio do conector MCP do TypingMind.

Guia de configuração para usar o conector local

Use esta opção quando o servidor MCP precisar acessar arquivos locais, aplicativos ou recursos privados no seu computador.

1

Abra as configurações de MCP

No TypingMind, vá até Configurações, Configurações avançadas e depois Model Context Protocol e selecione Configurar conector.

  1. Abra o TypingMind no navegador.
  2. Clique no ícone de Ajustes.
  3. Acesse Configurações avançadas.
  4. Abra a seção Model Context Protocol.
  5. Clique em Configurar conector e selecione Este dispositivo.
Tela de configuração do conector MCP do TypingMind com a opção Este dispositivo selecionada
2

Execute o comando do conector

Selecione Este dispositivo, copie o comando do TypingMind e execute-o no Terminal. Mantenha o processo em execução enquanto usa o MCP.

  1. Copie o comando de configuração exibido pelo TypingMind.
  2. Abra o Terminal no macOS ou o Windows Terminal no Windows.
  3. Cole e execute o comando.
  4. Autorize a instalação do pacote se o Terminal pedir confirmação para continuar.
  5. Mantenha o processo em execução na janela do Terminal enquanto usa as ferramentas MCP.
3

Adicione PDF Manipulation como servidor

Quando o status do conector for Pronto, clique em Editar e cole a configuração do servidor MCP.

  1. Aguarde até que o status do conector mostre Pronto.
  2. Clique em Editar.
  3. Cole a configuração do servidor MCP de PDF Manipulation.
  4. Salve a lista de servidores.
  5. Atualize para confirmar se o conector ainda está pronto para uso.
Configurações de MCP do TypingMind mostrando um servidor ativo e o botão Editar
{
  "mcpServers": {
    "pdf-manipulation": {
      "command": "npx",
      "args": [
        "-y",
        "pdf-manipulation-mcp-server"
      ]
    }
  }
}
4

Use a conexão com diferentes modelos

Salve a lista de servidores, abra Plugins, ative as ferramentas MCP de PDF Manipulation, selecione qualquer modelo de IA compatível no TypingMind e use as ferramentas no chat ou atribua-as a um agente de IA.

  1. Abra a página Plugins no TypingMind.
  2. Ative as ferramentas MCP de PDF Manipulation.
  3. Inicie um chat e escolha o modelo de IA que deseja usar.
  4. Use as ferramentas MCP no chat ou atribua-as a um agente de IA.
  5. Mude para outro modelo de IA sempre que necessário, sem reconectar o MCP.
Chat do TypingMind usando ferramentas MCP ativadas com um modelo de IA selecionado
Pode usar PDF Manipulation para me ajudar nesta tarefa?
PDF Manipulation
Claro. Já li.
Veja o que encontrei usando PDF Manipulation.

Perguntas frequentes

Para que serve o servidor MCP PDF Manipulation?

PDF Manipulation é um servidor MCP que permite que aplicativos de IA compatíveis se conectem a ferramentas externas e informações de contexto. No TypingMind, basta adicionar esse servidor MCP uma vez para disponibilizar suas ferramentas no seu espaço de trabalho com IA.

Posso usar o MCP PDF Manipulation com vários modelos de IA no TypingMind?

Sim. O TypingMind conecta as ferramentas MCP no nível do espaço de trabalho, permitindo usar PDF Manipulation com diferentes modelos de IA, como Claude, ChatGPT, Gemini ou outros modelos configurados no TypingMind, sem configurar o servidor MCP separadamente para cada modelo.

Por que usar o MCP PDF Manipulation com o TypingMind?

O TypingMind é uma das melhores interfaces de chat com LLMs porque reúne vários modelos de IA, prompts, plugins, agentes de IA, chaves de API e ferramentas MCP em um só espaço de trabalho. Com PDF Manipulation conectado, é possível usar suas ferramentas MCP nos seus modelos preferidos e manter seu fluxo de trabalho de chat organizado no TypingMind.

Como conecto o MCP PDF Manipulation ao TypingMind?

PDF Manipulation funciona por meio do conector MCP local do TypingMind. Essa é a melhor opção quando o servidor MCP precisa acessar arquivos locais, apps de desktop, ferramentas de linha de comando ou recursos privados no seu computador.

Quais ferramentas o MCP PDF Manipulation oferece no TypingMind?

PDF Manipulation disponibiliza 16 ferramentas MCP que podem ser ativadas na página Plugins do TypingMind e usadas no chat ou atribuídas a agentes de IA.

Preciso compartilhar minhas chaves de API com o TypingMind para usar o MCP PDF Manipulation?

Não. O TypingMind prioriza o uso local e permite manter seus provedores de modelos, chaves de API, prompts e configuração MCP sob seu controle. Se PDF Manipulation exigir autenticação, adicione os cabeçalhos, as configurações OAuth ou a configuração local exigidos por esse servidor MCP ao criar a conexão.

Servidores MCP relacionados

Ver todos

Crie seu próprio espaço de IA agora

Inscreva-se na nossa newsletter para receber novidades sobre recursos e futuros sorteios 👇