Skip to main content
Glama

ReceiptBox — 付款前,让 AI 先审一遍票 · MCP Server + Web App

CI License: MIT Zero-dependency core

ReceiptBox is a functioning MCP server that audits invoices before you pay them. Four tools — extract_document, audit_document, risk_score, payment_link — exposed over three transports (stdio + Streamable HTTP spec 2025-11-25 + Gradio web app), plus a simulated Alexa+ experience that proves the loop.

Hackathons: Amazon Developer Hackathon (Alexa+ track + AWS Builder & Open Source mini challenges) · Hugging Face Gradio November Hackathon — Track 1 (MCP Servers).


Why

Every finance team pays invoices. Some of those invoices are wrong: the subtotal and tax don't add up to the total, the tax rate doesn't match the amount, the same invoice number appears twice (double-payment risk), the date is in the future. These are cheap to catch and expensive to miss.

ReceiptBox catches them with evidence — every finding names the exact fields and numbers it was derived from. Nothing is a black box, and nothing is ever fabricated: a field that can't be extracted stays empty.

Related MCP server: invoice-intake

The four MCP tools

Tool

Input

Output

extract_document

messy invoice/receipt text

structured fields (vendor, no, dates, currency, subtotal, tax, total, status)

audit_document

KEY:VALUE blocks (--- separated) or messy text

7 risk-rule findings + score + band, each with evidence

risk_score

single invoice text

score 0–100, band, summary, top findings

payment_link

invoice text or explicit fields

PayPal collection link (live Orders with credentials, labelled demo link otherwise)

Risk rules: TOTAL_MISMATCH (subtotal + tax ≠ total), TAX_MISMATCH (declared rate vs implied), DUPLICATE (same vendor+no / vendor+amount+date — the double-payment killer), MISSING_FIELD, FUTURE_DATE, STALE_UNPAID, ROUND_AMOUNT.

Three transports, one brain

                     ┌──────────────────────────────┐
   MCP host ──stdio──▶  receiptbox.mcp_server        │
 (Claude Desktop,     │  zero-dependency JSON-RPC   │
  Cline, any agent)   │  2.0 over stdio             │
                     └──────────────┬───────────────┘
                                    │ same tool layer
                     ┌──────────────▼───────────────┐
   MCP host ──HTTP──▶  receiptbox.http_mcp (:7861)   │
 (Alexa+, any host)   │  Streamable HTTP, spec      │
                     │  2025-11-25 + sessions       │
                     └──────────────┬───────────────┘
                                    │ same tool layer
                     ┌──────────────▼──────────────┐
   Human ──browser──▶  Gradio app (app.py)          │
                     │  4 tool tabs + JSON-RPC tab │
                     └──────────────────────────────┘
                     ┌──────────────────────────────┐
   "Alexa, …" ──────▶  alexa_sim.py (:7862)         │
                     │  simulated Alexa+ experience │
                     │  live MCP calls, spoken     │
                     │  reply + receipt card       │
                     └──────────────────────────────┘

The protocol layers (mcp_server.py stdio, http_mcp.py Streamable HTTP) and the web layers (app.py, alexa_sim.py) all call the same pure functions in receiptbox/tools.py — what an agent gets over the wire is exactly what a human gets in the browser.

Alexa+ track: self-hosted MCP server (spec 2025-11-25)

python -m receiptbox.http_mcp --port 7861     # Streamable HTTP + Mcp-Session-Id
PORT=7862 python alexa_sim.py                 # simulated Alexa+ experience

The HTTP server implements the Streamable HTTP transport with zero dependencies: single POST endpoint, SSE-framed responses (event: message), server-assigned Mcp-Session-Id, initialize version negotiation (client-requested version if supported, else latest), 202 Accepted for notifications, DELETE to terminate a session, 405 for GET. alexa_sim.py then runs the full agent loop against it — PERCEIVE → PLAN → MCP tools/call → EXPLAIN → RECEIPT — with every call visible on screen, and an automatic in-process fallback if the server is unreachable (labelled offline, the demo never dies).

Three extraction brains (priority: Bedrock → LLM → offline)

Brain

Needs

Notes

aws_brain.BedrockExtractor

AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY

Bedrock Converse API, hand-written SigV4 (stdlib hmac/sha256)

extract.LLMExtractor

RECEIPTBOX_LLM_BASE/RECEIPTBOX_LLM_KEY

