
Facturas Inbox Mcp
io.github.pedrozapatadevv0.1.0更新于 Oct 8, 2026
Spanish invoice PDFs to validated data: NIF/IVA/IRPF extraction, arithmetic checks, IVA per quarter.
概览
读取一个存放西班牙语发票 PDF 的文件夹,提取并校验发票字段,并计算季度 IVA 状况。
- 功能
- 这个本地 stdio 服务器会对文件夹中的每个 PDF 进行分类(factura、rectificativa、ticket、nómina、modelo AEAT),并提取发票字段,如 NIF/CIF、base imponible、各税率的 IVA、IRPF 和总额。它会校验 NIF/NIE/CIF 校验位,并以整数分为单位检查算术(base × rate、IRPF 预扣、base + VAT − IRPF = total)。工具包括 scan_folder、classify_document、extract_invoice、validate_tax_id、vat_summary 和 export_csv。未通过检查的单据会被排除在合计之外,并列出原因。
- 适用场景
- 适用于记账和 gestoría 工作:需要整理、核对并汇总一个月内收到的西班牙语业务单据。适合回答某份单据是什么、数字是否对得上,以及某季度的 IVA soportado 与 repercutido 状况。它是复核辅助工具,不是会计软件,也不能用于申报。
- 运行要求
- 通过 npx(npm 包 facturas-inbox-mcp)以 stdio 进程在本地运行,需要 Node.js 20.12 或更高版本。需要以参数形式或通过 FACTURAS_INBOX_DIRS 环境变量提供一个或多个文件夹路径;使用 --demo 参数可使用内置的合成收件箱。未声明需要 API 密钥或账户。PDF 需要有文本层,不含内置 OCR。
安装
在 SourceWeft 中
- 打开 控制台中的 Facturas Inbox Mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
facturas-inbox-mcp
[CI] [License: MIT] [MCP SDK v2] [Node ≥ 20.12]
An MCP server that turns a folder of Spanish business documents into validated, structured data an AI agent can reason over. It classifies each PDF (factura, rectificativa, ticket, nómina, modelo AEAT…), extracts the invoice fields (NIF/CIF, base imponible, IVA per rate, IRPF, total), checks the arithmetic and the tax-ID checksums, and computes the IVA soportado / repercutido position for a quarter.
Local and offline. No API keys. It reads only the folders you give it.
Built for the everyday job of a Spanish gestoría: a client drops a month of PDFs in a folder and someone has to work out what is what, what adds up and what the VAT position is.
30-second demo
Claude Code, Sonnet, pointed at the synthetic examples/inbox (11 documents,
including a wrong total, a ticket, a credit note, a payslip, a modelo 303 and a scanned page).
Real session; the answer is trimmed for length (full, unedited transcript in docs/demo-transcript.md):
5 turns · 23 s · $0.13. Every number comes from a tool result, not from the model doing arithmetic. Documents that fail a check are excluded and listed with a reason, so nothing is silently counted or silently dropped.
Tools
Every tool publishes an outputSchema and returns structuredContent, and the SDK validates both
directions. All tools set full annotations
(readOnlyHint, destructiveHint: false, idempotentHint, openWorldHint: false), so clients can
auto-approve the read-only ones.
The checks
extract_invoice returns status: "ok" only when every check passes:
All arithmetic is in integer cents.
Install
Requires Node.js 20.12 or newer.
Try it in 30 seconds (bundled sample data)
--demo serves the synthetic inbox that ships with the package. Then ask Claude:
"I'm the bookkeeper for CIF B87654323. What's our IVA position for Q3 2026, and what should I check
by hand?"
Claude Code
Claude Desktop
Add this to claude_desktop_config.json (Settings → Developer → Edit Config):
Any other MCP client
It's a standard stdio server: npx -y facturas-inbox-mcp <folder> [more folders…], or
npx -y facturas-inbox-mcp --demo. Folders can also come from FACTURAS_INBOX_DIRS (separated
like PATH).
From source, with the sample inbox
Then ask: "I'm the bookkeeper for CIF B87654323. What's our IVA position for Q3 2026?"
To poke at the tools without an LLM, run npm run inspect (MCP Inspector).
Design decisions
- Deterministic core, no model inside. The agent is already a language model. What it lacks are tools whose answers it can trust. Extraction is rule-based and every result carries its evidence: classifier signals, check details, warnings. The server can explain itself, and the same input always gives the same output.
- Fail loudly, not silently. Fields that weren't found are
null, not guessed. Documents that fail a check are excluded from totals and listed with the reason. Errors are returned asisErrorresults that say how to fix the call ("Passforce: trueto try anyway", "Run OCR first"). - Token-efficient.
scan_folderreturns compact rows and paginates.extract_invoiceis concise by default.export_csvreturns a path and counts, not the data. - Sandboxed filesystem. Paths are resolved with
realpathand must sit inside a folder given at startup, so../traversal and symlinks that point outside are rejected (and tested). The only write isexport_csv, which creates new.csvfiles and never overwrites. - Untrusted document text. The server instructions tell the agent never to follow instructions
found inside a document. Raw text is only returned on request, labelled
untrusted_text_preview. CSV cells that start with=,+,-or@are neutralized against spreadsheet formula injection. Exports are created0600. - Bounded work per document. Files are limited to 20 MB and PDFs to 200 pages. Text is cut at 1M characters before analysis. The extraction regexes are linear-time; a ReDoS case has a regression test.
- Threat model. The attacker controls document contents, not the filesystem. Paths that are missing and paths outside the folders get the same error, so the tool can't be used to probe what exists elsewhere. Someone who can already write to the inbox could race the check-then-read (a TOCTOU window); that is out of scope.
- stdout is the protocol. All logging goes to stderr. An end-to-end test drives the built binary
over real stdio, and it would fail on a stray
console.log.
Limitations
Honest scope. This is a showcase-sized tool, not accounting software.
- PDFs need a text layer. Scanned images are reported as
unreadablewith an OCR hint (e.g.ocrmypdf); there is no built-in OCR. - Heuristic extraction tuned to common Spanish invoice layouts (labelled fields like
Base imponible, IVA 21 %, Total factura). Unusual layouts come back as
needs_reviewrather than wrong. - Not handled yet: recargo de equivalencia, intra-EU / reverse-charge invoices, Facturae XML, and counterparty names (only tax IDs).
- Checksum validation only. A valid NIF is well-formed; it is not confirmed as registered with AEAT or VIES.
- Not an e-invoicing or VeriFactu tool. It reads received paperwork; it does not issue invoices
or file returns.
vat_summaryis a working figure for review, not a modelo 303.
Development
Built on the official MCP TypeScript SDK v2 (@modelcontextprotocol/server),
zod and unpdf.
Releasing
- Bump
versioninpackage.jsonand bothversionfields inserver.json. npm publish(runs build + tests first; needs npm 2FA).gh workflow run publish-mcp-registry.ymllists the new version in the MCP Registry via GitHub OIDC (no secrets).
Roadmap
- Optional OCR pass for scanned documents
- Counterparty names, recargo de equivalencia, intra-EU invoices
- Facturae XML input
- VIES lookup as an opt-in, clearly network-marked tool
- Streamable HTTP transport for remote deployment
License
MIT © 2026 Pedro Zapata Medal. All sample documents are synthetic: the companies, people and tax IDs are fictional.
来源:README.md,提交 d789988
工具
0版本历史
1- v0.1.0最新Oct 8, 2026


