Skip to main content
Glama

extract_receipt_async

Submit a receipt image or PDF for asynchronous AI extraction of receipt data. Receive a job ID to poll for status, with optional webhook notification. Returns extracted data for further processing.

Instructions

Submit a receipt for async AI extraction. Returns a job ID for polling.

Use get_receipt_job to check status and get_receipt_job_result for the result.

Args: image_base64: Base64-encoded receipt image or PDF. filename: Original filename. content_type: MIME type (default: image/jpeg). callback_url: Optional webhook URL to receive the result.

Returns: JSON with jobId and status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_base64Yes
filenameNoreceipt.jpg
content_typeNoimage/jpeg
callback_urlNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function for the extract_receipt_async MCP tool. Decodes base64 image bytes and calls dg.receipts.extract_async() to submit the receipt for async AI extraction, returning a job ID for polling.
    def extract_receipt_async(
        image_base64: str,
        filename: str = "receipt.jpg",
        content_type: str = "image/jpeg",
        callback_url: str | None = None,
    ) -> str:
        """Submit a receipt for async AI extraction. Returns a job ID for polling.
    
        Use get_receipt_job to check status and get_receipt_job_result for the result.
    
        Args:
            image_base64: Base64-encoded receipt image or PDF.
            filename: Original filename.
            content_type: MIME type (default: image/jpeg).
            callback_url: Optional webhook URL to receive the result.
    
        Returns:
            JSON with jobId and status.
        """
        dg = _get_client()
        file_bytes = base64.b64decode(image_base64)
        result = dg.receipts.extract_async(file_bytes, filename, content_type, callback_url=callback_url)
        return json.dumps(result, default=str)
  • Registration of extract_receipt_async as an MCP tool via the @mcp.tool() decorator on the FastMCP instance.
    @mcp.tool()
    def extract_receipt_async(
  • Helper function _get_client() that lazily initializes the DocGen client, which provides the receipts.extract_async() method used by the handler.
    def _get_client():
        """Lazy-initialise the DocGen client."""
        global _client
        if _client is None:
            # Import here so the module can be imported without the SDK installed
            # (useful for schema introspection)
            from docgen import DocGen
    
            api_key = os.environ.get("DOCGEN_API_KEY", "")
            if not api_key:
                raise RuntimeError(
                    "DOCGEN_API_KEY environment variable is required. "
                    "Set it to your DocGen API key before starting the server."
                )
            base_url = os.environ.get("DOCGEN_BASE_URL")
            kwargs: dict[str, Any] = {"api_key": api_key}
            if base_url:
                kwargs["base_url"] = base_url
            _client = DocGen(**kwargs)
        return _client
Behavior3/5

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

No annotations are provided, so the description must carry the behavioral burden. It states the return (job ID) and optional callback_url, but lacks details on error handling, rate limits, or potential rejection reasons. It adequately describes the async submission pattern.

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 extremely concise: one sentence for purpose, one for usage guidance, and a clear list of parameters. Every sentence adds value, and the structure front-loads the most important information.

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

Completeness5/5

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

Given the complexity (async job with polling), the description covers the full lifecycle: submit, then poll status, then get result. It mentions the return JSON structure and the optional callback_url. With sibling tools for polling and results, this is complete.

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

Parameters5/5

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

The input schema has 0% description coverage, so the description fully compensates by explaining each parameter (image_base64, filename, content_type, callback_url), including defaults and optionality. This adds significant value beyond the schema.

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

Purpose5/5

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

The description clearly states the action (submit a receipt), the resource (receipt), and the outcome (returns a job ID for polling). It distinguishes from siblings like extract_receipt (synchronous) and get_receipt_job by emphasizing the async nature.

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

Usage Guidelines5/5

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

It explicitly instructs to use get_receipt_job for status and get_receipt_job_result for the result, and implies this is the async alternative to extract_receipt. This provides clear when-to-use guidance.

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/dokmatiq/docgen-sdks'

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