any OpenAI-compatible endpoint

extract.OfflineExtractor

nothing

deterministic regex engine, always available

Quick start

1. As an MCP server (stdio) — e.g. Claude Desktop

{
  "mcpServers": {
    "receiptbox": {
      "command": "python",
      "args": ["-m", "receiptbox.mcp_server"],
      "cwd": "/path/to/receiptbox"
    }
  }
}

Then ask: "Audit this invoice: Subtotal 8800, Tax 500, Total 9300" → TOTAL_MISMATCH with evidence subtotal=8800.0 tax=500.0 total=9300.0.

2. As an MCP server (Streamable HTTP) + web app

pip install -r requirements.txt
python app.py          # http://localhost:7860  ·  MCP at /gradio_api/mcp/

Connect any MCP client to http://localhost:7860/gradio_api/mcp/. The JSON-RPC tab in the UI lets you speak the protocol by hand — no client needed:

{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}

3. As a library

from receiptbox import audit_document
print(audit_document(open("invoice.txt").read()))

Design principles

  1. Evidence or it didn't happen. Every finding carries the fields and numbers behind it. The score formula is min(100, HIGH*30 + CAUTION*10) — published, reproducible, arguable.

  2. Never fabricate. The extractor returns empty for fields it can't find. A missing total produces a MISSING_FIELD caution, not an invented number.

  3. Dual brain, graceful degradation. Offline regex brain (zero-dependency, deterministic, always available) + optional OpenAI-compatible LLM brain for messy OCR text. Set RECEIPTBOX_LLM_BASE/KEY/MODEL to upgrade; unset it and nothing breaks.

  4. Zero-dependency core. pip install nothing: the protocol, extractor, auditor and receipt renderer are pure stdlib. Gradio is only the web shell.

  5. Payments are real when credentials are real. payment_link creates a genuine PayPal Orders v2 order with sandbox credentials; without them it returns a clearly-labelled demo deep-link — never a fake "live" link.

Testing

python eval.py

68 assertions, all offline, covering: extractor field/guards/edges, the 7 risk rules + scoring, in-process JSON-RPC (initialize / tools/list / tools/call / notifications / error paths), a real subprocess stdio session (initialize → notifications/initialized → tools/list → tools/call ×2 → stdin EOF → clean exit 0), a real Streamable HTTP server + client session (spec 2025-11-25: session id, version negotiation, SSE framing, 202 notifications, unknown-tool error path), SigV4 signing (determinism

  • header construction + brain-selection chain), and the Alexa+ simulator loop (e2e over real MCP + offline fallback). The same tool layer is additionally exercised through the official mcp Python SDK against the Gradio HTTP endpoint during development.

Repository layout

receiptbox/
  models.py       Invoice / Finding / Report dataclasses (to_dict for wire)
  extract.py      dual-brain extractor: OfflineExtractor + LLMExtractor
  aws_brain.py    Bedrock Converse extractor with hand-written SigV4 (stdlib)
  audit.py        7 risk rules + scoring (transparent, evidence-first)
  paylink.py      PayPal Orders v2 (live) / demo deep-link (fallback)
  tools.py        the 4 tool functions — shared by protocol and web layers
  mcp_server.py   zero-dependency JSON-RPC 2.0 MCP server (stdio)
  http_mcp.py     zero-dependency MCP server, Streamable HTTP, spec 2025-11-25
  mcp_client.py   zero-dependency Streamable HTTP client (stdlib)
app.py            Gradio app: 4 tool tabs + JSON-RPC passthrough, mcp_server=True
alexa_sim.py      simulated Alexa+ experience: live MCP calls + spoken reply
eval.py           68 offline assertions
examples/         sample invoices (messy + structured) + SDK client demo
AMAZON_SUBMISSION.md   Devpost text for the Amazon hackathon
FEEDBACK.md           product feedback (Alexa+/MCP, Bedrock, GitHub)

Configuration

Variable

Effect

RECEIPTBOX_LLM_BASE / RECEIPTBOX_LLM_KEY / RECEIPTBOX_LLM_MODEL

enable the LLM extraction brain

RECEIPTBOX_PAYPAL_CLIENT_ID / RECEIPTBOX_PAYPAL_SECRET

enable live PayPal order creation

License

MIT — see LICENSE.


💝 赞助 / 打赏

