Skip to main content
Glama
idin9-doc-ocr-mcp

idin9-doc-ocr-mcp

by idin9

idin9-doc-ocr-mcp

Standalone Model Context Protocol (MCP) server for document OCR and Thai tax invoice processing, with automated scanner ingestion (SMB/Shared Folder) and SQLite storage.

The server extracts tax invoices from PDFs and scanned images, parses the 13 core Thai tax-invoice fields, applies three-tier routing (success / need-train / failed), and stores results in SQLite. It can also poll an SMB scanner share or watch a local drop folder.

Features

  • Digital + scanned documents — PyMuPDF for embedded text, Tesseract (tha+eng) with image pre-processing (grayscale, de-noise, adaptive threshold, de-skew) for scans.

  • Thai tax invoice parsing — supplier/buyer, 13-digit tax IDs, line items, summary, currency, and capture-rate scoring.

  • Three-tier routing

    • success — 100% capture + valid totals + buyer verification → processed/YYYY-MM/

    • need_train — 80–99% capture → Need-Train/

    • failed — < 80% capture or non-tax document → failed/

  • Automated ingestion — SMBv2/v3 scanner share polling and watchdog folder watching.

  • SQLite storage — WAL mode, tax invoices + canonical contacts tables, full CRUD.

  • MCP tools — exposed via FastMCP for Hermes / Claude Desktop / any MCP client.

Related MCP server: DocumentPro MCP

Requirements

  • Python 3.11+

  • Tesseract OCR with Thai + English language packs (tesseract-ocr-tha, tesseract-ocr-eng)

  • Access to a scanner SMB share (optional)

Debian / Ubuntu Tesseract install

sudo apt-get update
sudo apt-get install -y tesseract-ocr tesseract-ocr-tha tesseract-ocr-eng

Installation

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # then edit values

Configuration

Copy .env.example to .env and adjust:

Variable

Description

SCAN_DROP_DIR

Local/mounted scanner drop folder

SMB_HOST, SMB_SHARE, SMB_USER, SMB_PASSWORD, SMB_DOMAIN

SMB scanner share (leave blank to disable)

DB_PATH

SQLite database path

TESSERACT_CMD, OCR_LANGUAGES, OCR_DPI

OCR engine settings

MIN_EMBEDDED_TEXT_CHARS

Threshold to decide digital vs scanned extraction

Running

python -m src.mcp_server

Or with Docker:

docker compose up --build

MCP Client Configuration

Hermes

{
  "mcpServers": {
    "idin9-doc-ocr-mcp": {
      "command": "python",
      "args": ["-m", "src.mcp_server"],
      "cwd": "/path/to/idin9-doc-ocr-mcp",
      "env": {
        "TESSERACT_CMD": "tesseract",
        "OCR_LANGUAGES": "tha+eng"
      }
    }
  }
}

Claude Desktop

{
  "mcpServers": {
    "idin9-doc-ocr-mcp": {
      "command": "python",
      "args": ["-m", "src.mcp_server"],
      "cwd": "/path/to/idin9-doc-ocr-mcp"
    }
  }
}

Available Tools

Tool

Purpose

ocr_extract_invoice(file_path)

Extract a single PDF/image invoice

ocr_batch_process(folder_path?)

Process all pending files in a folder

ocr_poll_scanner_share()

Pull & process new files from the SMB share

ocr_get_record(invoice_id?, invoice_number?)

Retrieve a stored record

ocr_list_records(status?, limit=50)

List records with filters

ocr_manage_contact(action, tax_id, company_name?)

CRUD on contacts

ocr_review_queue(limit=50)

List low-confidence (need_train) records awaiting human confirmation

ocr_review_record(invoice_id, action, reviewer, notes?, corrected?)

Confirm (→ success) or reject (→ failed) a review item

ocr_system_health()

DB/SMB/queue health report

Human Review Workflow (Multi-User)

Documents that score 80–99% capture (or have valid totals but an unverified buyer) are routed to Need-Train/ and stored with status need_train. These are held for human confirmation before they are trusted as final.

Two interfaces are provided, both backed by the same SQLite database:

