invoices-mcp
Optional read-only integration that fetches new invoice attachments from Gmail into the local invoice folder via sync_gmail_invoices, allowing emailed CSV/PDF invoices to be parsed and analyzed locally.
Optional read-only integration that copies new invoice files from a configured Google Drive folder into the local invoice folder via sync_drive_invoices, allowing Drive-stored CSV/PDF invoices to be parsed and analyzed locally.
Enables parsing and querying Nubank CSV invoice and account-statement files, including card invoices, transactions, categories, installments, and card-bill payments. Supports tools for invoice listing, spending summaries, transaction search, monthly totals, month comparison, and recurring charge detection.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@invoices-mcp what did I spend on food in September?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
invoices-mcp
A small MCP server that lets an AI agent answer questions about your own bank invoices — "what did I spend on food in September?", "which subscriptions am I paying for?", "what changed between August and September?" — without your financial data going anywhere you didn't choose.
You drop invoice files in a folder. The server works out which bank each file is from, reads it with that bank's parser, and gives the agent a handful of narrow, read-only tools.
Supported banks
Bank | Files | What is read |
Nubank | CSV | Card invoice ( |
Itaú | Credit-card statement (Fatura): purchases, installments, cancellations, international purchases (with conversion rate), IOF and payments |
More banks are planned but not built yet. A file from any other bank is not guessed at: it is reported as skipped, with the list of supported banks, by list_invoices. See Adding a bank.
Free. No service to pay for, no account of ours, no API key.
Private by default. It reads files from one folder you choose. In its default mode it makes no network requests and never writes to disk. This is enforced by tests, not just promised (see Privacy).
Checks its own work. Where a statement prints its own total, the server compares it with the sum of the lines it parsed and says so (
check.matchesStatement), instead of silently trusting a regular expression.Optional Gmail and Google Drive. If invoices reach you by e-mail, or live in a Drive folder, the server can fetch them for you — read-only, off unless you turn it on. See Gmail and Drive.
Status: v0.4. Nubank is verified on a real mailbox. Itaú is verified on three real statements (every one adds up to its printed total) plus synthetic ones, including the PDF text-extraction path; run
list_invoiceson your own statement and look atcheckto confirm it adds up. If your files look different, see what to do.
Related MCP server: LedgerLens
How it works
your files ─────────────▶ a folder ◀──read-only── invoices-mcp ◀──MCP (stdio)── your AI agent
(Nubank CSV, Itaú PDF) ▲ │
└── optional: new files ┴── Gmail / one Drive folder (read-only)For each file the server extracts its text (PDFs are read in-process, no external program), asks each bank parser "is this yours?", and parses it with the one that says yes. The agent never gets a file path and never gets raw access to the files: it calls narrow tools and receives JSON.
Tools
Tool | What it answers |
| Which banks and formats are supported |
| Files found: bank, month, due date, transaction count, totals, and whether the parsed lines match the statement's own total. Unreadable files are listed under |
| Totals, spend by bank and category, top merchants, largest purchases (filter by bank, invoice, dates, category) |
| Find transactions by text, bank, date range, category or amount (newest first, max 200 rows) |
| Spend, refunds and payments per month, optionally for one bank or category |
| What changed between two months, by category, biggest change first |
| Likely subscriptions: same merchant, similar amount (±5%), about once a month |
| Only when Gmail is configured. Download new invoice attachments into the folder |
| Only when a Drive folder is configured. Copy new invoice files from that one folder into the local folder |
Every analysis tool takes an optional bank filter (nubank, itau).
What "spend" means
All amounts are in BRL. Amounts are handled as integer cents, so totals never pick up floating-point noise.
Term | Meaning |
| Purchases and fees (money out), before refunds |
| Cancellations and refunds (money back) |
| Card-bill settlements: the payment shown on a card invoice, and the matching "pay the bill" outflow on an account statement. Never counted as spending, so paying a card from your account is not double-counted |
|
|
Categories and merchants in summaries are net of refunds. Itaú's own category labels are normalised (HEALTH → saúde, SUPERMARKET → supermercado); international purchases are international, and the IOF charged on them is fees.
Quick start
Requires Node.js 20 or newer.
git clone <this repo>
cd invoices-mcp
npm install
npm run buildPut your invoice files in a folder, for example
C:\Users\you\Documents\invoices— Nubank CSVs and Itaú PDFs can sit side by side.Try it on the included fake data first (one Itaú PDF and four Nubank CSVs):
node dist/index.js --dir sampleConnect it to an agent
Claude Code — either run
claude mcp add invoices -- node /path/to/invoices-mcp/dist/index.js --dir /path/to/invoicesor put this in a project's .mcp.json. Claude Desktop uses the same block in claude_desktop_config.json:
{
"mcpServers": {
"invoices": {
"command": "node",
"args": ["C:/path/to/invoices-mcp/dist/index.js", "--dir", "C:/Users/you/Documents/invoices"]
}
}
}You can also set the folder with the INVOICES_DIR environment variable instead of --dir.
Things to ask
"List my invoices and tell me if any of them don't add up."
"Summarise my spending for September. What are my top three categories?"
"Which subscriptions am I paying for, and what do they cost per year?"
"Compare August and September on the Itaú card. What went up the most?"
"Find every purchase over R$ 150 this quarter."
Supported formats in detail
Nubank (CSV)
The layout is detected from the header row; comma or semicolon delimiters both work, as do 1.234,56 and 1,234.56 style amounts and ISO or dd/mm/yyyy dates.
Layout | Header | Notes |
Card invoice |
| Purchases are positive; the payment received is negative and tagged |
Account statement |
| Negative |
Itaú (PDF)
The PDF's text is read and flattened (so differences in line breaks between PDF readers don't matter), then:
the due date (
Vencimento) fixes the year of every row, since rows only printDD/MM; a December purchase on a January statement becomes last year;purchases are read as date, merchant, optional installment
NN/NN, amount, with the category and city printed underneath each row;cancellations (
CANCELAMENTO DE COMPRA) are negative and net against the purchase;international purchases are read with their original amount and currency; the R$ figure is identified by checking which printed amount equals another times the printed Dólar de Conversão rate;
the IOF passed on for international purchases is a
feesline, because it is part of the invoice total;the "Compras parceladas – próximas faturas" section (future installments) is ignored: it is not charged on this invoice;
repeated page headers,
continua...markers and stray page numbers are discarded;card numbers, cardholder names and addresses are never copied into the result.
Self-check. The parsed lines are compared with the statement's card subtotal, its international total and its Total dos lançamentos atuais. Any difference becomes a warning, and list_invoices shows check: { statementTotalBRL, parsedTotalBRL, matchesStatement }. If it says false, a line was missed or misread — don't trust that invoice's numbers until it's looked at.
Damaged text layers. Some statements come out of the PDF with stray spaces inside words and numbers (6.634 ,53, 128,5 0, 04/ 08) and with the two columns interleaved. The parser repairs number-shaped damage and matches section headings loosely, but merchant names stay as printed (REST AUR ANT E), categories are not read for such statements (they are uncategorized), and the result carries a warning saying so. It is accepted only because the lines still add up to the printed total; a statement it cannot read, or whose total it cannot find, is rejected rather than guessed at.
Password-protected PDFs. If your statements need a password, set INVOICES_PDF_PASSWORD. It is used only to open the file and is never stored or logged.
If a file does not parse
list_invoices reports skipped files with a reason, and check flags statements whose lines don't add up. If your file uses a different layout, open an issue describing it without including transactions or personal data (for a CSV, only the header line; for a PDF, which section looks different).
Optional: fetch invoices from Gmail or Google Drive
Both are off by default, share one sign-in, and can be used together. Use Gmail if invoices reach you by e-mail (an exported CSV you forward to yourself, or a PDF statement a bank sends). Use Drive if you keep invoice files in a Drive folder. Each adds one tool — sync_gmail_invoices, sync_drive_invoices — that copies new CSV and PDF files into the invoice folder; everything after that, parsing and analysis, is the same local code.
One-time setup (about 10 minutes)
In Google Cloud Console create a project and enable the Gmail API and/or the Google Drive API (whichever you will use).
Configure the OAuth consent screen (External) and add your own Google account as a test user (without this Google answers
403 access_denied).Create credentials → OAuth client ID → application type Desktop app, and download the JSON. Keep it somewhere outside this project.
Authorise once. This prints a URL; open it and approve read-only access. Say which sources you want:
node dist/index.js auth --google-credentials /path/to/client.json --scopes gmail,drive(
--scopes gmail,--scopes driveor--scopes gmail,drive; the default isgmail.) To add Drive later, run it again with the scopes you want.Tell the server what to read, in your MCP configuration:
"args": ["C:/path/to/invoices-mcp/dist/index.js", "--dir", "C:/Users/you/Documents/invoices", "--google-credentials", "C:/path/to/client.json", "--gmail-query", "label:invoices", "--drive-folder", "https://drive.google.com/drive/folders/<folder id>"]Use either option or both. The environment variables are
INVOICES_GOOGLE_CREDENTIALS,INVOICES_GMAIL_QUERYandINVOICES_DRIVE_FOLDER. Then ask your agent: "Fetch new invoices from Drive and Gmail, then summarise this month."
How the access is kept narrow
The source is yours, not the agent's. The Gmail search and the Drive folder are fixed when the server starts. The Gmail query must contain
from:,label:orsubject:; the Drive folder must be a plain folder id or folder link (anything that could alter the Drive search is refused at startup). The tools' only parameter is a count (how many recent messages or files to look at). A prompt-injected agent cannot widen the search or point the server at another folder.Drive: one folder, no subfolders. Only files listed directly in that folder are considered, and each file must report that folder as its parent. Folders, Google Docs and Google Sheets are not downloaded.
CSV and PDF only. Gmail always appends
has:attachment (filename:csv OR filename:pdf); Drive considers only.csv/.pdffiles. Images, documents and everything else are never downloaded.Only real bank invoices are kept. Every file must be recognised and read by one of the bank parsers; anything else is discarded without being saved.
Gmail: email text is never read. Only the attachment structure is requested, not message bodies.
One safe-save routine for every source (
src/google/save.ts): files are renamed from safe characters only (gmail-<id>-<name>,drive-<id>-<name>), so../../x.csvcannot leave the folder; an existing file is never overwritten or downloaded again; files are capped at 5 MB and 50 per run.Read-only scopes (
gmail.readonly,drive.readonly). The Gmail and Drive clients send nothing butGETrequests, so nothing in your mailbox or your Drive can be changed, moved, shared or trashed; tests fail if that ever stops being true.Network limited to Google. Sign-in and API calls go only to
accounts.google.com,oauth2.googleapis.com,gmail.googleapis.comandwww.googleapis.com/drive/v3/files(plus a loopback address for the sign-in redirect). A test fails if any other host appears.Tokens. Only a refresh token is stored, at
~/.invoices-mcp/google-token.json(override withINVOICES_GOOGLE_TOKEN). Access tokens live in memory. The OAuth flow uses PKCE and checksstate, and the credentials file is rejected if its token endpoint isn't Google's. Before each sync the server checks that the saved token actually includes the needed scope and says how to add it if not.
Honest limits of the Google options
The permissions are broader than what the code does. Google offers no narrower scope that can read Gmail attachments or the contents of an arbitrary Drive folder. So the token can technically read your whole mailbox (
gmail.readonly) and every file in your Drive (drive.readonly). This server only runs the search and folder you configured, but the credential itself is powerful. Consider a dedicated Google account for invoices, keep the token file private, and know how to revoke access: https://myaccount.google.com/permissions.Tokens expire weekly in "Testing" mode. While your OAuth app is unverified, Google expires refresh tokens after 7 days; re-run
authwhen the tool says so.Drive: subfolders are not read; a file you later edit in Drive is not downloaded again (a new file name or a deleted local copy is); Google Sheets are not read (export one as CSV first).
Downloaded files are real financial data sitting in your folder. Protect it like any bank statement.
Some banks protect PDF statements with a password; set
INVOICES_PDF_PASSWORDso they can be validated and saved.
Privacy
Two modes, stated plainly:
Default (no Gmail options)
Reads only
*.csvand*.pdffiles directly inside the configured folder (no recursion). A file whose real path leaves the folder, such as a symlink, is skipped.Read-only. No code path writes, renames or deletes files.
No network access and no child processes. PDFs are read in-process. The transport is stdio only. The Gmail code is not even loaded.
Nothing is logged: transaction contents are never written to stdout or stderr (stdout carries the MCP protocol).
File size is capped at 10 MB and file count at 500.
With Gmail and/or Drive enabled
Everything above still holds for the parsing and analysis code. The only code allowed to use the network or write files lives in
src/google/, and only thesync_gmail_invoicesandsync_drive_invoicestools reach it.
test/privacy.test.ts turns this into a build failure: outside src/google/ no source may import a network or process module, call fetch, or write a file; the Google modules may only mention Google hosts, may only request the two read-only scopes, may not reference mutating endpoints, and the Gmail and Drive clients may send nothing but GET requests; nothing may log through console; and no status line may interpolate a token or transaction contents. .gitignore excludes every *.csv and *.pdf except the fake files in sample/, so you can't commit your real data by accident.
One more honest limit: the agent you connect decides what happens to the answers. If the host sends tool results to a cloud model, those results (for example, a list of your transactions) go to that model's provider. This server keeps the files local; it can't control what a connected model does with what it is shown. For fully local use, connect it to a local model.
Adding a bank
The design keeps this small. A bank is one file that answers two questions about a file's text — is this yours? and what are the transactions? — plus one line in a list.
Add the bank's id to
BankIdinsrc/types.ts.Write
src/banks/<bank>.tsexporting aBankParser(detectandparse, both plain functions of the file's text; throwBankFormatErrorwhen a recognised file can't be read). Return amounts as integer cents, positive for money out, negative for money back, and tag card-bill settlementspayment.Add it to
PARSERSinsrc/banks/index.ts.Add a synthetic fixture and tests. Never commit a real statement.
Nothing else changes: the store, every tool, the Gmail sync and the privacy tests all go through the same ingest() path. If the bank prints totals, reconcile against them as the Itaú parser does.
Development
npm test # parsers, analytics, file loading, Gmail (against fakes), privacy rules, and end-to-end MCP sessions
npm run typecheck
npm run dev -- --dir sampleThe end-to-end test starts the real server over stdio and talks to it with the official MCP client, the same way an agent host would. PDF tests build real PDF files from fake statement text, so the extraction path is exercised too. One test (symlink escape) is skipped on systems that don't allow creating symlinks, such as Windows without developer mode.
src/types.ts shared types: Transaction, BankParser, ParseResult
src/parse.ts bank-neutral helpers: CSV, dates, money (integer cents)
src/banks/ one module per bank + the registry (nubank.ts, itau.ts, index.ts)
src/pdf.ts in-process PDF text extraction
src/ingest.ts bytes -> text -> the parser that recognises it
src/store.ts read-only loader: top-level .csv/.pdf only, path-escape guard, mtime cache
src/analytics.ts summaries, month comparison, recurring-charge detection (pure functions)
src/server.ts MCP tool definitions
src/index.ts stdio entry point and CLI (including `auth`)
src/google/ optional Gmail and Drive: shared OAuth (auth.ts), REST clients and syncs
(gmail-api.ts, gmail-sync.ts, drive-api.ts, drive-sync.ts), one safe-save routine (save.ts)
sample/ synthetic invoices (not real data)Known limitations
Recurring-charge detection is heuristic: one charge a month within ±5%. It misses subscriptions whose price changed and may flag a habit that happens to be regular.
Categories are whatever the bank printed; Nubank's e-mailed card CSV has none, so those rows are
uncategorized.Only BRL totals; foreign-currency purchases are kept in BRL with the original amount shown.
Emailed Nubank statements are named after the invoice due date, so an invoice holds the previous month's purchases. Invoice
monthfollows the due date;monthly_totalsandcompare_monthsgroup by transaction date, so the two views can differ.Itaú statements with several cards (additional cardholders) are read as one invoice; per-card breakdown is not exposed.
Built for personal use on a handful of files, not as a financial-reporting tool.
Built with AI assistance
Most of the code, tests and documentation in this repository were written by an AI assistant (Claude Code, by Anthropic), working from my requirements and constraints: read-only access, financial data stays local, the agent cannot change which mailbox query or Drive folder is read, and every parse must reconcile with the totals printed on the statement. I directed the design, supplied the real statements and accounts it was tested against, and ran it. Nubank and Itaú parsing was checked against my own real files (every Itaú statement adds up to its printed total), but that is a handful of files from one person, so treat it as unreviewed software: read the code, and check list_invoices's check field against your own statements before relying on any number.
License
MIT
Available Tools
7 toolscompare_monthsCompare two monthsARead-onlyIdempotent
Compare spending by category between two calendar months and show what changed most. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: month_a (required), month_b (required), bank.
find_recurring_chargesFind recurring chargesARead-onlyIdempotent
Detect likely subscriptions: the same merchant charged a similar amount (within 5%), about once a month, in several different months. Installment purchases are ignored. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: bank, min_months.
list_banksList supported banksARead-onlyIdempotent
Which banks and file formats this server can read. Files from other banks are not supported yet and are reported as skipped by list_invoices.
Inputs: no named parameters.
list_invoicesList invoicesARead-onlyIdempotent
List the invoice files that were found: bank, month, type (card or account), due date, transaction count and spend. Where a statement prints its own total, check says whether the parsed lines add up to it. Files that could not be read are listed under skippedFiles. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: bank.
monthly_totalsMonthly totalsARead-onlyIdempotent
Spend and credits per calendar month, optionally for one bank or category. Months come from transaction dates. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: bank, category.
search_transactionsSearch transactionsARead-onlyIdempotent
Find individual transactions by text, bank, date range, category or amount, newest first. min_amount and max_amount compare the absolute amount in BRL. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: to, bank, from, limit, +5 more.
spending_summarySpending summaryARead-onlyIdempotent
Totals, spend by bank and category, top merchants and largest purchases. Optionally narrow by bank, invoice, date range or category. Amounts are in BRL. A positive amount is money leaving the account or card (a purchase or fee); refunds, card payments and deposits are reported separately as credits.
Inputs: to, bank, from, invoice, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Most tools have clearly distinct purposes: list_banks vs list_invoices separate source banks from statement files, search_transactions is item-level, compare_months and find_recurring_charges are specific analyses. spending_summary and monthly_totals overlap somewhat since both produce aggregated totals, but the monthly and category/bank breakdowns help differentiate them.
All names use consistent snake_case, which is good. However, the verb-first convention (list_, search_, compare_, find_) is broken by two noun-phrase names (spending_summary, monthly_totals), a minor deviation that is still readable.
Seven tools sit squarely in the well-scoped range for an invoice-analysis server. Each tool covers a distinct analytic need (inventory, totals, trends, search, comparison, recurring detection) with no redundant entries.
The read-only analysis surface is well covered: discovery, summaries, monthly trends, search, comparison, and recurring-charge detection. Minor gaps remain, such as per-transaction drill-down detail or category management, but these are workable given the apparent read-only scope.
Related MCP Connectors
Ask your AI about Brazilian bank spending. Read-only bank access, never moves money. Paid plan.
Convert bank statements to CSV or JSON from your AI assistant. See the cost, then approve.
Turn bank statement PDFs, CSVs, XLSX and OFX into categorised transactions plus a summary.
Turn bank statement PDFs into categorized, balance-checked transactions and reports.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables personal expense management through CSV storage, allowing AI agents to add, query, and analyze expenses with automatic categorization and payment method validation.-
- AlicenseNot gradedqualityBmaintenanceEnables querying your own local bank and credit card statement files (CSV or PDF) in plain language, so you can discover forgotten recurring subscriptions, compare spending across months and quarters, and look up transactions without any bank logins or network calls.MIT
- AlicenseBqualityBmaintenanceEnables AI assistants to analyze a local bank statement CSV through seven tools covering spending by category, top merchants, recurring subscriptions, unusual or duplicate charges, end-of-month forecasts, and transaction search, plus a monthly review prompt. CSV files stay on the user's machine, with only aggregated results and matched transactions exposed to the assistant.7MIT
- FlicenseNot gradedqualityNot gradedmaintenanceEnables an AI agent to answer questions about real spending from Brazilian bank accounts connected via Open Finance, with read-only access to accounts, cards, transactions, spending summaries, and recurring charges. Limited write actions only manage categories and sync requests within the service.-