Skip to main content
Glama

Invoice Vision MCP

An MCP server that lets AI agents read invoice images. It uses computer vision (OpenCV + Tesseract OCR) to turn a scan or phone photo into structured data, checks it against Saudi VAT rules, and stores it in SQL so an LLM can answer questions like "How much did we spend on IT services last month?"

Preprocessing pipeline

Protocol

Model Context Protocol (MCP): tools, resources and prompts over stdio or Streamable HTTP

Computer vision

OpenCV denoising, projection-profile deskew, adaptive thresholding → Tesseract OCR

Extraction

Rule-based parser → Pydantic models (vendor, invoice no., date, VAT no., line items, totals)

Validation

15% VAT check, total = subtotal + VAT, line items sum to the subtotal, 15-digit VAT number

Storage

SQLite with duplicate protection and a read-only SQL tool for analysts and agents

Quality

21 automated tests, including a real MCP client session and security tests


Why

Finance teams still type invoices into spreadsheets by hand. LLMs are good at answering questions about the data, but they can't open your files or your database safely. MCP is the standard way to give a model controlled access to tools and data. This server is that bridge: any MCP client (Claude Desktop, Cursor, VS Code, or the Business Analyst Agent built with LangGraph) can ingest invoices and analyse spend.

Related MCP server: Doc Agent

Architecture

flowchart LR
    A[Invoice image<br/>scan / phone photo] --> B[OpenCV preprocessing<br/>grayscale · denoise · deskew · threshold]
    B --> C[Tesseract OCR<br/>text + confidence]
    C --> D[Parser<br/>regex → Pydantic]
    D --> E[Validator<br/>VAT 15% · totals · VAT no.]
    E --> F[(SQLite)]
    F --> G[MCP server<br/>tools · resources · prompts]
    G <--> H[MCP clients<br/>Claude Desktop · Cursor · LangGraph agent]

MCP interface

Type

Name

What it does

Tool

list_inbox

New vs already-ingested images in the inbox

Tool

extract_invoice

Run CV + OCR and return structured fields (does not save)

Tool

ingest_invoice

Extract, validate and save; duplicates are rejected

Tool

list_invoices

Filter by vendor, category, date range, or invalid only

Tool

get_invoice

One invoice with its line items and validation issues

Tool

spending_report

Count, subtotal, VAT and total grouped by vendor, category or month

Tool

query_invoices_sql

Read-only SELECT for questions the other tools don't cover

Resource

invoices://schema

DB schema, so the model writes correct SQL

Resource

invoices://summary

Headline numbers

Prompt

monthly_spend_report

Reusable template for a monthly finance report (EN + AR)

Results

Measured with python scripts/evaluate.py on 12 generated invoices. One in three is a simulated phone photo (rotated ±4°, blurred, noisy), and 2 contain deliberate errors.

Metric

Result

Field accuracy (7 header fields)

100% (84/84)

Line-item count match

100%

Error detection (bad invoices flagged, good ones passed)

100%

Mean OCR confidence

~94%

Time per invoice (CPU)

~1.5 s

Honest limitation: the data is synthetic and uses one clean layout. Real invoices vary widely, so a rule-based parser will miss fields on unseen layouts. The roadmap below covers how I would handle that.

Security

An MCP server runs with real permissions, so it's built defensively:

  • Path sandbox. Files are resolved inside INVOICE_INBOX only, so ../../etc/passwd is rejected (tested).

  • Read-only SQL. The SQL tool uses a keyword filter, allows one statement only, and opens a mode=ro SQLite connection (tested).

  • Typed inputs. Every tool argument is validated through its type-hinted signature.

  • No secrets. The server needs no API keys, and everything runs locally.

Quick start

# 1. System dependency
sudo apt install tesseract-ocr        # macOS: brew install tesseract

# 2. Install
git clone https://github.com/Abdullah-Alroumi/invoice-vision-mcp
cd invoice-vision-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

# 3. Demo data and tests
python -m invoice_vision.samples --out samples
pytest -q
python scripts/evaluate.py

# 4. Inspect the server in the official MCP Inspector
npx @modelcontextprotocol/inspector invoice-vision-mcp

Use it from Claude Desktop

Add this to claude_desktop_config.json:

{
  "mcpServers": {
    "invoice-vision": {
      "command": "/absolute/path/to/.venv/bin/invoice-vision-mcp",
      "env": {
        "INVOICE_INBOX": "/absolute/path/to/samples",
        "INVOICE_DB": "/absolute/path/to/data/invoices.db"
      }
    }
  }
}

Then ask: "Ingest the new invoices and show me spend by category. Which ones failed validation?"

Run over HTTP (Docker)

