Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_add_image

Add images to PDF documents by specifying exact page positions and dimensions to enhance or annotate content.

Instructions

Add an image to a PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numberYes
image_pathYes
xYes
yYes
widthYes
heightYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'pdf_add_image' tool. It validates the input PDF and image paths, opens the PDF using PyMuPDF (fitz), adds the image to the specified page at given coordinates and size, generates a timestamped output filename, saves the modified PDF, and returns the output path.
    @mcp.tool()
    async def pdf_add_image(
        pdf_path: str,
        page_number: int,
        image_path: str,
        x: float,
        y: float,
        width: float,
        height: float
    ) -> str:
        """Add an image to 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 not os.path.exists(image_path):
            return f"Error: Image file not found: {image_path}"
        
        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]
            
            # Create rectangle for image placement
            rect = fitz.Rect(x, y, x + width, y + height)
            
            # Add image to the page
            page.insert_image(rect, filename=image_path)
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully added image to PDF. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error adding image to PDF: {str(e)}"
  • Helper utility used by pdf_add_image (and other tools) to generate a timestamped output filename to prevent overwriting the original PDF.
    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}")
  • Helper function used by pdf_add_image to validate that the input file is a valid PDF.
    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_add_image to check if the specified page number is valid.
    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)
Behavior1/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Add an image to a PDF' implies a mutation operation, but it doesn't specify whether this modifies the original file in-place, creates a new file, requires specific permissions, has side effects, or handles errors. For a tool with 7 required parameters and no annotation coverage, this is critically inadequate.

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 a single, clear sentence with zero wasted words. It's perfectly front-loaded and gets straight to the point without unnecessary elaboration. Every word earns its place in communicating the core function.

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 (7 required parameters, mutation operation), complete lack of annotations, and 0% schema description coverage, the description is woefully incomplete. While an output schema exists, the description doesn't address critical behavioral aspects, parameter meanings, or usage context needed for effective tool invocation.

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?

Schema description coverage is 0%, meaning none of the 7 parameters have descriptions in the schema. The description provides no information about what any parameter means, their formats, units, or constraints. It doesn't even mention that parameters exist, leaving the agent completely in the dark about how to use this tool effectively.

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 verb 'Add' and the resource 'image to a PDF', making the purpose immediately understandable. It distinguishes from siblings like pdf_add_text or pdf_add_annotation by specifying the type of content being added. However, it doesn't specify whether this modifies the original PDF or creates a new one, which prevents a perfect 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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like pdf_add_text for text or pdf_add_annotation for annotations, there's no indication of the specific use case for images versus other additions. No prerequisites, constraints, or comparison to similar tools are mentioned.

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