Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_merge_files

Combine multiple PDF documents into a single file for easier organization and sharing.

Instructions

Merge multiple PDF files into one combined PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathsYes
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'pdf_merge_files' tool. It validates input PDF files, merges them using PyMuPDF's fitz library by creating a new document and inserting pages from each input PDF, generates an output filename if not provided, and saves the merged PDF. The @mcp.tool() decorator registers it with FastMCP.
    @mcp.tool()
    async def pdf_merge_files(
        pdf_paths: List[str],
        output_path: Optional[str] = None
    ) -> str:
        """Merge multiple PDF files into one combined PDF."""
        # Validate all PDF files
        for pdf_path in pdf_paths:
            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:
            # Create new document for merging
            merged_doc = fitz.open()
            
            # Merge all PDFs
            for pdf_path in pdf_paths:
                doc = fitz.open(pdf_path)
                merged_doc.insert_pdf(doc)
                doc.close()
            
            # Determine output path
            if not output_path:
                output_path = generate_output_filename(pdf_paths[0], "merged")
            
            # Save merged PDF
            merged_doc.save(output_path)
            merged_doc.close()
            
            return f"Successfully merged {len(pdf_paths)} PDFs. Output saved to: {output_path}"
            
        except Exception as e:
            return f"Error merging PDFs: {str(e)}"
  • Utility function used by pdf_merge_files (and other tools) to check if a given file path points to a valid PDF by attempting to open it with fitz.
    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
  • Utility function used by pdf_merge_files to generate a timestamped output filename based on the first input PDF path to prevent overwriting original files.
    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_merge_filesArguments"
  2. First observed

TDQS

C2.7/5.0
Behavior1/5

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

With no annotations, the description carries the full burden of behavioral disclosure, but it only states the general purpose. It does not mention output behavior, default output_path handling, overwrite risks, or any side effects, which is insufficient for a merge operation.

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 concise sentence with no redundant words, front-loading the core action. It avoids fluff and is appropriately minimal for the stated purpose.

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?

Despite the tool having only 2 parameters and an output schema, the description is too sparse to be contextually complete. It lacks essential information such as how output_path works (e.g., default behavior), what types of PDF paths are accepted, and any constraints, leaving the agent to infer too much.

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%, so the description must compensate, but it does not explain pdf_paths or output_path beyond what is already evident from their names. No additional meaning or format details are provided.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Merge' and the resource 'multiple PDF files' into 'one combined PDF', distinguishing it from siblings like pdf_combine_pages_to_single which works on pages, not files. It is specific and 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 alternatives. It only states what it does without any context on prerequisites, exclusions, or comparisons to sibling tools like pdf_combine_pages_to_single.

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