Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_add_text

Insert custom text at precise coordinates on PDF pages to annotate documents, add labels, or include additional information.

Instructions

Add text to a PDF at a specified position.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numberYes
textYes
xYes
yYes
font_sizeNo
colorNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'pdf_add_text' tool. It adds text to a specified page and position in a PDF using PyMuPDF (fitz), generates a timestamped output file, and returns success/error message.
    @mcp.tool()
    async def pdf_add_text(
        pdf_path: str,
        page_number: int,
        text: str,
        x: float,
        y: float,
        font_size: int = 12,
        color: List[float] = None
    ) -> str:
        """Add text to a PDF at a specified position."""
        if color is None:
            color = [0, 0, 0]
        
        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}"
        
        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]
            
            # Add text to the page
            page.insert_text(
                (x, y),
                text,
                fontsize=font_size,
                color=color
            )
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully added text to PDF. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error adding text to PDF: {str(e)}"
  • Utility function used by pdf_add_text to generate timestamped output filenames preventing overwrite of originals.
    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_text to validate the input 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_add_text to validate the page number.
    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)
  • The server entry point that imports and runs the MCP server instance with all registered tools including pdf_add_text.
    def main():
        """Main function to run the MCP server."""
        mcp.run()

Schema Changelog

Changes observed during successful MCP inspections.

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

TDQS

C2.7/5.0
Behavior2/5

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

With no annotations present, the description carries the full burden for behavioral disclosure. It only states the action and position, but does not reveal whether the PDF is modified in-place, how the coordinate system works, how page numbers are indexed, or whether the input file is preserved. This is a significant gap for a mutation tool.

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, grammatically complete sentence with no wasted words. It is formatted plainly and front-loads the core action clearly, which fits the conciseness criterion.

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 7 parameters, 5 required, and no annotations, the description is insufficiently complete. It omits crucial context such as coordinate system, unit of measurement, file mutation semantics, and error/return behavior. The presence of an output schema is noted, but the input handling remains underspecified.

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%, and the description provides no additional meaning for parameters beyond their names. It does not explain the units for x/y, the coordinate origin, the expected format for color, or the range/validity of page_number. The sparse one-line description fails to compensate for the undocumented schema.

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 ('Add text') and the resource ('to a PDF') with a positional qualifier ('at a specified position'). It is specific enough to distinguish from sibling tools like pdf_replace_text (replace vs. add), though it does not explicitly contrast with alternative tools.

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 siblings such as pdf_replace_text or pdf_add_annotation. The usage is only implied by the tool name and description, with no explicit context or exclusions.

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