iflow-mcp_truaxki-pdf2png 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_truaxki-pdf2png
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server to convert a PDF to a PNG file.
|
|
5
|
+
Author-email: Kirk Truax <kirktruax93@proton.me>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: mcp>=1.2.0
|
|
8
|
+
Requires-Dist: pdf2image>=1.16.3
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# PDF to PNG MCP Server
|
|
12
|
+
|
|
13
|
+
A Model Context Protocol (MCP) server that provides PDF to PNG conversion capabilities. This server allows you to convert PDF documents into PNG images with a simple MCP tool call.
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
This server requires the Model Context Protocol (MCP). If you're new to MCP, start by installing the SDK:
|
|
18
|
+
```bash
|
|
19
|
+
uv pip install mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Additional requirements:
|
|
23
|
+
- Python 3.10 or higher
|
|
24
|
+
- [uv](https://github.com/astral-sh/uv) package manager
|
|
25
|
+
- poppler (required for pdf2image)
|
|
26
|
+
|
|
27
|
+
### Installing Poppler
|
|
28
|
+
|
|
29
|
+
- **Windows**: Download and install from [poppler-windows](https://github.com/oschwartz10612/poppler-windows/releases/)
|
|
30
|
+
- **macOS**: `brew install poppler`
|
|
31
|
+
- **Linux**: `sudo apt-get install poppler-utils`
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
1. Clone this repository:
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/truaxki/mcp-Pdf2png.git
|
|
38
|
+
cd mcp-Pdf2png
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Create and activate a virtual environment:
|
|
42
|
+
```bash
|
|
43
|
+
uv venv
|
|
44
|
+
# Windows
|
|
45
|
+
.venv\Scripts\activate
|
|
46
|
+
# Unix/macOS
|
|
47
|
+
source .venv/bin/activate
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3. Install the package:
|
|
51
|
+
```bash
|
|
52
|
+
uv pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### 1. Configure MCP Client
|
|
58
|
+
|
|
59
|
+
Add the server configuration to your `claude_desktop_config.json`. The file is typically located in:
|
|
60
|
+
- Windows: `%APPDATA%\Claude Desktop\config\claude_desktop_config.json`
|
|
61
|
+
- macOS/Linux: `~/.config/Claude Desktop/config/claude_desktop_config.json`
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"mcpServers": {
|
|
66
|
+
"pdf2png": {
|
|
67
|
+
"command": "uv",
|
|
68
|
+
"args": [
|
|
69
|
+
"--directory",
|
|
70
|
+
"/absolute/path/to/mcp-Pdf2png",
|
|
71
|
+
"run",
|
|
72
|
+
"pdf2png"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Note: Replace `/absolute/path/to/mcp-Pdf2png` with the actual path where you cloned the repository.
|
|
80
|
+
|
|
81
|
+
### 2. Using the Server
|
|
82
|
+
|
|
83
|
+
The server provides a single tool `pdf2png` with these parameters:
|
|
84
|
+
- `read_file_path`: Absolute path to the input PDF file
|
|
85
|
+
- `write_folder_path`: Absolute path to the directory where PNG files should be saved
|
|
86
|
+
|
|
87
|
+
Output:
|
|
88
|
+
- Each PDF page is converted to a PNG image
|
|
89
|
+
- Files are named `page_1.png`, `page_2.png`, etc.
|
|
90
|
+
- Returns a success message with the conversion count
|
|
91
|
+
|
|
92
|
+
## Contributing
|
|
93
|
+
|
|
94
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
pdf2png/__init__.py,sha256=kS5ZO4LqhqaH6MAaId2CzZAO-kBTmJeVgF25qISeCIw,195
|
|
2
|
+
pdf2png/server.py,sha256=VZb5hxZKi4h2sxtGO2JhosPhmjwO47liHolKPH9IxjQ,2554
|
|
3
|
+
iflow_mcp_truaxki_pdf2png-0.1.0.dist-info/METADATA,sha256=S3ogqPhaxVTsoVkauypZ_MAQHLv4a2FHTRBKhxtc9Pk,2466
|
|
4
|
+
iflow_mcp_truaxki_pdf2png-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
5
|
+
iflow_mcp_truaxki_pdf2png-0.1.0.dist-info/entry_points.txt,sha256=Cs__6PgvxSbLIIKsaNgh5a9q8SqSUmKF75laiLk-UlE,41
|
|
6
|
+
iflow_mcp_truaxki_pdf2png-0.1.0.dist-info/RECORD,,
|
pdf2png/__init__.py
ADDED
pdf2png/server.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from mcp.server.models import InitializationOptions
|
|
3
|
+
import mcp.types as types
|
|
4
|
+
from mcp.server import NotificationOptions, Server
|
|
5
|
+
import mcp.server.stdio
|
|
6
|
+
from pdf2image import convert_from_path
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
server = Server("pdf2png")
|
|
10
|
+
|
|
11
|
+
@server.list_tools()
|
|
12
|
+
async def handle_list_tools() -> list[types.Tool]:
|
|
13
|
+
"""List available tools."""
|
|
14
|
+
return [
|
|
15
|
+
types.Tool(
|
|
16
|
+
name="pdf2png",
|
|
17
|
+
description="Converts PDFs to images in PNG format.",
|
|
18
|
+
inputSchema={
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"read_file_path": {"type": "string"},
|
|
22
|
+
"write_folder_path": {"type": "string"},
|
|
23
|
+
},
|
|
24
|
+
"required": ["read_file_path", "write_folder_path"],
|
|
25
|
+
},
|
|
26
|
+
)
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
@server.call_tool()
|
|
30
|
+
async def handle_call_tool(
|
|
31
|
+
name: str, arguments: dict | None
|
|
32
|
+
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
|
33
|
+
"""Handle tool execution requests."""
|
|
34
|
+
if name != "pdf2png":
|
|
35
|
+
raise ValueError(f"Unknown tool: {name}")
|
|
36
|
+
|
|
37
|
+
if not arguments:
|
|
38
|
+
raise ValueError("Missing arguments")
|
|
39
|
+
|
|
40
|
+
read_file_path = arguments.get("read_file_path")
|
|
41
|
+
write_folder_path = arguments.get("write_folder_path")
|
|
42
|
+
|
|
43
|
+
if not read_file_path or not write_folder_path:
|
|
44
|
+
raise ValueError("Missing read_file_path or write_folder_path")
|
|
45
|
+
|
|
46
|
+
# Convert PDF to PNG
|
|
47
|
+
images = convert_from_path(read_file_path)
|
|
48
|
+
|
|
49
|
+
# Create output directory if it doesn't exist
|
|
50
|
+
os.makedirs(write_folder_path, exist_ok=True)
|
|
51
|
+
|
|
52
|
+
# Save each page as PNG
|
|
53
|
+
output_files = []
|
|
54
|
+
for i, image in enumerate(images):
|
|
55
|
+
output_path = os.path.join(write_folder_path, f'page_{i+1}.png')
|
|
56
|
+
image.save(output_path, 'PNG')
|
|
57
|
+
output_files.append(output_path)
|
|
58
|
+
|
|
59
|
+
return [
|
|
60
|
+
types.TextContent(
|
|
61
|
+
type="text",
|
|
62
|
+
text=f"Successfully converted PDF to {len(output_files)} PNG files in {write_folder_path}"
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
async def main():
|
|
67
|
+
# Run the server using stdin/stdout streams
|
|
68
|
+
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
|
69
|
+
await server.run(
|
|
70
|
+
read_stream,
|
|
71
|
+
write_stream,
|
|
72
|
+
InitializationOptions(
|
|
73
|
+
server_name="pdf2png",
|
|
74
|
+
server_version="0.1.0",
|
|
75
|
+
capabilities=server.get_capabilities(
|
|
76
|
+
notification_options=NotificationOptions(),
|
|
77
|
+
experimental_capabilities={},
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
)
|