bilan
# bilan
**Local-first, multi-currency Open Banking ledger & universal MCP server** for any AI agent: local coding harnesses (Antigravity, Claude Desktop, Claude Code, Codex, Cursor, Windsurf, OpenCode, Gemini CLI, VS Code, Zed, LM Studio) and remote/cloud agents or apps (Hark, Grokbot, ChatGPT, Claude web, OpenClaw, n8n, LangChain, custom apps).
Connect EU/EEA bank accounts for free via **Enable Banking (PSD2, Restricted Mode)** or import CSV statements for UK/US banks and brokers, organize accounts into **Personal** and **Business** workspaces (for example, a Romania SRL and a UK Ltd), and let your AI assistant analyze cashflow, track budgets, detect recurring subscriptions, and categorize transactions. Everything stays **strictly read-only and 100% local**.
## Highlights
- **Local Web UI & Setup Wizard (`bilan setup`):** Runs on `http://127.0.0.1:8788` with automatic local HTTPS OAuth callback handling on `https://localhost:8787/callback` or zero-warning GitHub Pages redirect (`https://razvangirgiz.github.io/bilan/callback.html`).
- **Universal Remote MCP Gateway (`bilan gateway`):** Isolated HTTP/SSE MCP server on `127.0.0.1:8789` (`/mcp` Streamable HTTP + `/sse` legacy SSE) with per-agent scoped Bearer API keys (`read_only` or `read_write`), optional entity lock (e.g., UK Ltd only), rate limiting, audit log, and 1-click Cloudflare HTTPS Tunnel for cloud agents (Hark, Grokbot, ChatGPT, Claude web, OpenClaw, n8n).
- **Personal & Business Entities:** Create separate workspaces with country, currency, tax ID, linked accounts, and agent context notes so your AI knows which accounts belong to Personal vs. each company.
- **Transactions Explorer & Rules Manager:** Filter by entity, account, category, direction, date range, and search query; triage uncategorized transactions inline; create literal auto-categorization rules and manage or delete rules in place.
- **Reports, Budgets & Exports:** Inspect monthly cashflow charts, entity comparisons, category/merchant rankings, recurring bills, and multi-currency budgets; export filtered CSV (with UTF-8 BOM and formula-injection neutralization) or Markdown reports.
- **Background Auto-Sync (`bilan schedule`):** Native macOS `launchd` LaunchAgent presets (`1x`, `2x`, `3x`, `4x` daily) that stay within PSD2 bank rate limits, plus cross-process SQLite sync locking.
- **True Multi-Currency FX:** Tracks accounts in `RON`, `EUR`, `GBP`, `USD`, `CHF`, `PLN`, and more, converting via **BNR XML** and **ECB Frankfurter** (including historical backfill on sync).
- **Strictly Read-Only & Local:** Zero payment scopes, `0700`/`0600` local file permissions, masked IBANs (`****1234`), DNS rebinding and CSRF protection, and prompt-injection hygiene. See [SECURITY.md](./SECURITY.md) and [BRAND.md](./BRAND.md).
---
## Quick Start
Requires **Node.js 22.13+** (uses built-in `node:sqlite`, zero native builds).
```bash
npm install
npm run build
npm run setup
```
*(Once published to npm: `npx bilan setup`. Config, secrets, logs, and SQLite default to `~/.bilan` or `BILAN_HOME`.)*
The browser opens **bilan** at `http://127.0.0.1:8788`:
1. **Key:** Drop your free Enable Banking `.pem` key (Application ID is extracted from the filename automatically).
2. **Banks:** Link EU/EEA banks (Revolut, ING, Banca Transilvania, Wise, BCR, Raiffeisen, N26, Bunq, etc.), import CSV statements, and optionally enable background auto-sync.
3. **AI apps:** Click **Install** next to any detected local MCP client, or use **Remote & cloud agents** to mint a scoped Bearer API key and start a 1-click Cloudflare HTTPS tunnel for cloud agents (Hark, Grokbot, ChatGPT, Claude web, OpenClaw, n8n, custom apps).
4. **Accounts, Transactions & Reports:** Review balances by entity, triage transactions, track budgets, and query your ledger directly from your AI assistant.
> Want to explore first without connecting a real bank? Click **Load demo** in **Accounts** (or run `bilan sync --demo`). Clear demo data anytime with **Clear demo** without touching real banks.
---
## CLI Commands
```bash
bilan setup # Open visual Web UI & Setup Wizard on http://127.0.0.1:8788
bilan gateway # Start isolated HTTP/SSE MCP Gateway on 127.0.0.1:8789
bilan gateway --tunnel # Expose MCP Gateway via Cloudflare HTTPS Tunnel
bilan gateway --create-key "Hark" --scope read_only --entity personal
bilan connect # Connect a bank interactively via Enable Banking PSD2 OAuth
bilan install # Auto-install MCP config into detected AI apps
bilan install claude-desktop # Install into a specific AI client
bilan sync # Sync all active banks (respects PSD2 rate limits & lock)
bilan sync --force # Force immediate sync
bilan sync --demo # Seed realistic multi-currency demo accounts
bilan sync --clear-demo # Remove only demo accounts, demo sync logs, and demo budgets
bilan schedule status # Inspect macOS LaunchAgent auto-sync status
bilan schedule enable 2x # Enable background auto-sync (1x | 2x | 3x | 4x daily)
bilan schedule disable # Disable background auto-sync
bilan # Start MCP stdio server
```
## MCP Tools
| Category | Tools |
|---|---|
| **Read & Analytics (Read-Only)** | `overview`, `list_accounts`, `transactions`, `cashflow`, `recurring`, `list_uncategorized`, `budget_status`, `sync_status` |
| **Entities, Budgets & Tagging (Local SQLite)** | `manage_entities`, `tag_transactions`, `manage_rules`, `manage_budgets`, `update_account` |
| **Sync, Onboarding & Import** | `list_supported_banks`, `start_bank_connect`, `complete_bank_connect`, `sync_now`, `import_csv`, `seed_demo_data`, `clear_demo_data` |
> For security, the MCP `import_csv` tool only reads `.csv`/`.tsv` files placed inside `<BILAN_HOME>/imports` (up to 5 MB). Web UI CSV imports are parsed strictly in memory.
## Remote & Cloud Agents (Streamable HTTP + SSE)
To connect cloud or external agents (Hark, Grokbot, ChatGPT, Claude web, OpenClaw, n8n, LangChain, custom apps):
1. Open **3. AI apps -> Remote & cloud agents** in `bilan setup` (or run `bilan gateway --tunnel`).
2. Click **New API key**, choose **Read-only** (recommended) and optionally lock the key to a single entity (e.g. `Personal` or `UK Ltd`).
3. Click **Start HTTPS tunnel** (uses `cloudflared` on isolated port `8789`, never exposing the Setup UI on `8788` or `.pem` keys).
4. Paste the `/mcp` URL (or `/sse` for legacy SSE clients) and `Authorization: Bearer bilan_sk_...` header into your agent:
```json
{
"mcpServers": {
"bilan": {
"url": "https://<your-tunnel>.trycloudflare.com/mcp",
"headers": {
"Authorization": "Bearer bilan_sk_..."
}
}
}
}
```
For a permanent custom domain instead of a quick tunnel URL, set `CLOUDFLARE_TUNNEL_TOKEN` (and optionally `CLOUDFLARE_TUNNEL_PUBLIC_URL`) in `.env`.
## Background Sync (Linux / Cron Alternative)
On macOS, use **Banks -> Background auto-sync** or `bilan schedule enable 2x`. On Linux or custom setups:
```bash
0 8,14,20 * * * /path/to/node /path/to/bilan/dist/src/index.js sync >> ~/.bilan/logs/autosync.log 2>&1
```
## License
MIT. See [LICENSE](./LICENSE).
TDQS
Scored across 20 tools
Most tools target a distinct resource or lifecycle stage (connect start/complete, sync status/trigger, seed/clear demo), but several overlap: overview bundles cashflow and budget status, manage_budgets vs budget_status differ only by verb, and list_uncategorized is essentially a filtered view of transactions. Descriptions do disambiguate these in practice, so misselection risk is low but non-zero.
The dominant convention is snake_case verb_noun (list_accounts, update_account, tag_transactions, manage_rules, import_csv, start_bank_connect), applied consistently across most tools. The deviations are the bare-noun analytics/query tools (overview, transactions, cashflow, recurring, budget_status), which are readable but break the pattern.
At 20 tools this is on the heavier side, but the surface spans genuinely separate concerns: bank connectivity/SCA, sync, accounts, transactions, rules, budgets, entities, analytics, and demo data. Each tool maps to a real user workflow, though a few (list_uncategorized, budget_status vs manage_budgets) could arguably be folded in.
The lifecycle is well covered: connect → sync → view/search → categorize → rule → budget → analyze, plus CSV import for uncovered institutions. Minor gaps remain: no way to revoke/delete a real bank connection, no manual transaction creation or deletion, and no export path.