pdfco-mcp 0.1.0__tar.gz
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.
- pdfco_mcp-0.1.0/.github/workflows/release.yml +65 -0
- pdfco_mcp-0.1.0/.gitignore +14 -0
- pdfco_mcp-0.1.0/.python-version +1 -0
- pdfco_mcp-0.1.0/PKG-INFO +33 -0
- pdfco_mcp-0.1.0/README.md +21 -0
- pdfco_mcp-0.1.0/pdfco/mcp/__init__.py +8 -0
- pdfco_mcp-0.1.0/pdfco/mcp/models.py +68 -0
- pdfco_mcp-0.1.0/pdfco/mcp/server.py +3 -0
- pdfco_mcp-0.1.0/pdfco/mcp/services/__init__.py +0 -0
- pdfco_mcp-0.1.0/pdfco/mcp/services/client.py +49 -0
- pdfco_mcp-0.1.0/pdfco/mcp/services/pdf.py +95 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/__init__.py +0 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/conversion.py +371 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/document.py +25 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/editing.py +71 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/extraction.py +42 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/file.py +32 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/form.py +102 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/job.py +82 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/modification.py +43 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/search.py +54 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/searchable.py +58 -0
- pdfco_mcp-0.1.0/pdfco/mcp/tools/apis/security.py +96 -0
- pdfco_mcp-0.1.0/pyproject.toml +23 -0
- pdfco_mcp-0.1.0/uv.lock +1471 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
name: release
|
2
|
+
|
3
|
+
permissions:
|
4
|
+
contents: write
|
5
|
+
packages: write
|
6
|
+
|
7
|
+
on:
|
8
|
+
release:
|
9
|
+
types: [published]
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
set-version:
|
13
|
+
runs-on: ubuntu-24.04
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v4
|
16
|
+
|
17
|
+
- name: Export tag
|
18
|
+
id: vars
|
19
|
+
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
|
20
|
+
if: ${{ github.event_name == 'release' }}
|
21
|
+
|
22
|
+
- name: Update project version
|
23
|
+
run: |
|
24
|
+
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
|
25
|
+
env:
|
26
|
+
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
|
27
|
+
if: ${{ github.event_name == 'release' }}
|
28
|
+
|
29
|
+
- name: Upload updated pyproject.toml
|
30
|
+
uses: actions/upload-artifact@v4
|
31
|
+
with:
|
32
|
+
name: pyproject-toml
|
33
|
+
path: pyproject.toml
|
34
|
+
|
35
|
+
publish:
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
needs: [set-version]
|
38
|
+
steps:
|
39
|
+
- name: Check out
|
40
|
+
uses: actions/checkout@v4
|
41
|
+
|
42
|
+
- name: Set up the environment
|
43
|
+
uses: ./.github/actions/setup-python-env
|
44
|
+
|
45
|
+
- name: Download updated pyproject.toml
|
46
|
+
uses: actions/download-artifact@v4
|
47
|
+
with:
|
48
|
+
name: pyproject-toml
|
49
|
+
|
50
|
+
- name: Build package
|
51
|
+
run: uv build
|
52
|
+
|
53
|
+
- name: Publish package
|
54
|
+
run: uv publish
|
55
|
+
env:
|
56
|
+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
57
|
+
|
58
|
+
- name: Upload dists to release
|
59
|
+
uses: svenstaro/upload-release-action@v2
|
60
|
+
with:
|
61
|
+
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
62
|
+
file: dist/*
|
63
|
+
file_glob: true
|
64
|
+
tag: ${{ github.ref }}
|
65
|
+
overwrite: true
|
@@ -0,0 +1 @@
|
|
1
|
+
3.12
|
pdfco_mcp-0.1.0/PKG-INFO
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pdfco-mcp
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Add your description here
|
5
|
+
Requires-Python: >=3.12
|
6
|
+
Requires-Dist: httpx>=0.28.1
|
7
|
+
Requires-Dist: langchain-community>=0.3.21
|
8
|
+
Requires-Dist: langchain[google-genai]>=0.3.23
|
9
|
+
Requires-Dist: langgraph>=0.3.30
|
10
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
|
13
|
+
# PDF.co MCP
|
14
|
+
|
15
|
+
#### Sample `.cursor/mcp.json` for test in cursor
|
16
|
+
```json
|
17
|
+
{
|
18
|
+
"mcpServers": {
|
19
|
+
"pdfco": {
|
20
|
+
"command": "uv",
|
21
|
+
"args": [
|
22
|
+
"--directory",
|
23
|
+
"/path/to/pdfco-mcp",
|
24
|
+
"run",
|
25
|
+
"main.py"
|
26
|
+
],
|
27
|
+
"env": {
|
28
|
+
"X_API_KEY": "YOUR_TEST_KEY"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
```
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# PDF.co MCP
|
2
|
+
|
3
|
+
#### Sample `.cursor/mcp.json` for test in cursor
|
4
|
+
```json
|
5
|
+
{
|
6
|
+
"mcpServers": {
|
7
|
+
"pdfco": {
|
8
|
+
"command": "uv",
|
9
|
+
"args": [
|
10
|
+
"--directory",
|
11
|
+
"/path/to/pdfco-mcp",
|
12
|
+
"run",
|
13
|
+
"main.py"
|
14
|
+
],
|
15
|
+
"env": {
|
16
|
+
"X_API_KEY": "YOUR_TEST_KEY"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
```
|
@@ -0,0 +1,68 @@
|
|
1
|
+
from pydantic import BaseModel, Field
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
class BaseResponse(BaseModel):
|
5
|
+
status: str
|
6
|
+
content: Any
|
7
|
+
credits_used: int | None = None
|
8
|
+
credits_remaining: int | None = None
|
9
|
+
tips: str | None = None
|
10
|
+
|
11
|
+
class ConversionParams(BaseModel):
|
12
|
+
url: str = Field(description="URL to the source file. Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files.", default="")
|
13
|
+
httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default="")
|
14
|
+
httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default="")
|
15
|
+
pages: str = Field(description="Comma-separated page indices (e.g., '0, 1, 2-' or '1, 3-7'). Use '!' for inverted page numbers (e.g., '!0' for last page). Processes all pages if None. (Optional)", default="")
|
16
|
+
unwrap: bool = Field(description="Unwrap lines into a single line within table cells when lineGrouping is enabled. Must be true or false. (Optional)", default=False)
|
17
|
+
rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default="")
|
18
|
+
lang: str = Field(description="Language for OCR for scanned documents. Default is 'eng'. See PDF.co docs for supported languages. (Optional, Default: 'eng')", default="eng")
|
19
|
+
line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0")
|
20
|
+
password: str = Field(description="Password of the PDF file. (Optional)", default="")
|
21
|
+
name: str = Field(description="File name for the generated output. (Optional)", default="")
|
22
|
+
autosize: bool = Field(description="Controls automatic page sizing. If true, page dimensions adjust to content. If false, uses worksheet’s page setup. (Optional)", default=False)
|
23
|
+
|
24
|
+
html: str = Field(description="Input HTML code to be converted. To convert the link to a PDF use the /pdf/convert/from/url endpoint instead.", default="")
|
25
|
+
templateId: str = Field(description="Set to the ID of your HTML template. You can find and copy the ID from HTML to PDF Templates.", default="")
|
26
|
+
templateData: str = Field(description="Set it to a string with input JSON data (recommended) or CSV data.", default="")
|
27
|
+
margins: str = Field(description="Set to CSS style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left). (Optional)", default="")
|
28
|
+
paperSize: str = Field(description="A4 is set by default. Can be Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 or a custom size. Custom size can be set in px (pixels), mm or in (inches) with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in. (Optional)", default="")
|
29
|
+
orientation: str = Field(description="Set to Portrait or Landscape. Portrait is set by default. (Optional)", default="")
|
30
|
+
printBackground: bool = Field(description="true by default. Set to false to disable printing of background. (Optional)", default=True)
|
31
|
+
mediaType: str = Field(description="Uses print by default. Set to screen to convert HTML as it appears in a browser or print to convert as it appears for printing or none to set none as mediaType for CSS styles. (Optional)", default="")
|
32
|
+
DoNotWaitFullLoad: bool = Field(description="false by default. Set to true to skip waiting for full load (like full video load etc. that may affect the total conversion time). (Optional)", default=False)
|
33
|
+
header: str = Field(description="User definable HTML for the header to be applied on every page header. (Optional)", default="")
|
34
|
+
footer: str = Field(description="User definable HTML for the footer to be applied on every page footer. (Optional)", default="")
|
35
|
+
|
36
|
+
worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default="")
|
37
|
+
|
38
|
+
def parse_payload(self, async_mode: bool = True):
|
39
|
+
payload = {
|
40
|
+
"async": async_mode,
|
41
|
+
}
|
42
|
+
if self.url: payload["url"] = self.url
|
43
|
+
if self.httpusername: payload["httpusername"] = self.httpusername
|
44
|
+
if self.httppassword: payload["httppassword"] = self.httppassword
|
45
|
+
if self.pages: payload["pages"] = self.pages
|
46
|
+
if self.unwrap: payload["unwrap"] = self.unwrap
|
47
|
+
if self.rect: payload["rect"] = self.rect
|
48
|
+
if self.lang: payload["lang"] = self.lang
|
49
|
+
if self.line_grouping: payload["lineGrouping"] = self.line_grouping
|
50
|
+
if self.password: payload["password"] = self.password
|
51
|
+
if self.name: payload["name"] = self.name
|
52
|
+
if self.autosize: payload["autosize"] = self.autosize
|
53
|
+
|
54
|
+
if self.html: payload["html"] = self.html
|
55
|
+
if self.templateId: payload["templateId"] = self.templateId
|
56
|
+
if self.templateData: payload["templateData"] = self.templateData
|
57
|
+
if self.margins: payload["margins"] = self.margins
|
58
|
+
if self.paperSize: payload["paperSize"] = self.paperSize
|
59
|
+
if self.orientation: payload["orientation"] = self.orientation
|
60
|
+
if self.printBackground: payload["printBackground"] = self.printBackground
|
61
|
+
if self.mediaType: payload["mediaType"] = self.mediaType
|
62
|
+
if self.DoNotWaitFullLoad: payload["DoNotWaitFullLoad"] = self.DoNotWaitFullLoad
|
63
|
+
if self.header: payload["header"] = self.header
|
64
|
+
if self.footer: payload["footer"] = self.footer
|
65
|
+
|
66
|
+
if self.worksheetIndex: payload["worksheetIndex"] = self.worksheetIndex
|
67
|
+
|
68
|
+
return payload
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from contextlib import asynccontextmanager
|
2
|
+
from httpx import AsyncClient
|
3
|
+
import os, sys
|
4
|
+
from typing import AsyncGenerator
|
5
|
+
import importlib.metadata
|
6
|
+
|
7
|
+
__BASE_URL = "https://api.pdf.co"
|
8
|
+
X_API_KEY = os.getenv("X_API_KEY")
|
9
|
+
|
10
|
+
__version__ = importlib.metadata.version('pdfco-mcp')
|
11
|
+
print(f"pdfco-mcp version: {__version__}", file=sys.stderr)
|
12
|
+
|
13
|
+
@asynccontextmanager
|
14
|
+
async def PDFCoClient() -> AsyncGenerator[AsyncClient, None]:
|
15
|
+
if not X_API_KEY:
|
16
|
+
raise ValueError("""X_API_KEY is not set. Please set X_API_KEY in the environment variables in your MCP server.
|
17
|
+
To get the API key please sign up at https://pdf.co and you can get the API key from the dashboard.
|
18
|
+
ex) .cursor/mcp.json
|
19
|
+
```json
|
20
|
+
{
|
21
|
+
"mcpServers": {
|
22
|
+
"pdfco": {
|
23
|
+
"command": "uv",
|
24
|
+
"args": [
|
25
|
+
"--directory",
|
26
|
+
"/Users/outstandingboy/workspace/pdfco-mcp",
|
27
|
+
"run",
|
28
|
+
"pdfco-mcp"
|
29
|
+
],
|
30
|
+
"env": {
|
31
|
+
"X_API_KEY": "YOUR_API_KEY"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
""")
|
38
|
+
|
39
|
+
client = AsyncClient(
|
40
|
+
base_url=__BASE_URL,
|
41
|
+
headers={
|
42
|
+
"x-api-key": X_API_KEY,
|
43
|
+
"User-Agent": f"pdfco-mcp/{__version__}",
|
44
|
+
},
|
45
|
+
)
|
46
|
+
try:
|
47
|
+
yield client
|
48
|
+
finally:
|
49
|
+
await client.aclose()
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import sys
|
2
|
+
from pdfco.mcp.models import BaseResponse, ConversionParams
|
3
|
+
from pdfco.mcp.services.client import PDFCoClient
|
4
|
+
|
5
|
+
async def convert_to(_from: str, _to: str, params: ConversionParams) -> BaseResponse:
|
6
|
+
return await request(f'{_from}/convert/to/{_to}', params)
|
7
|
+
|
8
|
+
async def convert_from(_to: str, _from: str, params: ConversionParams) -> BaseResponse:
|
9
|
+
return await request(f'{_to}/convert/from/{_from}', params)
|
10
|
+
|
11
|
+
async def merge_pdf(params: ConversionParams) -> BaseResponse:
|
12
|
+
return await request(f'pdf/merge2', params)
|
13
|
+
|
14
|
+
async def split_pdf(params: ConversionParams) -> BaseResponse:
|
15
|
+
return await request(f'pdf/split', params)
|
16
|
+
|
17
|
+
async def get_pdf_form_fields_info(params: ConversionParams) -> BaseResponse:
|
18
|
+
return await request('pdf/info/fields', params)
|
19
|
+
|
20
|
+
async def fill_pdf_form_fields(params: ConversionParams, fields: list = None, annotations: list = None) -> BaseResponse:
|
21
|
+
custom_payload = {}
|
22
|
+
if fields:
|
23
|
+
custom_payload["fields"] = fields
|
24
|
+
if annotations:
|
25
|
+
custom_payload["annotations"] = annotations
|
26
|
+
return await request('pdf/edit/add', params, custom_payload=custom_payload)
|
27
|
+
|
28
|
+
async def pdf_add(params: ConversionParams, **kwargs) -> BaseResponse:
|
29
|
+
"""General PDF Add function that supports all PDF Add API parameters"""
|
30
|
+
custom_payload = {}
|
31
|
+
|
32
|
+
# Add all supported parameters
|
33
|
+
for key, value in kwargs.items():
|
34
|
+
if value is not None and value != "":
|
35
|
+
custom_payload[key] = value
|
36
|
+
|
37
|
+
return await request('pdf/edit/add', params, custom_payload=custom_payload)
|
38
|
+
|
39
|
+
async def find_text_in_pdf(params: ConversionParams, search_string: str, regex_search: bool = False, word_matching_mode: str = None) -> BaseResponse:
|
40
|
+
custom_payload = {
|
41
|
+
"searchString": search_string,
|
42
|
+
"regexSearch": regex_search
|
43
|
+
}
|
44
|
+
if word_matching_mode:
|
45
|
+
custom_payload["wordMatchingMode"] = word_matching_mode
|
46
|
+
return await request('pdf/find', params, custom_payload=custom_payload)
|
47
|
+
|
48
|
+
async def find_table_in_pdf(params: ConversionParams) -> BaseResponse:
|
49
|
+
return await request('pdf/find/table', params)
|
50
|
+
|
51
|
+
async def make_pdf_searchable(params: ConversionParams) -> BaseResponse:
|
52
|
+
return await request('pdf/makesearchable', params)
|
53
|
+
|
54
|
+
async def make_pdf_unsearchable(params: ConversionParams) -> BaseResponse:
|
55
|
+
return await request('pdf/makeunsearchable', params)
|
56
|
+
|
57
|
+
async def get_pdf_info(params: ConversionParams) -> BaseResponse:
|
58
|
+
return await request('pdf/info', params)
|
59
|
+
|
60
|
+
async def add_pdf_password(params: ConversionParams, **kwargs) -> BaseResponse:
|
61
|
+
return await request('pdf/security/add', params, custom_payload=kwargs)
|
62
|
+
|
63
|
+
async def remove_pdf_password(params: ConversionParams) -> BaseResponse:
|
64
|
+
return await request('pdf/security/remove', params)
|
65
|
+
|
66
|
+
async def parse_invoice(params: ConversionParams) -> BaseResponse:
|
67
|
+
return await request('ai-invoice-parser', params)
|
68
|
+
|
69
|
+
async def extract_pdf_attachments(params: ConversionParams) -> BaseResponse:
|
70
|
+
return await request('pdf/attachments/extract', params)
|
71
|
+
|
72
|
+
async def request(endpoint: str, params: ConversionParams, custom_payload: dict = None) -> BaseResponse:
|
73
|
+
payload = params.parse_payload(async_mode=True)
|
74
|
+
if custom_payload:
|
75
|
+
payload.update(custom_payload)
|
76
|
+
|
77
|
+
try:
|
78
|
+
async with PDFCoClient() as client:
|
79
|
+
url = f"/v1/{endpoint}"
|
80
|
+
print(f"Requesting {url} with payload {payload}", file=sys.stderr)
|
81
|
+
response = await client.post(url, json=payload)
|
82
|
+
print(f"response: {response}", file=sys.stderr)
|
83
|
+
json_data = response.json()
|
84
|
+
return BaseResponse(
|
85
|
+
status="working",
|
86
|
+
content=json_data,
|
87
|
+
credits_used=json_data.get("credits"),
|
88
|
+
credits_remaining=json_data.get("remainingCredits"),
|
89
|
+
tips=f"You **should** use the 'wait_job_completion' tool to wait for the job [{json_data.get('jobId')}] to complete if a jobId is present.",
|
90
|
+
)
|
91
|
+
except Exception as e:
|
92
|
+
return BaseResponse(
|
93
|
+
status="error",
|
94
|
+
content=f'{type(e)}: {[arg for arg in e.args if arg]}',
|
95
|
+
)
|
File without changes
|