Files
KomediruzeckiandGitHub b7187420a5 feat(mcp): account MCP server and bearer-authed import API (#497)
Adds a remote MCP server at POST /mcp and a bearer-authed account API, so an
agent can read the account, import statements and write back categorizations
without a browser session.

- 15 tools across read / write / import scopes; stateless streamable-HTTP
  JSON-RPC. Tokens are tc_pat_-prefixed and stored as a SHA-256 hash
  (migration 0027).
- Auth is an allow-list, not a widening of authenticateRequest: a bearer token
  reaches /mcp and /api/v1/* and nothing else, with a regression test pinning
  401 on the cookie-authed routes.
- File bytes never travel through a tool argument. prepare_import returns a
  15-minute HMAC-signed, purpose-bound capability URL and the bytes go over
  plain HTTP; export_snapshot does the same in reverse.
- POST /api/v1/import runs the bank adapters before falling back to generic
  CSV, so the API accepts the files the Bank Imports tab accepts. The
  detection/parse core moved to shared/bankImport/ for this; its 42-name public
  surface is unchanged and 14 of the 20 moved files are byte-identical in logic.

Verified against a real 94-row Erste statement locally: parsed by the erste
adapter at 0.97 confidence, 100% date and amount parse rates, account created
and linked, re-import deduped to 0.

624 worker tests / 73 files, 1680 frontend tests / 137 files, both typechecks
and lint clean. Deploys to dev only; prod still requires a v* tag.
2026-08-29 21:42:47 +02:00

53 lines
1.6 KiB
TypeScript

/**
* Bank statement import — adapter registry + detection.
*
* The single place that knows the set of supported banks. Add a bank by
* importing its adapter and appending it here; everything else (detection, the
* UI's bank dropdown, processing) is driven off this list.
*/
import { dkbAdapter } from './adapters/dkb';
import { ersteAdapter } from './adapters/erste';
import { ingAdapter } from './adapters/ing';
import { n26Adapter } from './adapters/n26';
import { pbzAdapter } from './adapters/pbz';
import { revolutAdapter } from './adapters/revolut';
import { sparkasseAdapter } from './adapters/sparkasse';
import { wiseAdapter } from './adapters/wise';
import { ynabAdapter } from './adapters/ynab';
import type { BankAdapter, BankId, DetectInput } from './types';
export const ADAPTERS: readonly BankAdapter[] = [
revolutAdapter,
ersteAdapter,
pbzAdapter,
n26Adapter,
wiseAdapter,
ingAdapter,
sparkasseAdapter,
dkbAdapter,
ynabAdapter,
];
export function listAdapters(): readonly BankAdapter[] {
return ADAPTERS;
}
export function getAdapter(id: BankId): BankAdapter | undefined {
return ADAPTERS.find((a) => a.id === id);
}
export interface DetectResult {
adapter: BankAdapter;
confidence: number;
}
/** Highest-confidence adapter for a file, or null if none clears `threshold`. */
export function detectBank(input: DetectInput, threshold = 0.3): DetectResult | null {
let best: DetectResult | null = null;
for (const adapter of ADAPTERS) {
const confidence = adapter.detect(input);
if (confidence > (best?.confidence ?? 0)) best = { adapter, confidence };
}
return best && best.confidence >= threshold ? best : null;
}