extract_attachments
Extract embedded files from PDF documents to access attachments like images, spreadsheets, or documents stored within PDF files.
Instructions
Extracts attachments from a source PDF file.
Ref: https://developer.pdf.co/api-reference/pdf-extract-attachments.md
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to the source PDF file. | |
| 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) | |
| password | No | Password of PDF file. (Optional) | |
| api_key | No | PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional) |
Implementation Reference
- pdfco/mcp/tools/apis/extraction.py:31-59 (handler)The MCP tool handler for 'extract_attachments'. It defines the input schema using Pydantic Field, registers the tool via @mcp.tool(), and delegates to the service helper function extract_pdf_attachments.@mcp.tool() async def extract_attachments( url: str = Field(description="URL to the source PDF file."), 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="", ), password: str = Field(description="Password of PDF file. (Optional)", default=""), api_key: str = Field( description="PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)", default="", ), ) -> BaseResponse: """ Extracts attachments from a source PDF file. Ref: https://developer.pdf.co/api-reference/pdf-extract-attachments.md """ params = ConversionParams( url=url, httpusername=httpusername if httpusername else None, httppassword=httppassword if httppassword else None, password=password if password else None, ) return await extract_pdf_attachments(params, api_key=api_key)
- pdfco/mcp/services/pdf.py:119-123 (helper)Service helper function that invokes the PDF.co API endpoint for extracting attachments from PDF.async def extract_pdf_attachments( params: ConversionParams, api_key: str | None = None ) -> BaseResponse: return await request("pdf/attachments/extract", params, api_key=api_key)
- pdfco/mcp/services/pdf.py:125-154 (helper)Core request helper function used by extract_pdf_attachments to make the async HTTP POST request to the PDF.co API.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]}", )