excel_to_json
Convert Excel files (XLS, XLSX) to JSON format for data processing and integration. Supports public URLs and cloud storage links.
Instructions
Convert Excel(XLS, XLSX) to JSON.
Ref: https://developer.pdf.co/api-reference/convert-from-excel/json.md
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 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. | |
| httpusername | No | HTTP auth user name if required to access source url. (Optional) | |
| httppassword | No | HTTP auth password if required to access source url. (Optional) | |
| name | No | File name for the generated output. (Optional) | |
| worksheetIndex | No | Index of the worksheet to convert. (Optional) | |
| api_key | No | PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional) |
Implementation Reference
- The main handler function for the 'excel_to_json' MCP tool. Decorated with @mcp.tool() for automatic registration and schema definition via Pydantic Field descriptions. It wraps the convert_to service to perform Excel to JSON conversion via PDF.co API.@mcp.tool() async def excel_to_json( 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." ), httpusername: str = Field( description="HTTP auth user name if required to access source url. (Optional)", default="", ), httppassword: str = Field( description="HTTP auth password if required to access source url. (Optional)", default="", ), name: str = Field( description="File name for the generated output. (Optional)", default="" ), worksheetIndex: str = Field( description="Index of the worksheet to convert. (Optional)", default="" ), api_key: str = Field( description="PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)", default="", ), ) -> BaseResponse: """ Convert Excel(XLS, XLSX) to JSON. Ref: https://developer.pdf.co/api-reference/convert-from-excel/json.md """ return await convert_to( "xls", "json", ConversionParams( url=url, httpusername=httpusername, httppassword=httppassword, name=name, worksheetIndex=worksheetIndex, api_key=api_key, ), )
- pdfco/mcp/services/pdf.py:6-9 (helper)Helper function convert_to that constructs the PDF.co API endpoint for conversion from one format to another and calls the generic request function.async def convert_to( _from: str, _to: str, params: ConversionParams, api_key: str | None = None ) -> BaseResponse: return await request(f"{_from}/convert/to/{_to}", params, api_key=api_key)
- pdfco/mcp/services/pdf.py:125-154 (helper)Core request helper that makes async POST requests to PDF.co API endpoints, parses responses into BaseResponse, and handles job IDs with tips for completion.async def request( endpoint: str, params: ConversionParams, custom_payload: dict | None = None, api_key: str | None = None, ) -> BaseResponse: payload = params.parse_payload(async_mode=True) if custom_payload: payload.update(custom_payload) try: async with PDFCoClient(api_key=api_key) as client: url = f"/v1/{endpoint}" print(f"Requesting {url} with payload {payload}", file=sys.stderr) response = await client.post(url, json=payload) print(f"response: {response}", file=sys.stderr) json_data = response.json() return BaseResponse( status="working", content=json_data, credits_used=json_data.get("credits"), credits_remaining=json_data.get("remainingCredits"), 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.", ) except Exception as e: return BaseResponse( status="error", content=f"{type(e)}: {[arg for arg in e.args if arg]}", )