This is the starting point if you want to build with Accounted rather than look at it from outside. It covers the stack, self-hosting, keys and scopes, the validation layer, and how MCP and REST relate. It assumes you've read The Accounting API for the AI Era.
The stack
Nothing exotic, on purpose. The interesting part of an accounting system should be the accounting.
┌──────────────────────────────────────────────────────┐
│ Clients (Web UI / Claude / Cursor / your backend) │
└──────────────────────────────────────────────────────┘
│ REST │ MCP
▼ ▼
┌──────────────────────────────────────────────────────┐
│ Next.js 16 route handlers (App Router) │
│ API-key scopes, OAuth 2.1, idempotency cache │
└──────────────────────────────────────────────────────┘
▼
┌──────────────────────────────────────────────────────┐
│ Deterministic validation layer │
│ Balance, BAS accounts, period state, Swedish VAT │
└──────────────────────────────────────────────────────┘
▼
┌──────────────────────────────────────────────────────┐
│ Postgres (Supabase): RLS, triggers, pg_cron │
└──────────────────────────────────────────────────────┘
Next.js 16, React 19 and Postgres via Supabase. Everything that writes goes through validation, and an append-only event log records what happened.
Self-hosting
You need Docker with Compose v2 and a Supabase project. The free tier works.
git clone https://github.com/erp-mafia/accounted.git
cd accounted
./docker/setup.sh
npm install -g supabase
supabase link --project-ref <your-project-ref>
supabase db push
setup.sh checks prerequisites, asks for your Supabase URL and keys, generates CRON_SECRET and writes .env. docker compose up -d then starts the app (ghcr.io/erp-mafia/gnubok:latest) and a cron sidecar.
The pg_cron migration needs a paid Supabase plan. On the free tier you skip it and the sidecar does the same work over HTTP. Configure your own SMTP provider too, since Supabase's built-in email is rate limited. The full guide is docs/SELF-HOSTING.md in the repo.
API keys and scopes
Keys are created at /settings/api, prefixed gnubok_sk_live_* or gnubok_sk_test_*. A test key forces every write into dry-run, but its reads return real company data. There is no separate sandbox.
Scopes are per capability. There is no admin scope that grants everything.
| Scope | Grants |
|---|---|
transactions:read | List transactions, template and category suggestions |
transactions:write | Categorise, receipt matching, invoice linking |
reports:read | Chart of accounts, ledgers, balance sheet, VAT, SIE |
bookkeeping:write | Close and lock periods, opening balances, SIE import |
pending_operations:approve | Approve or reject staged operations |
webhooks:manage | Manage webhook subscriptions |
A key created without explicit scopes gets a read-only default set. Built-in OAuth clients such as Claude and ChatGPT get every scope the user's role allows, and any row can be unticked on the consent screen.
A key holding both a staging scope and pending_operations:approve could stage a posting and commit it with nobody looking. That combination is blocked unless the user explicitly acknowledges it (acknowledge_sod: true), and the acknowledgement is stored on the key with who and when. For Claude and ChatGPT the consent click is that acknowledgement.
What the validation layer refuses
Every write is checked before anything commits.
- Total debits equal total credits.
- Every account exists in the chart of accounts.
- The target period is open. Locked periods reject writes.
- VAT treatment matches the account type.
- A repeated
Idempotency-Keyreplays the original response instead of booking twice.
Failures come back as one of 900+ structured error codes, each with a docs URL and, where there's a known fix, a recovery_hint. An agent that gets a recovery hint can usually fix its own call. Most write endpoints also take ?dry_run=true, but check each endpoint's docs rather than assuming.
Pending operations
Every MCP write that touches the books stages a pending operation. Abridged, for a categorised transaction:
{
"staged": true,
"operation_id": "7d2f0c4e-5b1a-4e8f-9c3d-2a6b8e1f4c90",
"risk_level": "low",
"preview": {
"debit_account": "6212",
"credit_account": "1930",
"amount": 499,
"currency": "SEK",
"date": "2026-04-14"
},
"approve": { "args": { "operation_id": "7d2f0c4e-…" } }
}
You approve in chat or at /pending. The risk level reflects what's at stake, so categorising a transaction is low while locking a period is not.
Staging is MCP-only. The REST endpoint POST /api/v1/companies/{companyId}/transactions/{id}/categorize books directly, so in your own backend code you own the review step. Agent auto-commit was removed in May 2026.
REST or MCP
Use REST for code you write, like scheduled jobs, webhook handlers and features in your product. Use MCP when an LLM is driving. Both hit the same validation layer and produce the same audit trail.
The MCP server has 200+ tools. Instead of memorising them, call gnubok_search_tools to find one by query, or gnubok_load_skill for step-by-step workflows like month-end close. For new installs use the accounted-mcp package; gnubok-mcp is the legacy name.
There are no official SDKs. The API is plain REST with an OpenAPI 3.1 spec at https://app.accounted.se/api/v1/openapi.json, plus llms.txt if you'd rather let a coding agent generate the client.
Where to go next
Mint a test key and connect Claude read-only to see what agent access to a ledger feels like. When you integrate, read the API documentation and start with GET /api/v1/companies. For the platform shape, including creating companies over the API, see Embedded accounting for SaaS. Bugs and ideas go in an issue on GitHub.
Frequently asked
- Why AGPL instead of MIT?
- Anyone who runs a modified version of the core as a service has to publish those changes under the same licence, so improvements to the ledger flow back. Extensions that only use the documented Extension API are exempt by an explicit exception in LICENSE. The MCP bridge packages are MIT, since they're glue rather than the ledger.
- What database does it need?
- Postgres, via Supabase. The schema, RLS policies, triggers and functions ship as ordered migrations in supabase/migrations. Some migrations need pgvector, btree_gist and pg_cron. There is no SQLite path.
- Can an agent book something without me?
- Only if you give it that right. Every MCP write that touches the books stages a pending operation, and booking it takes a separate approve call. A key holding both a staging scope and the approve scope is blocked unless you explicitly acknowledge the combination. A scheduled, unattended run can stage but never approve.
- How do I contribute?
- Open an issue on GitHub for bugs and feature requests, and open one before starting non-trivial work so we can agree on direction. Run npm test before sending a PR, and sign off every commit (DCO, git commit -s).