Skip to main content
Glama
andr3medeiros

PDF Manipulation MCP Server

pdf_split

Split PDF files into individual pages or specific page ranges to extract, organize, or manage document sections.

Instructions

Split a PDF into individual pages or page ranges.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
output_dirNo
page_rangesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler implementation for the 'pdf_split' MCP tool. This async function handles splitting a PDF file into individual pages or custom page ranges using PyMuPDF (fitz). The @mcp.tool() decorator registers it automatically in the FastMCP server. Input parameters define the schema via type hints.
    @mcp.tool()
    async def pdf_split(
        pdf_path: str,
        output_dir: Optional[str] = None,
        page_ranges: Optional[List[Dict[str, int]]] = None
    ) -> str:
        """Split a PDF into individual pages or page ranges."""
        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)
            
            # Determine output directory
            if not output_dir:
                pdf_file = Path(pdf_path)
                output_dir = str(pdf_file.parent / f"{pdf_file.stem}_split")
            
            # Create output directory
            os.makedirs(output_dir, exist_ok=True)
            
            split_files = []
            
            if page_ranges:
                # Split by page ranges
                for i, page_range in enumerate(page_ranges):
                    start_page = page_range["start"]
                    end_page = page_range["end"]
                    
                    # Validate page range
                    if start_page < 0 or end_page >= len(doc) or start_page > end_page:
                        doc.close()
                        return f"Error: Invalid page range {start_page}-{end_page}"
                    
                    # Create new document for this range
                    new_doc = fitz.open()
                    new_doc.insert_pdf(doc, from_page=start_page, to_page=end_page)
                    
                    # Save split PDF
                    output_file = os.path.join(output_dir, f"pages_{start_page + 1}_to_{end_page + 1}.pdf")
                    new_doc.save(output_file)
                    new_doc.close()
                    split_files.append(output_file)
            else:
                # Split into individual pages
                for page_num in range(len(doc)):
                    new_doc = fitz.open()
                    new_doc.insert_pdf(doc, from_page=page_num, to_page=page_num)
                    
                    output_file = os.path.join(output_dir, f"page_{page_num + 1}.pdf")
                    new_doc.save(output_file)
                    new_doc.close()
                    split_files.append(output_file)
            
            doc.close()
            
            return f"Successfully split PDF into {len(split_files)} files. Output directory: {output_dir}"
            
        except Exception as e:
            return f"Error splitting PDF: {str(e)}"

Schema Changelog

Changes observed during successful MCP inspections.

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

TDQS

B3.3/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 mention whether the original PDF is modified, what output files are created, how overwriting is handled, or any permissions/limitations. 'Split' implies output, but key behavioral traits are undisclosed.

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 wasted words. It front-loads the core action and scope, making it easy to parse.

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 an output schema, the description omits critical usage details such as how page ranges are specified, what output directory is used, and how individual-page splitting differs from range splitting. For a tool with no annotations, this is incomplete.

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?

The schema has zero description coverage for its three parameters. The description hints at page_ranges ('page ranges') but does not explain the format or the role of pdf_path and output_dir. This is insufficient for a 3-parameter tool with no parameter-level documentation.

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 tool's function with a specific verb and resource: 'Split a PDF into individual pages or page ranges.' This distinguishes it from sibling tools like pdf_merge_files and pdf_combine_pages_to_single, which perform related but different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use the tool (when you need to split a PDF), but it does not explicitly compare with alternatives or provide exclusions. There is no guidance on when to prefer this over pdf_delete_page or pdf_merge_files, so usage context is only implied.

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