Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_rotate_page

Rotate specific pages in PDF documents to correct orientation or adjust layout. Specify page number and rotation angle to modify PDF files.

Instructions

Rotate a page in a PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numberYes
rotationYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'pdf_rotate_page' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Validates input PDF and page, rotates the specified page using PyMuPDF's set_rotation(), generates output filename, and saves the modified PDF.
    @mcp.tool()
    async def pdf_rotate_page(
        pdf_path: str,
        page_number: int,
        rotation: int
    ) -> str:
        """Rotate 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 rotation not in [90, 180, 270]:
            return f"Error: Invalid rotation angle. Must be 90, 180, or 270 degrees."
        
        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 and rotate it
            page = doc[page_number]
            page.set_rotation(rotation)
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully rotated page {page_number + 1} by {rotation} degrees. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error rotating page: {str(e)}"
  • Helper function used by pdf_rotate_page to validate the page number exists in the document.
    def validate_page_number(doc: fitz.Document, page_num: int) -> bool:
        """Validate that the page number exists in the document."""
        return 0 <= page_num < len(doc)
  • Helper function used by pdf_rotate_page to validate the input is a valid PDF file.
    def validate_pdf_file(pdf_path: str) -> bool:
        """Validate that the file is a valid PDF."""
        try:
            doc = fitz.open(pdf_path)
            doc.close()
            return True
        except Exception:
            return False
  • Helper function used by pdf_rotate_page to generate a timestamped output filename.
    def generate_output_filename(input_path: str, suffix: str = "modified") -> str:
        """Generate a new filename with timestamp to avoid overwriting originals."""
        path = Path(input_path)
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        return str(path.parent / f"{path.stem}_{suffix}_{timestamp}{path.suffix}")

Schema Changelog

Changes observed during successful MCP inspections.

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

TDQS

C2.3/5.0
Behavior1/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, but it reveals nothing beyond the raw action. It does not mention rotation direction or units, page indexing, whether the operation is destructive, or what the output looks like.

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 concise and to the point, but it is overly sparse. It is a single short sentence that states the core function yet lacks necessary detail about parameters and behavior, making it under-specified rather than efficiently complete.

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?

The tool definition is incomplete for a mutation operation: no annotations, no parameter explanations, and a one-line description. Although an output schema exists, it does not clarify the operation's semantics, leaving important behavior ambiguous.

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 schema descriptions coverage is 0%, and the description does not compensate by explaining any of the three parameters. It omits details such as allowed rotation values (e.g., 90, 180, 270) and whether page_number is zero- or one-based.

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 the action ('Rotate') and the target ('a page in a PDF'), which makes the tool's purpose immediately identifiable. It distinguishes from sibling tools like pdf_delete_page or pdf_crop_page because it specifies a distinct operation, though it does not elaborate on rotation specifics.

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?

There is no guidance on when to use this tool versus other PDF manipulation tools. The description does not state prerequisites, whether the operation modifies the file in-place or produces a new file, or any context for typical usage.

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