upload_file
Transfer a file to the PDF.co API for processing, enabling tasks like PDF conversion, editing, and security operations. Requires the file’s absolute path and an optional API key.
Instructions
Upload a file to the PDF.co API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | No | PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional) | |
| file_path | Yes | The absolute path to the file to upload |
Implementation Reference
- pdfco/mcp/tools/apis/file.py:8-37 (handler)The main handler function for the 'upload_file' tool. It uploads a local file to PDF.co API using PDFCoClient and returns a BaseResponse.@mcp.tool() async def upload_file( file_path: str = Field(description="The absolute path to the file to upload"), api_key: str = Field( description="PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)", default="", ), ) -> BaseResponse: """ Upload a file to the PDF.co API """ try: async with PDFCoClient(api_key=api_key) as client: response = await client.post( "/v1/file/upload", files={ "file": open(file_path, "rb"), }, ) res = response.json() return BaseResponse( status="success" if res["status"] == 200 else "error", content=res, tips=f"You can use the url {res['url']} to access the file", ) except Exception as e: return BaseResponse( status="error", content=str(e), )
- pdfco/mcp/models.py:5-10 (schema)Pydantic model used as the output schema for the upload_file tool (and others).class BaseResponse(BaseModel): status: str content: Any credits_used: int | None = None credits_remaining: int | None = None tips: str | None = None
- pdfco/mcp/__init__.py:3-15 (registration)Imports the 'file' module (containing upload_file), which triggers registration of the tool via the @mcp.tool() decorator when the module is imported.from pdfco.mcp.tools.apis import ( conversion, job, file, modification, form, search, searchable, security, document, extraction, editing, )
- pdfco/mcp/tools/apis/file.py:1-2 (helper)Imports the mcp decorator and other dependencies used in the upload_file handler.from pdfco.mcp.server import mcp from pdfco.mcp.services.client import PDFCoClient