Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_crop_page

Crop a specific page in a PDF by defining coordinates to remove unwanted margins or content, enabling precise document editing.

Instructions

Crop a page in a PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numberYes
x0Yes
y0Yes
x1Yes
y1Yes
coordinate_modeNobbox

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'pdf_crop_page' tool. Decorated with @mcp.tool() which registers it with the FastMCP server. Implements PDF page cropping using PyMuPDF by setting the cropbox on the specified page, with support for 'bbox' (bottom-left origin) and 'rect' (top-left origin) coordinate modes. Validates inputs and generates a timestamped output file.
    @mcp.tool()
    async def pdf_crop_page(
        pdf_path: str,
        page_number: int,
        x0: float,
        y0: float,
        x1: float,
        y1: float,
        coordinate_mode: str = "bbox"
    ) -> str:
        """Crop a page in a PDF."""
        if not os.path.exists(pdf_path):
            return f"Error: PDF file not found: {pdf_path}"
        
        if not validate_pdf_file(pdf_path):
            return f"Error: Invalid PDF file: {pdf_path}"
        
        if coordinate_mode not in ["bbox", "rect"]:
            return f"Error: Invalid coordinate_mode. Must be 'bbox' or 'rect'."
        
        try:
            # Open PDF document
            doc = fitz.open(pdf_path)
            
            # Validate page number
            if not validate_page_number(doc, page_number):
                doc.close()
                return f"Error: Invalid page number {page_number}. Document has {len(doc)} pages."
            
            # Get the page
            page = doc[page_number]
            
            # Convert coordinates based on mode
            if coordinate_mode == "rect":
                # Convert from x, y, width, height to x0, y0, x1, y1
                # Note: PDF coordinates have origin at bottom-left, so we need to adjust
                page_rect = page.rect
                actual_x0 = x0
                actual_y0 = page_rect.height - (y0 + y1)  # Convert from top-left to bottom-left origin
                actual_x1 = x0 + x1
                actual_y1 = page_rect.height - y0
            else:  # bbox mode
                actual_x0, actual_y0, actual_x1, actual_y1 = x0, y0, x1, y1
            
            # Validate crop coordinates
            page_rect = page.rect
            if (actual_x0 < 0 or actual_y0 < 0 or 
                actual_x1 > page_rect.width or actual_y1 > page_rect.height or
                actual_x0 >= actual_x1 or actual_y0 >= actual_y1):
                doc.close()
                return f"Error: Invalid crop coordinates. Page dimensions: {page_rect.width:.1f} x {page_rect.height:.1f}"
            
            # Set the crop box
            crop_rect = fitz.Rect(actual_x0, actual_y0, actual_x1, actual_y1)
            page.set_cropbox(crop_rect)
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully cropped page {page_number + 1}. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error cropping page: {str(e)}"

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.0.0
    • addedInput schema / title
      Added value: +"pdf_crop_pageArguments"
  2. First observed

TDQS

C2.2/5.0
Behavior1/5

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

The description gives no information about side effects, such as whether the original file is modified or a new file is created, coordinate system details, or file handling. With no annotations to rely on, the description carries the full burden and fails to disclose essential behavior.

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

Conciseness3/5

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

The description is a single direct sentence with no wasted words, making it structurally concise. However, it is too terse to be considered well-structured for a tool with 7 parameters and no supporting detail elsewhere.

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

Completeness1/5

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

Given the complexity of 7 parameters, no annotations, and a minimal description, the tool's behavior remains almost entirely unspecified. The output schema exists but the description still fails to explain coordinate semantics, file impact, or pagination, making it deeply incomplete.

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

Parameters1/5

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

The description does not explain any of the 7 parameters (pdf_path, page_number, x0, y0, x1, y1, coordinate_mode). Schema description coverage is 0%, so the description must compensate but provides zero value beyond the parameter names.

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

Purpose4/5

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

The description clearly states a specific action ('Crop a page in a PDF') with a clear verb and resource. However, it does not differentiate from the closely related sibling tool pdf_auto_crop_page, so it misses the top score.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like pdf_auto_crop_page, pdf_rotate_page, or pdf_delete_page. There is no mention of prerequisites, interactions, or exclusions.

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