pdfco-mcp 0.0.1__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.
pdfco/mcp/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ from pdfco.mcp.server import mcp
2
+ from pdfco.mcp.tools.apis import conversion, job, file, modification, form, search, searchable, security, document, extraction, editing
3
+
4
+ def main():
5
+ mcp.run(transport="stdio")
6
+
7
+ if __name__ == "__main__":
8
+ main()
pdfco/mcp/models.py ADDED
@@ -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
pdfco/mcp/server.py ADDED
@@ -0,0 +1,3 @@
1
+ from mcp.server.fastmcp import FastMCP
2
+
3
+ mcp = FastMCP("pdfco")
File without changes
@@ -0,0 +1,46 @@
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": "uvx",
24
+ "args": [
25
+ "pdfco-mcp"
26
+ ],
27
+ "env": {
28
+ "X_API_KEY": "YOUR_API_KEY"
29
+ }
30
+ }
31
+ }
32
+ }
33
+ ```
34
+ """)
35
+
36
+ client = AsyncClient(
37
+ base_url=__BASE_URL,
38
+ headers={
39
+ "x-api-key": X_API_KEY,
40
+ "User-Agent": f"pdfco-mcp/{__version__}",
41
+ },
42
+ )
43
+ try:
44
+ yield client
45
+ finally:
46
+ 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
@@ -0,0 +1,371 @@
1
+ from pdfco.mcp.server import mcp
2
+ from pdfco.mcp.services.pdf import convert_to, convert_from
3
+ from pdfco.mcp.models import BaseResponse, ConversionParams
4
+
5
+ from pydantic import Field
6
+
7
+
8
+ @mcp.tool()
9
+ async def pdf_to_json(
10
+ 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."),
11
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
12
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
13
+ 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=""),
14
+ 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),
15
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
16
+ 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"),
17
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
18
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
19
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
20
+ ) -> BaseResponse:
21
+ """
22
+ Convert PDF and scanned images into JSON representation with text, fonts, images, vectors, and formatting preserved using the /pdf/convert/to/json2 endpoint.
23
+ Ref: https://developer.pdf.co/api-reference/pdf-to-json/basic.md
24
+ """
25
+ return await convert_to("pdf", "json2", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
26
+
27
+ @mcp.tool()
28
+ async def pdf_to_csv(
29
+ 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."),
30
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
31
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
32
+ 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=""),
33
+ 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),
34
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
35
+ 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"),
36
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
37
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
38
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
39
+ ) -> BaseResponse:
40
+ """
41
+ Convert PDF and scanned images into CSV representation with layout, columns, rows, and tables.
42
+ Ref: https://developer.pdf.co/api-reference/pdf-to-csv.md
43
+ """
44
+ return await convert_to("pdf", "csv", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
45
+
46
+ @mcp.tool()
47
+ async def pdf_to_text(
48
+ 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."),
49
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
50
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
51
+ 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=""),
52
+ 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),
53
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
54
+ 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"),
55
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
56
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
57
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
58
+ ) -> BaseResponse:
59
+ """
60
+ Convert PDF and scanned images to text with layout preserved.
61
+ Ref: https://developer.pdf.co/api-reference/pdf-to-text/basic.md
62
+ """
63
+ return await convert_to("pdf", "text", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
64
+
65
+ @mcp.tool()
66
+ async def pdf_to_xls(
67
+ 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."),
68
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
69
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
70
+ 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=""),
71
+ 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),
72
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
73
+ 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"),
74
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
75
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
76
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
77
+ ) -> BaseResponse:
78
+ """
79
+ Convert PDF and scanned images to XLS (Excel 97-2003) format.
80
+ Ref: https://developer.pdf.co/api-reference/pdf-to-excel/xls.md
81
+ """
82
+ return await convert_to("pdf", "xls", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
83
+
84
+ @mcp.tool()
85
+ async def pdf_to_xlsx(
86
+ 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."),
87
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
88
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
89
+ 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=""),
90
+ 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),
91
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
92
+ 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"),
93
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
94
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
95
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
96
+ ) -> BaseResponse:
97
+ """
98
+ Convert PDF and scanned images to XLSX (Excel 2007+) format.
99
+ Ref: https://developer.pdf.co/api-reference/pdf-to-excel/xlsx.md
100
+ """
101
+ return await convert_to("pdf", "xlsx", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
102
+
103
+ @mcp.tool()
104
+ async def pdf_to_xml(
105
+ 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."),
106
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
107
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
108
+ 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=""),
109
+ 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),
110
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
111
+ 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"),
112
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
113
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
114
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
115
+ ) -> BaseResponse:
116
+ """
117
+ Convert PDF and scanned images to XML format.
118
+ Ref: https://developer.pdf.co/api-reference/pdf-to-xml.md
119
+ """
120
+ return await convert_to("pdf", "xml", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
121
+
122
+ @mcp.tool()
123
+ async def pdf_to_html(
124
+ 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."),
125
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
126
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
127
+ 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=""),
128
+ 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),
129
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
130
+ 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"),
131
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
132
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
133
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
134
+ ) -> BaseResponse:
135
+ """
136
+ Convert PDF and scanned images to HTML format.
137
+ Ref: https://developer.pdf.co/api-reference/pdf-to-html.md
138
+ """
139
+ return await convert_to("pdf", "html", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
140
+
141
+ @mcp.tool()
142
+ async def pdf_to_image(
143
+ 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."),
144
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
145
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
146
+ 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=""),
147
+ 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),
148
+ rect: str = Field(description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)", default=""),
149
+ 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"),
150
+ line_grouping: str = Field(description="Enables line grouping within table cells when set to '1'. (Optional)", default="0"),
151
+ password: str = Field(description="Password of the PDF file. (Optional)", default=""),
152
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
153
+ type: str = Field(description="Type of image to convert to. (jpg, png, webp, tiff) (Optional)", default="jpg", choices=["jpg", "png", "webp", "tiff"]),
154
+ ) -> BaseResponse:
155
+ """
156
+ Convert PDF and scanned images to various image formats (JPG, PNG, WebP, TIFF).
157
+ Ref:
158
+ - https://developer.pdf.co/api-reference/pdf-to-image/jpg.md
159
+ - https://developer.pdf.co/api-reference/pdf-to-image/png.md
160
+ - https://developer.pdf.co/api-reference/pdf-to-image/webp.md
161
+ - https://developer.pdf.co/api-reference/pdf-to-image/tiff.md
162
+ """
163
+ return await convert_to("pdf", type, ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, unwrap=unwrap, rect=rect, lang=lang, line_grouping=line_grouping, password=password, name=name))
164
+
165
+ @mcp.tool()
166
+ async def document_to_pdf(
167
+ url: str = Field(description="URL to the source file (DOC, DOCX, RTF, TXT, XPS). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
168
+ 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),
169
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
170
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
171
+ 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=""),
172
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
173
+ ) -> BaseResponse:
174
+ """
175
+ Convert various document types (DOC, DOCX, RTF, TXT, XLS, XLSX, CSV, HTML, JPG, PNG, TIFF, WEBP) into PDF.
176
+ Ref: https://developer.pdf.co/api-reference/pdf-from-document/doc.md
177
+ """
178
+ return await convert_from("pdf", "doc", ConversionParams(url=url, autosize=autosize, httpusername=httpusername, httppassword=httppassword, pages=pages, name=name))
179
+
180
+ @mcp.tool()
181
+ async def csv_to_pdf(
182
+ url: str = Field(description="URL to the source file (CSV, XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
183
+ 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),
184
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
185
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
186
+ 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=""),
187
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
188
+ ) -> BaseResponse:
189
+ """
190
+ Convert CSV or spreadsheet files (XLS, XLSX) to PDF.
191
+ Ref: https://developer.pdf.co/api-reference/pdf-from-document/csv.md
192
+ """
193
+ return await convert_from("pdf", "csv", ConversionParams(url=url, autosize=autosize, httpusername=httpusername, httppassword=httppassword, pages=pages, name=name))
194
+
195
+ @mcp.tool()
196
+ async def image_to_pdf(
197
+ url: str = Field(description="URL to the source file (JPG, PNG, TIFF). Multiple files are supported (by providing a comma-separated list of URLs). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
198
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
199
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
200
+ 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=""),
201
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
202
+ ) -> BaseResponse:
203
+ """
204
+ Convert various image formats (JPG, PNG, TIFF) to PDF.
205
+ Ref: https://developer.pdf.co/api-reference/pdf-from-image.md
206
+ ```
207
+ """
208
+ return await convert_from("pdf", "image", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, pages=pages, name=name))
209
+
210
+ @mcp.tool()
211
+ async def webpage_to_pdf(
212
+ url: str = Field(description="URL to the source file (external webpage URL)."),
213
+ 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=""),
214
+ 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=""),
215
+ orientation: str = Field(description="Set to Portrait or Landscape. Portrait is set by default. (Optional)", default=""),
216
+ printBackground: bool = Field(description="true by default. Set to false to disable printing of background. (Optional)", default=True),
217
+ 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=""),
218
+ 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),
219
+ header: str = Field(description="User definable HTML for the header to be applied on every page header. (Optional)", default=""),
220
+ footer: str = Field(description="User definable HTML for the footer to be applied on every page footer. (Optional)", default=""),
221
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
222
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
223
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
224
+ ) -> BaseResponse:
225
+ """
226
+ Convert external webpage URL to PDF.
227
+ Ref: https://developer.pdf.co/api-reference/pdf-from-url.md
228
+
229
+ The header and footer parameters can contain valid HTML markup with the following classes used to inject printing values into them:
230
+ - date: formatted print date
231
+ - title: document title
232
+ - url: document location
233
+ - pageNumber: current page number
234
+ - totalPages: total pages in the document
235
+ - img: tag is supported in both the header and footer parameter, provided that the src attribute is specified as a base64-encoded string.
236
+ For example, the following markup will generate Page N of NN page numbering:
237
+ ```html
238
+ <span style='font-size:10px'>Page <span class='pageNumber'></span> of <span class='totalPages'></span>.</span>
239
+ """
240
+ return await convert_from("pdf", "url", ConversionParams(url=url, margins=margins, paperSize=paperSize, orientation=orientation, printBackground=printBackground, mediaType=mediaType, DoNotWaitFullLoad=DoNotWaitFullLoad, header=header, footer=footer, httpusername=httpusername, httppassword=httppassword, name=name))
241
+
242
+ @mcp.tool()
243
+ async def html_to_pdf(
244
+ 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. If it is a local file, just pass the file content as a string."),
245
+ 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=""),
246
+ 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=""),
247
+ orientation: str = Field(description="Set to Portrait or Landscape. Portrait is set by default. (Optional)", default=""),
248
+ printBackground: bool = Field(description="true by default. Set to false to disable printing of background. (Optional)", default=True),
249
+ 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=""),
250
+ 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),
251
+ header: str = Field(description="User definable HTML for the header to be applied on every page header. (Optional)", default=""),
252
+ footer: str = Field(description="User definable HTML for the footer to be applied on every page footer. (Optional)", default=""),
253
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
254
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
255
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
256
+ ) -> BaseResponse:
257
+ """
258
+ Convert HTML to PDF.
259
+ Ref: https://developer.pdf.co/api-reference/pdf-from-html/convert.md
260
+
261
+ The header and footer parameters can contain valid HTML markup with the following classes used to inject printing values into them:
262
+ - date: formatted print date
263
+ - title: document title
264
+ - url: document location
265
+ - pageNumber: current page number
266
+ - totalPages: total pages in the document
267
+ - img: tag is supported in both the header and footer parameter, provided that the src attribute is specified as a base64-encoded string.
268
+ For example, the following markup will generate Page N of NN page numbering:
269
+ ```html
270
+ <span style='font-size:10px'>Page <span class='pageNumber'></span> of <span class='totalPages'></span>.</span>
271
+ """
272
+ return await convert_from("pdf", "html", ConversionParams(html=html, margins=margins, paperSize=paperSize, orientation=orientation, printBackground=printBackground, mediaType=mediaType, DoNotWaitFullLoad=DoNotWaitFullLoad, header=header, footer=footer, httpusername=httpusername, httppassword=httppassword, name=name))
273
+
274
+ @mcp.tool()
275
+ async def email_to_pdf(
276
+ url: str = Field(description="URL to the source file (MSG, EML). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
277
+ embedAttachments: bool = Field(description="Set to true to automatically embeds all attachments from original input email MSG or EML files into the final output PDF. Set it to false if you don’t want to embed attachments so it will convert only the body of the input email. True by default.", default=True),
278
+ convertAttachments: bool = Field(description="Set to false if you don’t want to convert attachments from the original email and want to embed them as original files (as embedded PDF attachments). Converts attachments that are supported by the PDF.co API (DOC, DOCx, HTML, PNG, JPG etc.) into PDF format and then merges into output final PDF. Non-supported file types are added as PDF attachments (Adobe Reader or another viewer may be required to view PDF attachments).", default=True),
279
+ 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=""),
280
+ 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=""),
281
+ orientation: str = Field(description="Set to Portrait or Landscape. Portrait is set by default. (Optional)", default=""),
282
+ ) -> BaseResponse:
283
+ """
284
+ Convert email to PDF.
285
+ Ref: https://developer.pdf.co/api-reference/pdf-from-email.md
286
+ """
287
+ return await convert_from("pdf", "email", ConversionParams(url=url, embedAttachments=embedAttachments, convertAttachments=convertAttachments, margins=margins, paperSize=paperSize, orientation=orientation))
288
+
289
+ @mcp.tool()
290
+ async def excel_to_csv(
291
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
292
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
293
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
294
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
295
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
296
+ ) -> BaseResponse:
297
+ """
298
+ Convert Excel(XLS, XLSX) to CSV.
299
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/csv.md
300
+ """
301
+ return await convert_to("xls", "csv", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))
302
+
303
+ @mcp.tool()
304
+ async def excel_to_json(
305
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
306
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
307
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
308
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
309
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
310
+ ) -> BaseResponse:
311
+ """
312
+ Convert Excel(XLS, XLSX) to JSON.
313
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/json.md
314
+ """
315
+ return await convert_to("xls", "json", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))
316
+
317
+ @mcp.tool()
318
+ async def excel_to_html(
319
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
320
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
321
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
322
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
323
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
324
+ ) -> BaseResponse:
325
+ """
326
+ Convert Excel(XLS, XLSX) to HTML.
327
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/html.md
328
+ """
329
+ return await convert_to("xls", "html", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))
330
+
331
+ @mcp.tool()
332
+ async def excel_to_txt(
333
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
334
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
335
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
336
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
337
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
338
+ ) -> BaseResponse:
339
+ """
340
+ Convert Excel(XLS, XLSX) to TXT.
341
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/text.md
342
+ """
343
+ return await convert_to("xls", "txt", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))
344
+
345
+ @mcp.tool()
346
+ async def excel_to_xml(
347
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
348
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
349
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
350
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
351
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
352
+ ) -> BaseResponse:
353
+ """
354
+ Convert Excel(XLS, XLSX) to XML.
355
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/xml.md
356
+ """
357
+ return await convert_to("xls", "xml", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))
358
+
359
+ @mcp.tool()
360
+ async def excel_to_pdf(
361
+ url: str = Field(description="URL to the source file (XLS, XLSX). Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files."),
362
+ httpusername: str = Field(description="HTTP auth user name if required to access source url. (Optional)", default=""),
363
+ httppassword: str = Field(description="HTTP auth password if required to access source url. (Optional)", default=""),
364
+ name: str = Field(description="File name for the generated output. (Optional)", default=""),
365
+ worksheetIndex: str = Field(description="Index of the worksheet to convert. (Optional)", default=""),
366
+ ) -> BaseResponse:
367
+ """
368
+ Convert Excel(XLS, XLSX) to PDF.
369
+ Ref: https://developer.pdf.co/api-reference/convert-from-excel/pdf.md
370
+ """
371
+ return await convert_to("xls", "pdf", ConversionParams(url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex))