Skip to main content
Glama

extract_receipt

Extract vendor, date, totals, line items, and other structured data from receipt or invoice images using AI. Returns confidence score and supports JPEG, PNG, or PDF.

Instructions

Extract structured data from a receipt or invoice image using AI.

Returns vendor, date, totals (gross/net/VAT per rate), line items, currency, payment method, SKR03/04 account, category, and confidence score.

Args: image_base64: Base64-encoded receipt image (JPEG, PNG) or PDF. filename: Original filename (helps with format detection). content_type: MIME type (default: image/jpeg). Use application/pdf for PDF receipts.

Returns: JSON with extracted receipt data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_base64Yes
filenameNoreceipt.jpg
content_typeNoimage/jpeg

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler for the extract_receipt MCP tool. Decodes the base64 image, calls dg.receipts.extract(), and returns JSON results.
    @mcp.tool()
    def extract_receipt(image_base64: str, filename: str = "receipt.jpg", content_type: str = "image/jpeg") -> str:
        """Extract structured data from a receipt or invoice image using AI.
    
        Returns vendor, date, totals (gross/net/VAT per rate), line items,
        currency, payment method, SKR03/04 account, category, and confidence score.
    
        Args:
            image_base64: Base64-encoded receipt image (JPEG, PNG) or PDF.
            filename: Original filename (helps with format detection).
            content_type: MIME type (default: image/jpeg). Use application/pdf for PDF receipts.
    
        Returns:
            JSON with extracted receipt data.
        """
        dg = _get_client()
        file_bytes = base64.b64decode(image_base64)
        result = dg.receipts.extract(file_bytes, filename, content_type)
        return json.dumps(result, default=str)
  • The @mcp.tool() decorator registers extract_receipt as an MCP tool on the FastMCP instance.
    @mcp.tool()
Behavior3/5

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

No annotations are provided, so the description carries full burden. It discloses the AI-based extraction and return format but omits limitations, error handling, or performance characteristics (e.g., image size, confidence thresholds).

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?

The description is concise (4 sentences plus a bullet list of return fields) and front-loaded with the core purpose. It wastes no words, though the list could be integrated more smoothly.

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

Completeness4/5

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

Given the tool's complexity (AI OCR, structured output), the description covers input requirements and output fields comprehensively. However, it does not detail the exact JSON structure or error responses, and the output schema existence is not leveraged.

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

Parameters4/5

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

With 0% schema description coverage, the description adds meaning to all three parameters: image_base64 as base64-encoded image, filename for format detection, content_type with MIME type defaults and PDF handling. This compensates well for the sparse 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 tool extracts structured data from receipt/invoice images via AI, listing specific extracted fields. It distinguishes itself from sibling tools like extract_receipt_async (async variant) and extract_text_from_pdf (pure text extraction) by focusing on structured receipt data.

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

Usage Guidelines3/5

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

The description implies use for receipt/invoice images but lacks explicit guidance on when to use this tool versus alternatives like extract_receipt_async. No when-not conditions or prerequisites are mentioned.

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