Skip to main content
Glama

merge-pdfs

Combine multiple PDF files into one document using the merge-pdfs tool from the mcp-pdf-tools server. Specify input files and output path to create a single PDF.

Instructions

Merge multiple PDF files into a single PDF

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_pathsYesList of input PDF file paths
output_pathYesOutput path for merged PDF

Implementation Reference

  • Executes the merge-pdfs tool by merging the provided PDF files using PyPDF2.PdfMerger and saving to the output path, with error handling.
    if name == "merge-pdfs":
        input_paths = arguments.get("input_paths", [])
        output_path = arguments.get("output_path")
        
        if not input_paths or not output_path:
            raise ValueError("Missing required arguments")
    
        merger = PyPDF2.PdfMerger()
        
        try:
            # Add each PDF to the merger
            for path in input_paths:
                with open(path, 'rb') as pdf_file:
                    merger.append(pdf_file)
            
            # Write the merged PDF
            with open(output_path, 'wb') as output_file:
                merger.write(output_file)
            
            return [types.TextContent(
                type="text",
                text=f"Successfully merged {len(input_paths)} PDFs into {output_path}"
            )]
            
        except Exception as e:
            return [types.TextContent(
                type="text",
                text=f"Error merging PDFs: {str(e)}"
            )]
        finally:
            merger.close()
  • Registers the merge-pdfs tool with the MCP server, providing name, description, and input schema validation.
    types.Tool(
        name="merge-pdfs",
        description="Merge multiple PDF files into a single PDF",
        inputSchema={
            "type": "object",
            "properties": {
                "input_paths": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "List of input PDF file paths"
                },
                "output_path": {
                    "type": "string",
                    "description": "Output path for merged PDF"
                }
            },
            "required": ["input_paths", "output_path"]
        }
    ),

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/hanweg/mcp-pdf-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server