1. MCP tools (for Claude Desktop / Hermes)

  • ocr_review_queue() → returns pending items.

  • ocr_review_record(invoice_id, action="confirm"|"reject", reviewer, notes?, corrected?)

    • confirm → status becomes success, file moves to processed/YYYY-MM/, reviewer identity and optional corrected fields are stored.

    • reject → status becomes failed, file moves to failed/.

2. Web UI (for manual multi-user review)

Run the review web server:

python -m src.webui
# or: idin9-doc-ocr-webui
# optional port: WEBUI_PORT=8080 python -m src.webui

Open http://localhost:8080. The queue lists every pending invoice; opening one shows an editable form (header, supplier, buyer, summary) plus the raw OCR text. A reviewer enters their name, then Confirms as correct or Rejects as bad. The reviewer name is remembered via a cookie and recorded on the record (reviewer, reviewed_at, review_notes, review_status).

The tax_invoices table gains these review columns: review_status (pending/confirmed/rejected), reviewer, reviewed_at, review_notes.

Data Layout

data/
  drop/        # scanner drop folder (watchdog)
  staging/     # temporary download area (SMB)
  processed/YYYY-MM/   # successful extractions
  Need-Train/           # 80-99% capture, for review/training
  failed/               # <80% capture or non-tax documents
  idin9_doc_ocr.db      # SQLite database

Development & Tests

pip install -e ".[dev]"
pytest

License

MIT

Available Tools

9 tools
ocr_batch_processC

Process all pending files in the drop/staging directory.

Inputs: folder_path.

ocr_extract_invoiceA

Extract a single PDF/image invoice and return structured JSON.

Inputs: file_path (required).

ocr_get_recordC

Retrieve a processed invoice record from the database.

Inputs: invoice_id, invoice_number.

ocr_list_recordsC

List invoice records with optional status filter.

Inputs: limit, status. Returns: result

ocr_manage_contactC

Perform CRUD operations on the contacts database.

Inputs: action (required), tax_id (required), company_name.

ocr_poll_scanner_shareB

Connect to the configured SMB scanner share, pull and process new files.

Inputs: no named parameters.

ocr_review_queueA

List low-confidence (need_train) records awaiting human confirmation.

Inputs: limit. Returns: result

ocr_review_recordB

Confirm (as success) or reject (as failed) a low-confidence record.

corrected is an optional JSON string of overridden fields (invoiceNumber, invoiceDate, currency, supplier_name, supplier_taxId, buyer_name, buyer_taxId, capture_rate).

Inputs: action (required), reviewer (required), invoice_id (required), notes, +1 more.

ocr_system_healthA

Report database status, SMB status, and queue depth.

Inputs: no named parameters.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 9 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes: extraction, batch processing, scanner polling, record retrieval, review, contact management, and health checks. The only slight overlap is between ocr_batch_process and ocr_poll_scanner_share, since both process files from directory-like sources.

    Naming Consistency4/5

    All tools share the ocr_ prefix and use snake_case, which creates a strong predictable pattern. However, ocr_batch_process and ocr_system_health deviate from the strict verb_noun structure used by most other tools.

    Tool Count5/5

    Nine tools is well-scoped for an OCR invoice processing server covering ingestion, extraction, retrieval, review, contacts, and system health. Each tool serves a meaningful part of the workflow without redundancy or bloat.

    Completeness4/5

    The toolset covers the main OCR invoice lifecycle: extract, batch process, poll scanner, retrieve/list records, review low-confidence results, manage contacts, and check health. Minor gaps exist, such as no direct update/delete for processed invoice records outside the review flow or explicit reprocessing of failed items.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Extract structured, schema-typed data from invoices, purchase orders, receipts, and tax forms, and classify documents into custom label sets — via a hosted MCP server. Free tier included.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Connects AI agents to ACCOS for OCR on Thai receipts, tax invoices, and withholding tax certificates via MCP.
      Apache 2.0
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables autonomous end-to-end SME loan underwriting through MCP microservices that handle email intake, document validation, KYC/AML screening, fraud detection, credit scoring, policy-based decisions, and automated Thai-language memo generation.
      -