Skip to main content
Glama
pdfdotco

PDF.co MCP Server

Official
by pdfdotco

wait_job_completion

Monitor PDF processing jobs for completion by checking status at specified intervals until finished or timeout occurs.

Instructions

Wait for a job to complete

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
job_idYesThe ID of the job to get the status of
intervalNoThe interval to check the status of the job (seconds)
timeoutNoThe timeout to wait for the job to complete (seconds)
api_keyNoPDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)

Implementation Reference

  • The primary handler function for the 'wait_job_completion' tool. Decorated with @mcp.tool() to register it with the MCP server. Polls the job status at specified intervals until completion, failure, or timeout, aggregating credits and providing tips.
    @mcp.tool()
    async def wait_job_completion(
        job_id: str = Field(description="The ID of the job to get the status of"),
        interval: int = Field(
            description="The interval to check the status of the job (seconds)", default=1
        ),
        timeout: int = Field(
            description="The timeout to wait for the job to complete (seconds)", default=300
        ),
        api_key: str = Field(
            description="PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)",
            default="",
        ),
    ) -> BaseResponse:
        """
        Wait for a job to complete
        """
        start_time = time.time()
        job_check_count = 0
        credits_used = 0
        credits_remaining = 0
        while True:
            response = await _get_job_status(job_id, api_key=api_key)
            job_check_count += 1
            credits_used += response.credits_used or 0
            credits_remaining = response.credits_remaining or 0
            if response.status == "success":
                return BaseResponse(
                    status="success",
                    content=response.content,
                    credits_used=credits_used,
                    credits_remaining=credits_remaining,
                    tips=f"Job check count: {job_check_count}",
                )
            elif response.status == "failed":
                return BaseResponse(
                    status="error",
                    content=response.content,
                    credits_used=credits_used,
                    credits_remaining=credits_remaining,
                )
            await asyncio.sleep(interval)
            if time.time() - start_time > timeout:
                return BaseResponse(
                    status="error",
                    content="Job timed out",
                    credits_used=credits_used,
                    credits_remaining=credits_remaining,
                    tips=f"Job check count: {job_check_count}",
                )
  • Supporting helper function _get_job_status that queries the PDF.co API for job status. Used internally by wait_job_completion (and get_job_check) without MCP decoration.
    async def _get_job_status(job_id: str, api_key: str = "") -> BaseResponse:
        """
        Internal helper function to check job status without MCP tool decoration
        """
        try:
            async with PDFCoClient(api_key=api_key) as client:
                response = await client.post(
                    "/v1/job/check",
                    json={
                        "jobId": job_id,
                    },
                )
                json_data = response.json()
                return BaseResponse(
                    status=json_data["status"],
                    content=json_data,
                    credits_used=json_data.get("credits"),
                    credits_remaining=json_data.get("remainingCredits"),
                    tips="You can download the result if status is success",
                )
        except Exception as e:
            return BaseResponse(
                status="error",
                content=str(e),
            )
  • Input schema defined via Pydantic Field descriptions in the function signature, which MCP uses for tool input validation. Returns BaseResponse model.
    async def wait_job_completion(
        job_id: str = Field(description="The ID of the job to get the status of"),
        interval: int = Field(
            description="The interval to check the status of the job (seconds)", default=1
        ),
        timeout: int = Field(
            description="The timeout to wait for the job to complete (seconds)", default=300
        ),
        api_key: str = Field(
            description="PDF.co API key. If not provided, will use X_API_KEY environment variable. (Optional)",
            default="",
        ),
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions waiting but doesn't disclose key behaviors: it's a blocking operation with polling (implied by 'interval' parameter), potential for timeout, or that it may return job results or errors. This is inadequate for a tool with mutation-like waiting behavior and no structured safety hints.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste—'Wait for a job to complete' is front-loaded and appropriately sized for the tool's purpose. It earns its place by stating the core action without redundancy or fluff.

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?

Given the tool's complexity (blocking wait with polling and timeout), no annotations, and no output schema, the description is incomplete. It doesn't cover return values (e.g., job status, results, errors), behavioral details like polling mechanics, or integration with sibling tools, leaving significant gaps for agent understanding.

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 description coverage is 100%, so the schema fully documents parameters like 'job_id', 'interval', 'timeout', and 'api_key'. The description adds no meaning beyond the schema, as it doesn't explain parameter interactions (e.g., how interval affects polling) or usage nuances. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Wait for a job to complete' clearly states the action (wait) and target (job completion), but it's vague about what constitutes 'completion' (e.g., success, failure, timeout) and doesn't differentiate from sibling tools like 'get_job_check', which might check status without waiting. It avoids tautology but lacks specificity.

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 is provided on when to use this tool versus alternatives such as 'get_job_check' for immediate status checks or other job-related tools. The description implies usage for waiting, but it doesn't specify prerequisites (e.g., needing a job ID from another tool) or exclusions, leaving the agent to infer context.

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