Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_add_form_field

Add interactive form fields like text boxes or checkboxes to PDF documents at specified positions and pages to create fillable forms.

Instructions

Add a form field to a PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numberYes
field_typeYes
field_nameYes
xYes
yYes
widthYes
heightYes
optionsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'pdf_add_form_field' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Adds interactive form fields (text, checkbox, radio button, or combobox) to a specified position on a PDF page using PyMuPDF. Validates input, creates the widget, updates it, saves to a new timestamped file, and returns the output path.
    async def pdf_add_form_field(
        pdf_path: str,
        page_number: int,
        field_type: str,
        field_name: str,
        x: float,
        y: float,
        width: float,
        height: float,
        options: List[str] = None
    ) -> str:
        """Add a form field to a PDF."""
        if options is None:
            options = []
        
        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]
            
            # Create rectangle for form field
            rect = fitz.Rect(x, y, x + width, y + height)
            
            # Add form field based on type
            if field_type == "text":
                widget = page.add_textfield(rect, field_name)
            elif field_type == "checkbox":
                widget = page.add_checkbox(rect, field_name)
            elif field_type == "radio":
                widget = page.add_radio_button(rect, field_name)
            elif field_type == "combobox":
                widget = page.add_combobox(rect, field_name, options)
            else:
                doc.close()
                return f"Error: Invalid field type: {field_type}"
            
            # Update widget appearance
            widget.update()
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully added {field_type} form field '{field_name}' to PDF. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error adding form field to PDF: {str(e)}"

Schema Changelog

Changes observed during successful MCP inspections.

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

TDQS

C2.6/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It does not state whether the PDF is modified in place, whether an output file is created, what validation is applied, or any side effects of adding a form field.

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, front-loaded sentence with no wasted words. However, it is too under-specified to be considered well-structured; conciseness should not trade away necessary information.

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?

With 8 required parameters, no annotations, and an output schema that is not described, the description is insufficient for correct invocation. It lacks information about return values, required field types, and page indexing, making it inadequate for an MCP tool of this complexity.

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?

Schema description coverage is 0%, and the description mentions no parameters. Parameter names are somewhat self-explanatory, but the description does not explain field_type options, coordinate system, or the role of options.

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 identifies the action (adding a form field) and resource (a PDF), using a specific verb. It does not elaborate on form field types or distinguish it from pdf_add_annotation, but the basic purpose is unambiguous.

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 pdf_fill_form or pdf_add_annotation. The description only states the action, with no context, prerequisites, or exclusions.

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