Skip to main content
Glama

PDF Redaction MCP Server

PDF Redaction MCP Server

A Model Context Protocol (MCP) server for PDF redaction using PyMuPDF (fitz). This server provides tools for loading PDFs, identifying and redacting sensitive text, and saving redacted documents.

Features

  • šŸ“„ Load and read PDF files - Extract text content from PDFs for review

  • šŸ” Text-based redaction - Search and redact specific text strings across all pages

  • šŸ“ Area-based redaction - Redact specific rectangular regions by coordinates

  • šŸ’¾ Save redacted PDFs - Apply redactions and save with automatic naming

  • šŸŽØ Customizable redaction appearance - Choose redaction fill colors

  • šŸ”’ Error handling - Comprehensive error messages via MCP protocol

Installation

This project uses uv for package management. To install:

# Clone the repository git clone <your-repo-url> cd redact_mcp # Install with uv uv pip install -e .

Usage

Running the Server

You can run the server using either the Python script directly or the FastMCP CLI:

Option 1: Direct Python execution (stdio transport)

python -m redact_mcp.server

Option 2: Using FastMCP CLI

# Stdio transport (default) fastmcp run redact_mcp.server:mcp # HTTP transport for remote access fastmcp run redact_mcp.server:mcp --transport http --port 8000

Installing in MCP Clients

Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{ "mcpServers": { "pdf-redaction": { "command": "uv", "args": [ "--directory", "/path/to/redact_mcp", "run", "fastmcp", "run", "redact_mcp.server:mcp" ] } } }

Other MCP Clients

Use the FastMCP CLI to generate configuration for other clients:

# For Cursor fastmcp install cursor redact_mcp.server:mcp # For Gemini CLI fastmcp install gemini-cli redact_mcp.server:mcp # Generate generic MCP JSON configuration fastmcp install mcp-json redact_mcp.server:mcp

Available Tools

1. load_pdf

Load a PDF file and extract its text content.

Parameters:

  • pdf_path (string): Path to the PDF file to load

Returns: The full text content of the PDF, organized by pages

Example:

Load the PDF at /path/to/document.pdf

2. redact_text

Redact all instances of specific text in a loaded PDF.

Parameters:

  • pdf_path (string): Path to the loaded PDF file

  • text_to_redact (string): Text string to search for and redact

  • fill_color (tuple, optional): RGB color (0-1 range) for redaction box. Default: (0, 0, 0) - black

Returns: Summary of redaction operations

Example:

Redact all instances of "confidential" in /path/to/document.pdf

3. redact_area

Redact a specific rectangular area on a PDF page.

Parameters:

  • pdf_path (string): Path to the loaded PDF file

  • page_number (int): Page number (1-indexed)

  • x0 (float): Left x coordinate

  • y0 (float): Top y coordinate

  • x1 (float): Right x coordinate

  • y1 (float): Bottom y coordinate

  • fill_color (tuple, optional): RGB color (0-1 range) for redaction box. Default: (0, 0, 0) - black

Returns: Confirmation message

Example:

Redact the area from (100, 100) to (300, 150) on page 1 of /path/to/document.pdf

4. save_redacted_pdf

Apply all pending redactions and save the PDF.

Parameters:

  • pdf_path (string): Path to the loaded PDF file

  • output_path (string, optional): Custom output path. If not provided, appends "_redacted" to original filename

Returns: Path to the saved redacted PDF

Example:

Save the redacted version of /path/to/document.pdf

5. list_loaded_pdfs

List all currently loaded PDF files.

Parameters: None

Returns: List of loaded PDF paths with page counts

6. close_pdf

Close a loaded PDF and free its resources.

Parameters:

  • pdf_path (string): Path to the PDF file to close

Returns: Confirmation message

Workflow Example

Here's a typical workflow using this MCP server:

  1. Load a PDF

    Load the PDF at /Users/me/documents/sensitive.pdf
  2. Review the content The tool will return the full text content, which you can review to identify sensitive information.

  3. Redact sensitive text

    Redact all instances of "Social Security Number" in /Users/me/documents/sensitive.pdf Redact all instances of "123-45-6789" in /Users/me/documents/sensitive.pdf
  4. Redact specific areas (optional)

    Redact the area from (50, 100) to (200, 120) on page 2 of /Users/me/documents/sensitive.pdf
  5. Save the redacted PDF

    Save the redacted version of /Users/me/documents/sensitive.pdf

    This will create /Users/me/documents/sensitive_redacted.pdf

  6. Close the PDF (optional)

    Close /Users/me/documents/sensitive.pdf

Technical Details

Dependencies

  • FastMCP (>=2.12.0): Python framework for building MCP servers

  • PyMuPDF (>=1.24.0): PDF manipulation library (imported as fitz)

Architecture

  • In-memory storage: Loaded PDFs are kept in memory for fast access during redaction operations

  • Lazy application: Redaction annotations are added but not applied until save_redacted_pdf is called

  • Error handling: Uses FastMCP's ToolError for proper error propagation to MCP clients

  • Context logging: All operations log to the MCP context for transparency

Limitations (Current Version)

  • Text-only redaction: This version focuses on text redaction. Image redaction is not yet implemented.

  • Memory usage: PDFs are kept in memory while loaded. Very large PDFs may consume significant memory.

  • Single session: The in-memory store is not persistent across server restarts.

Development

Running Tests

# Install development dependencies uv pip install -e ".[dev]" # Run tests (when implemented) pytest

Code Structure

redact_mcp/ ā”œā”€ā”€ src/ │ └── redact_mcp/ │ ā”œā”€ā”€ __init__.py # Package initialization │ └── server.py # Main MCP server implementation ā”œā”€ā”€ pyproject.toml # Package configuration └── README.md # This file

License

[Add your license here]

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Acknowledgments

Deploy Server
-
security - not tested
F
license - not found
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Enables loading, reviewing, and redacting sensitive content in PDF documents through text-based or area-based redaction methods. Supports customizable redaction appearance and saves redacted PDFs with comprehensive error handling.

  1. Features
    1. Installation
      1. Usage
        1. Running the Server
        2. Installing in MCP Clients
      2. Available Tools
        1. 1. load_pdf
        2. 2. redact_text
        3. 3. redact_area
        4. 4. save_redacted_pdf
        5. 5. list_loaded_pdfs
        6. 6. close_pdf
      3. Workflow Example
        1. Technical Details
          1. Dependencies
          2. Architecture
          3. Limitations (Current Version)
        2. Development
          1. Running Tests
          2. Code Structure
        3. License
          1. Contributing
            1. Acknowledgments

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/marc-hanheide/redact_mcp'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server