如果这个项目对你有帮助,欢迎通过 爱发电 请我喝杯咖啡 ☕
👉 https://afdian.com/a/Zhiyilang

GitHub Sponsors 在中国大陆暂不支持个人账号,赞助统一走爱发电。


💝 赞助 / 支持

如果这个项目对你有帮助,欢迎到 爱发电 请我喝杯咖啡 ☕ 你的支持是我持续维护开源、做更多实用工具的动力。

。

Related MCP Connectors

  • Create, send and track invoices from a conversation in Claude, ChatGPT or any MCP client that supports OAuth. Draft an invoice from one sentence or from last month's invoice for the same client, finalize it, email it to your client and send payment reminders for overdue ones. See revenue by month and by client, download PDFs and e-invoices (ZUGFeRD, XRechnung), and export DATEV packages for your tax advisor. Invoices follow the tax rules of 25 countries, including reverse charge and the small-business VAT exemption. New invoices are drafts, and nothing is emailed until you ask. Pay per invoice with no subscription: the first invoice is free.

    https://billstride.com/api/mcp
  • Verify before the agent pays. Screwtape is an independent check on agent work before a payment goes out: invoices, duplicate invoices and reconciliation, with a signed receipt for your auditor. It is independent of your agent's own model and vendor, with no stake in your agent passing. - judge: pass, fail or retry verdict on one agent output, with a score, reasons and a next_step. Optional deterministic checks: required fields, types, formats, sums, regex. - check_duplicate_invoice (/v1/duplicate): opt-in duplicate-invoice check using keyed fingerprints. - consensus: scores agreement across 2 to 16 agent answers and flags false consensus. - Advisory mode: recommends approve, review or return; a person decides. - Receipts: Ed25519-signed. The receipt proves what was checked, when, and the verdict. Verify via POST /v1/receipts/verify or offline; export via GET /v1/receipts/export. - Judged content isn't stored unless you opt in. Free key: 100 calls/day. Or $0.005 USDC per call via x402 on Base or Solana, no key needed. MCP: https://screwtape.ai/mcp Docs: https://screwtape.ai/docs/ Icon: https://screwtape.ai/icon-512.png Tags: verification, evaluation, llm-as-judge, invoices, receipts, x402

    https://screwtape.ai/mcp
  • Reads invoices and receipts from PDF to JSON and checks the math. $0.04/page via x402.

    https://subpay.ai/invoice/mcp
  • Documents 1.4.2: five focused MCP tools. analyze_receipt extracts caller-supplied receipt text or checks supported fields (0.25 USDC). match_invoice allocates invoice quantities against a purchase order, including split lines and remaining quantities (0.50 USDC). reconcile_purchase_documents is the free choice for discrepancies across supplied receipt, invoice and PO fields; missing documents remain needs_review and split links are flagged rather than allocated. Neither comparison requires the other. Consolidated example and status tools are free. Paid calls require buyer-authorized x402 on Base. Human review required; no image OCR, stored-analysis retrieval, delivery certification, payment approval or accounting writes. Service-specific cache and payment-metadata terms are disclosed through status. Runtime utilities: https://agents.getardaro.com/mcp/utilities . Legacy /mcp remains compatible. Guide: https://agents.getardaro.com/document-review

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables accounts payable teams to extract invoice data from PDFs and images, detect duplicates, normalize vendor names, calculate payment terms, and validate invoice completeness. Supports local extraction for text PDFs and optional vision providers for scanned documents.
    -
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables accounts-payable teams to turn emailed or uploaded invoice PDFs into structured, source-cited fields via Claude, run deterministic arithmetic, date, PO and duplicate checks, and route each invoice to a named human for approval or rejection through scoped bearer tokens. Also supports listing pending approvals and forecasting what falls due in the coming weeks, with per-extraction cost tracking.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables parsing of structured receipts, invoices, and bank statements and tolerance-based three-way reconciliation that detects tax calculation drift and duplicate claims, then synthesizes balanced double-entry bookkeeping journal entries. Exposes these capabilities as MCP tools (initialize, tools/list, tools/call) over a dependency-free JSON-RPC 2.0 stdio server.
    7
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI assistants to read, validate against the official KoSIT rules (no Java), create, and display XRechnung and ZUGFeRD e-invoices, and export incoming invoices as DATEV posting batches. Running it with a cloud language model sends invoice contents to that provider's service.
    MIT