upload_file
Upload files to the PDF.co API for processing tasks like conversion, editing, searching, and security operations.
Instructions
Upload a file to the PDF.co API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | The absolute path to the file to upload | |
| api_key | No | PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional) |
Implementation Reference
- pdfco/mcp/tools/apis/file.py:8-37 (handler)The main handler function for the 'upload_file' tool. It uploads the specified file to the PDF.co API using the PDFCoClient, handles the response, and returns a BaseResponse with status, content, and tips.@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/tools/apis/file.py:8-37 (registration)The @mcp.tool() decorator registers this function as the 'upload_file' MCP tool.@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/tools/apis/file.py:9-15 (schema)Pydantic Field definitions provide input schema (parameters) and output type (BaseResponse).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: