Skip to main content
Glama
pdfdotco

PDF.co MCP Server

Official
by pdfdotco

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
NameRequiredDescriptionDefault
urlYesURL to the source PDF file.
httpusernameNoHTTP auth user name if required to access source url. (Optional)
httppasswordNoHTTP auth password if required to access source url. (Optional)
passwordNoPassword of PDF file. (Optional)
api_keyNoPDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)

Implementation Reference

  • 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)
  • 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)
  • 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]}", )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pdfdotco/pdfco-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server