pdf2png
Convert PDF documents to PNG image files using this MCP server tool. Specify input PDF path and output folder to generate images from PDF pages.
Instructions
Converts PDFs to images in PNG format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| read_file_path | Yes | ||
| write_folder_path | Yes |
Implementation Reference
- src/pdf2png/server.py:29-64 (handler)The handle_call_tool function executes the pdf2png tool: validates arguments, converts PDF pages to PNG images using pdf2image.convert_from_path, saves them sequentially as page_N.png in the write_folder_path, and returns a success text message.@server.call_tool() async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """Handle tool execution requests.""" if name != "pdf2png": raise ValueError(f"Unknown tool: {name}") if not arguments: raise ValueError("Missing arguments") read_file_path = arguments.get("read_file_path") write_folder_path = arguments.get("write_folder_path") if not read_file_path or not write_folder_path: raise ValueError("Missing read_file_path or write_folder_path") # Convert PDF to PNG images = convert_from_path(read_file_path) # Create output directory if it doesn't exist os.makedirs(write_folder_path, exist_ok=True) # Save each page as PNG output_files = [] for i, image in enumerate(images): output_path = os.path.join(write_folder_path, f'page_{i+1}.png') image.save(output_path, 'PNG') output_files.append(output_path) return [ types.TextContent( type="text", text=f"Successfully converted PDF to {len(output_files)} PNG files in {write_folder_path}" ) ]
- src/pdf2png/server.py:11-27 (schema)The handle_list_tools function defines and returns the schema for the pdf2png tool, including name, description, and input schema requiring read_file_path and write_folder_path as strings.@server.list_tools() async def handle_list_tools() -> list[types.Tool]: """List available tools.""" return [ types.Tool( name="pdf2png", description="Converts PDFs to images in PNG format.", inputSchema={ "type": "object", "properties": { "read_file_path": {"type": "string"}, "write_folder_path": {"type": "string"}, }, "required": ["read_file_path", "write_folder_path"], }, ) ]
- src/pdf2png/server.py:9-9 (registration)Creates the MCP Server instance named 'pdf2png', onto which tool handlers are registered via decorators.server = Server("pdf2png")