docker build -t invoice-vision-mcp .
docker run -p 8000:8000 -v $PWD/samples:/app/samples invoice-vision-mcp
# MCP endpoint: http://localhost:8000/mcp

Configuration

Variable

Default

Meaning

INVOICE_INBOX

./samples

Only folder the server may read images from

INVOICE_DB

./data/invoices.db

SQLite path

OCR_LANG

eng

Tesseract languages, e.g. eng+ara

MCP_TRANSPORT

stdio

stdio or streamable-http

MCP_HOST / MCP_PORT

127.0.0.1 / 8000

Bind address for HTTP transport

Project structure

src/invoice_vision/
├── preprocess.py   # OpenCV pipeline (deskew via projection profile)
├── ocr.py          # Tesseract wrapper with confidence score
├── parser.py       # OCR text → Invoice, plus VAT business rules
├── models.py       # Pydantic schemas
├── pipeline.py     # image → validated ExtractionResult
├── db.py           # SQLite repository + read-only query guard
├── samples.py      # synthetic invoice generator (demo + tests)
└── server.py       # MCP tools / resources / prompts
scripts/            # accuracy evaluation
tests/              # parser, vision, DB, MCP-client and security tests

Roadmap

  • Vision-language model fallback. When OCR confidence is low or validation fails, send the image to a VLM for layout-free extraction, and keep the rule-based path as the cheap default.

  • Arabic invoices (OCR_LANG=eng+ara) and the ZATCA e-invoice QR code (TLV decoding).

  • Layout detection (YOLO / LayoutParser) to find the totals and line-item regions before OCR.

  • PostgreSQL and auth for multi-user HTTP deployments.

License

MIT. All sample companies and numbers are fictional.

Available Tools

7 tools
extract_invoiceA

Run computer vision + OCR on an invoice image and return structured fields WITHOUT saving.

Args: filename: image file name inside the inbox, e.g. "inv_001.png"

Inputs: filename (required).

get_invoiceA

Get one stored invoice with its line items and validation issues.

Inputs: invoice_id (required).

ingest_invoiceB

Extract an invoice image and save it to the database. Invalid invoices are saved but flagged.

Args: filename: image file name inside the inbox

Inputs: filename (required).

list_inboxB

List invoice images in the inbox and whether each one has already been ingested.

Inputs: no named parameters.

list_invoicesC

List stored invoices with optional filters. Dates are ISO strings (yyyy-mm-dd).

Categories: office_supplies, it_services, utilities, catering, logistics, maintenance, other.

Inputs: limit, vendor, date_to, category, +2 more. Returns: result

query_invoices_sqlA

Run a read-only SQL SELECT against the invoice database (tables: invoices, line_items).

Read the invoices://schema resource first. Writes are rejected.

Inputs: sql (required). Returns: result

spending_reportB

Aggregate spend (count, subtotal, VAT, total) grouped by 'vendor', 'category' or 'month'.

Inputs: date_to, group_by, date_from. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 7 tools

    Disambiguation4/5

    Each tool has a distinct role: listing inbox files vs. listing stored invoices, extracting without saving vs. ingesting with save, plus a report aggregator and a raw SQL escape hatch. The only real point of confusion is list_inbox vs. list_invoices, which differ in resource (inbox images vs. database records) but sound similar; descriptions clarify the difference.

    Naming Consistency4/5

    Most tools follow a clean verb_noun snake_case pattern (list_inbox, get_invoice, extract_invoice, ingest_invoice, list_invoices). spending_report drops the verb and query_invoices_sql appends a suffix, which are minor but noticeable deviations.

    Tool Count5/5

    Seven tools is a well-scoped surface for an invoice pipeline: inbox discovery, extraction, ingestion, retrieval, listing, aggregation, and SQL query. Every tool earns its place with no obvious filler.

    Completeness4/5

    The pipeline covers the full core lifecycle from inbox image to stored, queryable invoice with reporting. Gaps exist around mutation/cleanup (no delete or re-ingest/update of stored invoices, no way to resolve flagged validation issues), but read-only SQL and the flags field provide reasonable workarounds.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      Not graded
      maintenance
      A Python MCP server for invoice and receipt processing that uses OCR technology to extract data from PDFs and images, offering AI assistants the ability to process, extract text from, and merge invoice documents.
      2
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables extraction of structured data from documents like invoices, receipts, and bank statements using local Vision AI (Ollama) or cloud providers (Gemini), with data stored in a local SQLite database.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      MCP server for ScanToBill, an AI-powered OCR platform that extracts structured JSON from invoices and business documents in Arabic and English. It enables Claude Desktop to extract invoice data from URLs, list past extractions, and retrieve detailed results.
      3
      9 npm
      MIT