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)}"
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Crop a page in a PDF' implies a mutation operation that modifies the PDF file, but it doesn't specify whether this creates a new file, modifies in-place, requires write permissions, or has side effects like data loss. It also doesn't mention error conditions, performance characteristics, or output behavior. The description is too minimal for a tool that performs file modifications.

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

Conciseness5/5

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

The description is extremely concise at just 5 words ('Crop a page in a PDF.'). It's front-loaded with the core action and resource, with no unnecessary words or sentences. Every word serves a purpose in conveying the basic function.

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

Completeness2/5

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

Given the tool's complexity (7 parameters, mutation operation, coordinate-based cropping) and the absence of annotations, the description is insufficiently complete. While an output schema exists (which might describe return values), the description doesn't address critical context like how cropping works, coordinate systems, file handling behavior, or error scenarios. For a PDF manipulation tool with multiple parameters, this minimal description leaves too many questions unanswered.

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

Parameters2/5

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

The schema has 7 parameters with 0% description coverage, meaning none have descriptions in the schema. The tool description provides no information about any parameters—it doesn't explain what 'pdf_path', 'page_number', coordinate parameters (x0, y0, x1, y1), or 'coordinate_mode' represent. For a tool with 7 undocumented parameters, the description fails to compensate for the schema's lack of documentation.

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 'Crop a page in a PDF' clearly states the action (crop) and resource (a page in a PDF), making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling 'pdf_auto_crop_page', which appears to serve a similar function but with automated cropping. The description is specific but lacks sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling 'pdf_auto_crop_page' for automated cropping or explain scenarios where manual cropping with coordinates is preferred over automated methods. There's no context about prerequisites, file formats, or limitations.

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/andr3medeiros/pdf-manipulation-mcp-server'

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