Skip to main content
Glama
marc-hanheide

PDF Redaction MCP Server

redact_area

Add redaction annotations to specific rectangular areas on PDF pages by defining coordinates. Use this tool to mark sensitive content for removal before applying final redactions.

Instructions

Redact a specific rectangular area on a PDF page.

This tool adds a redaction annotation for a specific rectangular area defined by coordinates. The redactions are not yet applied to the document - use save_redacted_pdf to apply and save.

Args: pdf_path: Path to the PDF file (must be already loaded) page_number: Page number to redact (1-indexed) x0: Left x coordinate of the rectangle y0: Top y coordinate of the rectangle x1: Right x coordinate of the rectangle y1: Bottom y coordinate of the rectangle fill_color: RGB color tuple (0-1 range) for the redaction box. Default is black. ctx: MCP context for logging

Returns: Confirmation message

Raises: ToolError: If the PDF is not loaded, page doesn't exist, or redaction fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYesPath to the loaded PDF file
page_numberYesPage number (1-indexed)
x0YesLeft x coordinate
y0YesTop y coordinate
x1YesRight x coordinate
y1YesBottom y coordinate
fill_colorNoRGB color for redaction (values 0-1). Default is black (0,0,0)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'redact_area' MCP tool. It adds a redaction annotation to a specified rectangular area on a given page of a loaded PDF using PyMuPDF's fitz library. The @mcp.tool decorator handles both registration and schema definition via Annotated type hints and Field descriptions.
    @mcp.tool
    async def redact_area(
        pdf_path: Annotated[str, Field(description="Path to the loaded PDF file")],
        page_number: Annotated[int, Field(description="Page number (1-indexed)", ge=1)],
        x0: Annotated[float, Field(description="Left x coordinate")],
        y0: Annotated[float, Field(description="Top y coordinate")],
        x1: Annotated[float, Field(description="Right x coordinate")],
        y1: Annotated[float, Field(description="Bottom y coordinate")],
        fill_color: Annotated[tuple[float, float, float], Field(
            description="RGB color for redaction (values 0-1). Default is black (0,0,0)"
        )] = (0, 0, 0),
        ctx: Context = None
    ) -> str:
        """Redact a specific rectangular area on a PDF page.
        
        This tool adds a redaction annotation for a specific rectangular area
        defined by coordinates. The redactions are not yet applied to the document -
        use save_redacted_pdf to apply and save.
        
        Args:
            pdf_path: Path to the PDF file (must be already loaded)
            page_number: Page number to redact (1-indexed)
            x0: Left x coordinate of the rectangle
            y0: Top y coordinate of the rectangle
            x1: Right x coordinate of the rectangle
            y1: Bottom y coordinate of the rectangle
            fill_color: RGB color tuple (0-1 range) for the redaction box. Default is black.
            ctx: MCP context for logging
            
        Returns:
            Confirmation message
            
        Raises:
            ToolError: If the PDF is not loaded, page doesn't exist, or redaction fails
        """
        try:
            path = Path(pdf_path).resolve()
            path_str = str(path)
            
            await ctx.info(f"Redacting area on page {page_number} in: {path}")
            
            # Check if PDF is loaded
            if path_str not in _loaded_pdfs:
                raise ToolError(
                    f"PDF not loaded. Please load it first using load_pdf: {path}"
                )
            
            doc = _loaded_pdfs[path_str]
            
            # Validate page number
            if page_number < 1 or page_number > len(doc):
                raise ToolError(
                    f"Invalid page number {page_number}. PDF has {len(doc)} pages."
                )
            
            # Validate color values
            if not all(0 <= c <= 1 for c in fill_color):
                raise ToolError("RGB color values must be between 0 and 1")
            
            # Get the page (0-indexed internally)
            page = doc[page_number - 1]
            
            # Create rectangle and add redaction
            rect = fitz.Rect(x0, y0, x1, y1)
            page.add_redact_annot(rect, fill=fill_color)
            
            await ctx.info(f"Added area redaction on page {page_number}")
            
            return (
                f"Added redaction for area ({x0}, {y0}, {x1}, {y1}) on page {page_number}.\n"
                + "Note: Redaction is marked but not yet applied. "
                + "Use save_redacted_pdf to apply and save the changes."
            )
            
        except ToolError:
            raise
        except Exception as e:
            await ctx.error(f"Failed to redact area: {str(e)}")
            raise ToolError(f"Failed to redact area: {str(e)}")
  • Input schema defined using Pydantic's Annotated and Field for the redact_area tool parameters, including descriptions, constraints (e.g., ge=1 for page_number), and default value for fill_color.
    pdf_path: Annotated[str, Field(description="Path to the loaded PDF file")],
    page_number: Annotated[int, Field(description="Page number (1-indexed)", ge=1)],
    x0: Annotated[float, Field(description="Left x coordinate")],
    y0: Annotated[float, Field(description="Top y coordinate")],
    x1: Annotated[float, Field(description="Right x coordinate")],
    y1: Annotated[float, Field(description="Bottom y coordinate")],
    fill_color: Annotated[tuple[float, float, float], Field(
        description="RGB color for redaction (values 0-1). Default is black (0,0,0)"
    )] = (0, 0, 0),
  • The @mcp.tool decorator from FastMCP registers the redact_area function as an MCP tool, automatically using the function name, docstring, and type hints for tool metadata.
    @mcp.tool
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by explaining key behavioral traits: it's a preparatory step (redactions not applied yet), requires a loaded PDF, has specific error conditions (PDF not loaded, page doesn't exist), and returns a confirmation message. It doesn't cover rate limits or auth needs but provides substantial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, behavior, parameters, returns, errors) and appropriately sized. The first sentence immediately states the core purpose. Some redundancy exists between parameter descriptions and schema, but overall it's efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (7 parameters, mutation operation) and no annotations, the description provides good coverage: explains purpose, behavior, parameters, returns, and error conditions. With an output schema present, it doesn't need to detail return values. It could mention sibling tools more explicitly but is largely complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds minimal value beyond the schema by briefly explaining coordinate parameters and the default fill_color, but doesn't provide additional semantic context like coordinate system details or practical usage examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('redact a specific rectangular area'), resource ('on a PDF page'), and distinguishes from siblings by noting redactions are not yet applied, differentiating from save_redacted_pdf. It provides a precise verb+resource combination.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool ('adds a redaction annotation') and when not to use it ('redactions are not yet applied - use save_redacted_pdf to apply and save'). It provides clear context but does not mention alternatives like redact_text or prerequisites beyond PDF loading.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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