Skip to main content
Glama
pdfdotco

PDF.co MCP Server

Official
by pdfdotco

pdf_to_json

Convert PDFs and scanned images to JSON while preserving text, fonts, images, vectors, and formatting using the /pdf/convert/to/json2 endpoint.

Instructions

Convert PDF and scanned images into JSON representation with text, fonts, images, vectors, and formatting preserved using the /pdf/convert/to/json2 endpoint.
Ref: https://developer.pdf.co/api-reference/pdf-to-json/basic.md

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to the source file. Supports publicly accessible links including Google Drive, Dropbox, PDF.co Built-In Files Storage. Use 'upload_file' tool to upload local files.
httpusernameNoHTTP auth user name if required to access source url. (Optional)
httppasswordNoHTTP auth password if required to access source url. (Optional)
pagesNoComma-separated page indices (e.g., '0, 1, 2-' or '1, 3-7'). Use '!' for inverted page numbers (e.g., '!0' for last page). Processes all pages if None. (Optional)
unwrapNoUnwrap lines into a single line within table cells when lineGrouping is enabled. Must be true or false. (Optional)
rectNoDefines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)
langNoLanguage for OCR for scanned documents. Default is 'eng'. See PDF.co docs for supported languages. (Optional, Default: 'eng')eng
line_groupingNoEnables line grouping within table cells when set to '1'. (Optional)0
passwordNoPassword of the PDF file. (Optional)
nameNoFile name for the generated output. (Optional)
api_keyNoPDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)

Implementation Reference

  • The actual handler function for the 'pdf_to_json' MCP tool. Decorated with @mcp.tool(), it accepts parameters (url, httpusername, httppassword, pages, unwrap, rect, lang, line_grouping, password, name, api_key) and delegates to the 'convert_to' service function with source='pdf' and target='json2'.
    @mcp.tool()
    async def pdf_to_json(
        url: str = Field(
            description="URL to the source file. 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="",
        ),
        pages: str = Field(
            description="Comma-separated page indices (e.g., '0, 1, 2-' or '1, 3-7'). Use '!' for inverted page numbers (e.g., '!0' for last page). Processes all pages if None. (Optional)",
            default="",
        ),
        unwrap: bool = Field(
            description="Unwrap lines into a single line within table cells when lineGrouping is enabled. Must be true or false. (Optional)",
            default=False,
        ),
        rect: str = Field(
            description="Defines coordinates for extraction (e.g., '51.8,114.8,235.5,204.0'). (Optional)",
            default="",
        ),
        lang: str = Field(
            description="Language for OCR for scanned documents. Default is 'eng'. See PDF.co docs for supported languages. (Optional, Default: 'eng')",
            default="eng",
        ),
        line_grouping: str = Field(
            description="Enables line grouping within table cells when set to '1'. (Optional)",
            default="0",
        ),
        password: str = Field(
            description="Password of the PDF file. (Optional)", default=""
        ),
        name: str = Field(
            description="File name for the generated output. (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 PDF and scanned images into JSON representation with text, fonts, images, vectors, and formatting preserved using the /pdf/convert/to/json2 endpoint.
        Ref: https://developer.pdf.co/api-reference/pdf-to-json/basic.md
        """
        return await convert_to(
            "pdf",
            "json2",
            ConversionParams(
                url=url,
                httpusername=httpusername,
                httppassword=httppassword,
                pages=pages,
                unwrap=unwrap,
                rect=rect,
                lang=lang,
                line_grouping=line_grouping,
                password=password,
                name=name,
            ),
            api_key=api_key,
        )
  • The 'convert_to' helper function called by pdf_to_json. It constructs the API endpoint as '{_from}/convert/to/{_to}' (i.e., 'pdf/convert/to/json2') and delegates to the '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)
  • The 'request' helper that executes the actual HTTP POST to the PDF.co API. It calls the PDFCoClient, sends the payload, and wraps the response in a BaseResponse.
    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]}",
            )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose behavioral traits beyond the core conversion. Missing details about authentication needs, output size limits, or potential side effects. The reference link is helpful but not in the description itself.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences plus a reference link; concise and front-loaded with the core purpose. Could be slightly more structured but effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 11 parameters and no output schema, the description provides minimal context about usage, output format, or examples. More detail is needed to fully understand the tool's capabilities.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already describes parameters. The description adds no additional meaning beyond what is in the schema, but the schema is comprehensive.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states 'Convert PDF and scanned images into JSON representation', which is specific and distinguishes this tool from other conversion tools like pdf_to_text or pdf_to_xml. However, it does not explicitly differentiate from siblings, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool vs alternatives, no exclusions or prerequisites provided. The description simply states what it does without context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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