Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_fill_form

Fill form fields in PDF documents with specified values to complete digital forms. This tool populates text fields, checkboxes, and other form elements in PDF files.

Instructions

Fill form fields in a PDF with values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
field_valuesYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler implementation for the 'pdf_fill_form' tool. Uses PyMuPDF to iterate through PDF pages and widgets, filling form fields matching keys in field_values dictionary based on widget type. Includes input validation, error handling, and saves output to timestamped file. The @mcp.tool() decorator handles registration and schema inference from type hints and docstring.
    @mcp.tool()
    async def pdf_fill_form(
        pdf_path: str,
        field_values: Dict[str, Any]
    ) -> str:
        """Fill form fields in a PDF with values."""
        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)
            
            filled_fields = 0
            
            # Fill form fields
            for page_num in range(len(doc)):
                page = doc[page_num]
                widgets = page.widgets()
                
                for widget in widgets:
                    field_name = widget.field_name
                    if field_name in field_values:
                        value = field_values[field_name]
                        
                        # Set field value based on widget type
                        if widget.field_type == fitz.PDF_WIDGET_TYPE_TEXT:
                            widget.field_value = str(value)
                        elif widget.field_type == fitz.PDF_WIDGET_TYPE_CHECKBOX:
                            widget.field_value = bool(value)
                        elif widget.field_type == fitz.PDF_WIDGET_TYPE_RADIOBUTTON:
                            widget.field_value = str(value)
                        elif widget.field_type == fitz.PDF_WIDGET_TYPE_COMBOBOX:
                            widget.field_value = str(value)
                        
                        widget.update()
                        filled_fields += 1
            
            if filled_fields == 0:
                doc.close()
                return "No matching form fields found to fill."
            
            # Generate output filename
            output_path = generate_output_filename(pdf_path)
            
            # Save the modified PDF
            doc.save(output_path)
            doc.close()
            
            return f"Successfully filled {filled_fields} form fields. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error filling form fields: {str(e)}"
  • Helper function used by pdf_fill_form to validate the input PDF file is valid by attempting to open it with PyMuPDF.
    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_fill_form 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}")
  • Initialization of the FastMCP server instance. All tools decorated with @mcp.tool() are automatically registered here.
    mcp = FastMCP("pdf-manipulation")
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 states the action ('fill form fields') but lacks critical details: whether this modifies the original PDF or creates a new file, what permissions or formats are required, how errors are handled (e.g., invalid fields), or if there are rate limits. For a mutation tool with zero annotation coverage, this is 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, efficient sentence with zero waste—it directly states the tool's action without unnecessary words. It's appropriately sized for a simple tool and front-loaded with the core purpose.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters with nested objects, no annotations, but an output schema exists), the description is minimally complete. The output schema likely covers return values, reducing the need for output details in the description. However, for a mutation tool, it lacks behavioral context and parameter guidance, making it only adequate.

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%, so the description must compensate for undocumented parameters. It mentions 'form fields' and 'values', which loosely map to the parameters (pdf_path and field_values), but doesn't explain what pdf_path expects (e.g., file path, URL, or format) or how field_values should be structured (e.g., key-value pairs matching field names). This adds minimal semantic value beyond the 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 verb ('fill') and resource ('form fields in a PDF') with the action ('with values'), making the purpose specific and understandable. However, it doesn't explicitly distinguish this tool from similar siblings like pdf_add_form_field or pdf_replace_text, 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. It doesn't mention prerequisites (e.g., needing a PDF with existing form fields), exclusions, or comparisons to siblings like pdf_add_form_field (which might create new fields) or pdf_replace_text (which might handle non-form text).

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