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}")
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 ('merge') but doesn't cover critical aspects like whether the operation is read-only or destructive, what happens to source files, error handling for invalid inputs, or performance considerations. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 that front-loads the core action ('merge multiple PDF files') and outcome ('into one combined PDF') with zero wasted words. It's appropriately sized for a straightforward tool, making it easy for an agent to parse quickly.

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 (merging files), lack of annotations, and presence of an output schema (which reduces the need to describe return values), the description is incomplete. It covers the basic purpose but misses usage guidelines, behavioral details, and parameter semantics, leaving gaps that could hinder correct tool invocation by an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/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 only implies the existence of parameters without detailing them. It mentions 'multiple PDF files' (hinting at 'pdf_paths') and 'one combined PDF' (hinting at 'output_path'), but doesn't explain parameter formats, constraints, or defaults. This adds minimal value beyond the schema, meeting the baseline for partial compensation.

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 ('merge') and resource ('multiple PDF files') with the outcome ('into one combined PDF'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'pdf_combine_pages_to_single' or 'pdf_split', which also manipulate PDF files in related ways, so it doesn't reach the highest clarity level.

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 sibling tools like 'pdf_combine_pages_to_single' for combining pages or 'pdf_split' for splitting, nor does it specify prerequisites such as file accessibility or format requirements. This leaves the agent with minimal context for tool selection.

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