actual-mcp-server 0.16.15 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/dist/src/actualToolsManager.js +2 -0
- package/dist/src/lib/actual-adapter/filter-ids.js +4 -0
- package/dist/src/lib/actual-adapter.js +64 -1
- package/dist/src/lib/financial-analysis.js +330 -0
- package/dist/src/lib/tool-annotations.js +2 -0
- package/dist/src/tools/account_flow_summary.js +52 -0
- package/dist/src/tools/index.js +2 -0
- package/dist/src/tools/transactions_aggregate.js +87 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -24,13 +24,13 @@ Actual MCP Server is a [Model Context Protocol](https://modelcontextprotocol.io/
|
|
|
24
24
|
┌─────────────┐ MCP/HTTP ┌──────────────────┐ Actual API ┌──────────────┐
|
|
25
25
|
│ LibreChat │ ◄───────────► │ Actual MCP │ ◄───────────► │ Actual │
|
|
26
26
|
│ LobeChat │ │ Server │ │ Budget │
|
|
27
|
-
│ (remote) │ │ (
|
|
27
|
+
│ (remote) │ │ (76 tools) │ │ Server │
|
|
28
28
|
└─────────────┘ └──────────────────┘ └──────────────┘
|
|
29
29
|
|
|
30
30
|
┌─────────────┐ MCP/stdio ┌──────────────────┐ Actual API ┌──────────────┐
|
|
31
31
|
│ Claude │ ◄───────────► │ Actual MCP │ ◄───────────► │ Actual │
|
|
32
32
|
│ Desktop │ │ Server │ │ Budget │
|
|
33
|
-
│ (local) │ │ (
|
|
33
|
+
│ (local) │ │ (76 tools) │ │ Server │
|
|
34
34
|
└─────────────┘ └──────────────────┘ └──────────────┘
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -38,14 +38,14 @@ Actual MCP Server is a [Model Context Protocol](https://modelcontextprotocol.io/
|
|
|
38
38
|
|
|
39
39
|
Most Actual Budget MCP implementations are simple stdio bridges designed for single-user, local use with Claude Desktop. This project goes further:
|
|
40
40
|
|
|
41
|
-
- **
|
|
41
|
+
- **76 tools, the most comprehensive coverage available.** Accounts, transactions, categories, payees, tags, notes, rules, budgets, batch operations, bank sync, and more. Covers the reachable Actual Budget API with no genuine gaps.
|
|
42
42
|
- **HTTP and stdio transport.** Runs as a real remote server for LibreChat/LobeChat (`--http`), or as a direct local process for Claude Desktop (`--stdio`). No Docker or HTTP server is needed for local use.
|
|
43
43
|
- **6 exclusive ActualQL-powered tools.** Search and summarise transactions by month, amount, category, or payee using Actual Budget's native query engine. Aggregated results, no raw data dumped into the AI context window.
|
|
44
44
|
- **Multi-budget switching at runtime.** Configure multiple budget files and let the AI switch between them mid-conversation with `actual_budgets_switch`. Works on both transports: HTTP keys the active budget to the MCP session, and stdio (Claude Desktop, Claude Code, Cursor) gets a synthetic per-process session so a switch is scoped to that process rather than shared globally (#348).
|
|
45
45
|
- **Multi-user ready with OIDC.** Secure every session with JWKS-validated JWTs and per-user budget ACLs. No shared tokens required.
|
|
46
46
|
- **Production-grade reliability on both transports.** HTTP connection pooling (up to 15 concurrent sessions), and a long-lived stdio process that logs in ONCE and reuses that connection for every tool call instead of re-authenticating per call, so Claude Desktop and Claude Code stay fast and a burst of calls no longer risks a per-call login storm against the upstream limiter. Automatic retry with exponential backoff, and a full test suite (unit + E2E + integration).
|
|
47
47
|
|
|
48
|
-
> **Verified working** with [LibreChat](https://www.librechat.ai/), [LobeChat](https://lobehub.com/home), and [Claude Desktop](https://claude.ai/download). All
|
|
48
|
+
> **Verified working** with [LibreChat](https://www.librechat.ai/), [LobeChat](https://lobehub.com/home), and [Claude Desktop](https://claude.ai/download). All 76 tools tested end-to-end. Any MCP-compatible client should work.
|
|
49
49
|
|
|
50
50
|
---
|
|
51
51
|
|
|
@@ -178,7 +178,7 @@ Add to `claude_desktop_config.json` (see [docs/guides/MCP_CLIENTS_SETUP.md](docs
|
|
|
178
178
|
}
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
> **No token needed.** stdio runs as a local process owned by your user. The transport itself is the security boundary. All
|
|
181
|
+
> **No token needed.** stdio runs as a local process owned by your user. The transport itself is the security boundary. All 76 tools are available.
|
|
182
182
|
>
|
|
183
183
|
> **`MCP_BRIDGE_DATA_DIR` should be an absolute path.** Without one, the data directory resolves relative to wherever the client spawns the process, which can be unpredictable. The directory is created automatically on first run.
|
|
184
184
|
|
|
@@ -304,9 +304,9 @@ For Claude Desktop (stdio), restart Claude after upgrading.
|
|
|
304
304
|
|
|
305
305
|
## Available Tools
|
|
306
306
|
|
|
307
|
-
**
|
|
307
|
+
**76 tools** across all categories. All tools use the `actual_<category>_<action>` naming convention.
|
|
308
308
|
|
|
309
|
-
### Accounts (
|
|
309
|
+
### Accounts (8)
|
|
310
310
|
|
|
311
311
|
| Tool | Description |
|
|
312
312
|
|------|-------------|
|
|
@@ -317,8 +317,9 @@ For Claude Desktop (stdio), restart Claude after upgrading.
|
|
|
317
317
|
| `actual_accounts_close` | Close account. An account with NO transactions is REMOVED by Actual, not closed |
|
|
318
318
|
| `actual_accounts_reopen` | Reopen closed account. An id that is not an account is refused rather than creating one |
|
|
319
319
|
| `actual_accounts_get_balance` | Get account balance at a date |
|
|
320
|
+
| `actual_account_flow_summary` | Explain the exact balance change across a set of accounts over a date range: external income, expense outflow, credits, uncategorized inflows, and transfers into, out of, or within the selection, with an exact reconciliation |
|
|
320
321
|
|
|
321
|
-
### Transactions (
|
|
322
|
+
### Transactions (15)
|
|
322
323
|
|
|
323
324
|
**Standard (6)**
|
|
324
325
|
|
|
@@ -340,10 +341,11 @@ For Claude Desktop (stdio), restart Claude after upgrading.
|
|
|
340
341
|
| `actual_transactions_uncategorized` | Summary of uncategorized transactions (totalCount, totalAmount, per-account breakdown); pass `includeTransactions:true` for paginated rows |
|
|
341
342
|
| `actual_transactions_update_batch` | Apply many transaction updates in ONE call (`updates: [{ id, fields }]`); returns per-item success and failure counts |
|
|
342
343
|
|
|
343
|
-
**Exclusive ActualQL-powered (
|
|
344
|
+
**Exclusive ActualQL-powered (7)**, unique to this MCP server
|
|
344
345
|
|
|
345
346
|
| Tool | Description |
|
|
346
347
|
|------|-------------|
|
|
348
|
+
| `actual_transactions_aggregate` | Deterministic integer-cent totals grouped by month, category, category group, payee, or account; transfers excluded via `transfer_id` and split children counted once |
|
|
347
349
|
| `actual_transactions_search_by_month` | Search by month using `$month` transform |
|
|
348
350
|
| `actual_transactions_search_by_amount` | Find by amount range |
|
|
349
351
|
| `actual_transactions_search_by_category` | Search by category name |
|
|
@@ -591,7 +593,7 @@ stdio is the simplest way to connect Claude Desktop directly to Actual Budget. T
|
|
|
591
593
|
- No auth token. Process ownership is the security boundary.
|
|
592
594
|
- All logs go to stderr so they never corrupt the JSON-RPC framing on stdout
|
|
593
595
|
- The process exits when stdin closes (Claude Desktop shutting down)
|
|
594
|
-
- All
|
|
596
|
+
- All 76 tools are available, identical to HTTP mode
|
|
595
597
|
|
|
596
598
|
**Start manually to verify:**
|
|
597
599
|
|
|
@@ -690,7 +692,7 @@ See [AI Client Setup, OIDC](docs/guides/AI_CLIENT_SETUP.md#oidc-authentication-m
|
|
|
690
692
|
| Command | What It Tests | Requires Live Server |
|
|
691
693
|
|---------|---------------|---------------------|
|
|
692
694
|
| `npm run build` | TypeScript compilation | No |
|
|
693
|
-
| `npm run test:unit-js` |
|
|
695
|
+
| `npm run test:unit-js` | 76-tool smoke, schema validation, auth ACL | No |
|
|
694
696
|
| `npm run test:adapter` | Adapter, retry logic, concurrency | No |
|
|
695
697
|
| `npm run test:e2e` | MCP protocol compliance (Playwright) | No |
|
|
696
698
|
| `npm run test:e2e:docker:full` | Full stack integration | Yes (Docker) |
|
|
@@ -775,7 +777,7 @@ The software is provided **as-is**, without warranty of any kind. The author acc
|
|
|
775
777
|
|
|
776
778
|
---
|
|
777
779
|
|
|
778
|
-
**Version:** 0.
|
|
780
|
+
**Version:** 0.18.0 | **Tool Count:** 76 (verified LibreChat-compatible)
|
|
779
781
|
|
|
780
782
|
## Sponsor
|
|
781
783
|
|
|
@@ -4,6 +4,7 @@ import { formatZodError } from './lib/zod-error-format.js';
|
|
|
4
4
|
// ✅ List of tools already implemented in this class.
|
|
5
5
|
// Adding the tool name here is considered fully implemented.
|
|
6
6
|
const IMPLEMENTED_TOOLS = [
|
|
7
|
+
'actual_account_flow_summary',
|
|
7
8
|
'actual_accounts_close',
|
|
8
9
|
'actual_accounts_create',
|
|
9
10
|
'actual_accounts_delete',
|
|
@@ -48,6 +49,7 @@ const IMPLEMENTED_TOOLS = [
|
|
|
48
49
|
'actual_schedules_delete',
|
|
49
50
|
'actual_schedules_get',
|
|
50
51
|
'actual_schedules_update',
|
|
52
|
+
'actual_transactions_aggregate',
|
|
51
53
|
'actual_transactions_create',
|
|
52
54
|
'actual_transactions_delete',
|
|
53
55
|
'actual_transactions_filter',
|
|
@@ -31,6 +31,10 @@ import { UUID_PATTERN } from '../constants.js';
|
|
|
31
31
|
export const FILTER_ID_ENTITIES = {
|
|
32
32
|
account: { entity: 'Account', listTool: 'actual_accounts_list' },
|
|
33
33
|
category: { entity: 'Category', listTool: 'actual_categories_get' },
|
|
34
|
+
// #424: category_group joins so the aggregate tool's categoryGroupIds filter resolves a NAME the
|
|
35
|
+
// same way the other three do. Without it a group name would fall through resolveFilterId's rows
|
|
36
|
+
// resolver to the payee listing and match nothing (a wrong answer, not an error).
|
|
37
|
+
category_group: { entity: 'Category group', listTool: 'actual_category_groups_get' },
|
|
34
38
|
payee: { entity: 'Payee', listTool: 'actual_payees_get' },
|
|
35
39
|
};
|
|
36
40
|
/**
|
|
@@ -1659,7 +1659,8 @@ export async function resolveFilterId(kind, value, opts) {
|
|
|
1659
1659
|
const rows = opts?.rows
|
|
1660
1660
|
?? (kind === 'account' ? await getAccounts()
|
|
1661
1661
|
: kind === 'category' ? await getCategories()
|
|
1662
|
-
: await
|
|
1662
|
+
: kind === 'category_group' ? (await getCategoryGroups())
|
|
1663
|
+
: await getPayees());
|
|
1663
1664
|
if (isEntityId(value)) {
|
|
1664
1665
|
// Only reachable under verifyExists. A well-formed id that names nothing is a not-found,
|
|
1665
1666
|
// not a name to resolve.
|
|
@@ -2820,6 +2821,67 @@ export async function runQuery(queryString) {
|
|
|
2820
2821
|
throw new Error(`Query execution failed: ${errorMsg}`);
|
|
2821
2822
|
}
|
|
2822
2823
|
}
|
|
2824
|
+
/**
|
|
2825
|
+
* #424: one read snapshot for the deterministic financial-analysis tools. Runs a fixed set of
|
|
2826
|
+
* ActualQL reads inside ONE withActualApi session (not N+1): the in-range transactions with splits
|
|
2827
|
+
* GROUPED (so a split reduces to its children exactly once), plus the account/category/group/payee
|
|
2828
|
+
* listings the tool needs to resolve filters and label groups. The account-flow tool (#425) extends
|
|
2829
|
+
* this with transfer counterparts and opening/closing balances.
|
|
2830
|
+
*
|
|
2831
|
+
* Original query shapes by @maxvanweenen (PR #399).
|
|
2832
|
+
*/
|
|
2833
|
+
export async function getFinancialAnalysisSnapshot(params) {
|
|
2834
|
+
return withActualApi(async () => {
|
|
2835
|
+
observability.incrementToolCall('actual.financialAnalysis.snapshot').catch(() => { });
|
|
2836
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2837
|
+
const { q } = (await import('@actual-app/api'));
|
|
2838
|
+
const queryData = async (query) => {
|
|
2839
|
+
const response = await withConcurrency(() => retry(() => rawRunQuery(query), { retries: 2, backoffMs: 200 }));
|
|
2840
|
+
if (Array.isArray(response))
|
|
2841
|
+
return response;
|
|
2842
|
+
return Array.isArray(response?.data) ? response.data : [];
|
|
2843
|
+
};
|
|
2844
|
+
const transactions = await queryData(q('transactions')
|
|
2845
|
+
.options({ splits: 'grouped' })
|
|
2846
|
+
.filter({ $and: [{ date: { $gte: params.startDate } }, { date: { $lte: params.endDate } }] })
|
|
2847
|
+
.select('*'));
|
|
2848
|
+
const accounts = await queryData(q('accounts').select(['id', 'name', 'offbudget', 'closed']));
|
|
2849
|
+
const categories = await queryData(q('categories').select(['id', 'name', 'is_income', 'group']));
|
|
2850
|
+
const categoryGroups = await queryData(q('category_groups').options({ categories: 'none' }).select(['id', 'name', 'is_income']));
|
|
2851
|
+
const payees = await queryData(q('payees').select(['id', 'name', 'transfer_acct']));
|
|
2852
|
+
// #425: the transfer counterparts (the OTHER leg of each transfer), so account-flow can name the
|
|
2853
|
+
// funding account. splits:'all' here (not inline/grouped) so a split transfer leg is still seen.
|
|
2854
|
+
const transferIds = [...new Set(transactions.flatMap(t => [t, ...(t.subtransactions ?? [])])
|
|
2855
|
+
.map(t => t.transfer_id)
|
|
2856
|
+
.filter((id) => typeof id === 'string' && id.length > 0))];
|
|
2857
|
+
const transferCounterparts = transferIds.length > 0
|
|
2858
|
+
? await queryData(q('transactions').options({ splits: 'all' }).filter({ id: { $oneof: transferIds } }).select('*'))
|
|
2859
|
+
: [];
|
|
2860
|
+
// #425: opening (strictly before startDate) and closing (through endDate) balances for the
|
|
2861
|
+
// selected accounts. splits:'inline' expands a split to its children so each posting is summed
|
|
2862
|
+
// ONCE; splits:'all' would double-count a split parent plus its children and break reconciliation.
|
|
2863
|
+
const openingBalances = {};
|
|
2864
|
+
const closingBalances = {};
|
|
2865
|
+
const balanceAccountIds = params.balanceAccountIds ?? [];
|
|
2866
|
+
if (balanceAccountIds.length > 0) {
|
|
2867
|
+
const openingRows = await queryData(q('transactions').options({ splits: 'inline' })
|
|
2868
|
+
.filter({ $and: [{ account: { $oneof: balanceAccountIds } }, { date: { $lt: params.startDate } }] })
|
|
2869
|
+
.groupBy('account').select(['account', { balance: { $sum: '$amount' } }]));
|
|
2870
|
+
const closingRows = await queryData(q('transactions').options({ splits: 'inline' })
|
|
2871
|
+
.filter({ $and: [{ account: { $oneof: balanceAccountIds } }, { date: { $lte: params.endDate } }] })
|
|
2872
|
+
.groupBy('account').select(['account', { balance: { $sum: '$amount' } }]));
|
|
2873
|
+
for (const id of balanceAccountIds) {
|
|
2874
|
+
openingBalances[id] = 0;
|
|
2875
|
+
closingBalances[id] = 0;
|
|
2876
|
+
}
|
|
2877
|
+
for (const row of openingRows)
|
|
2878
|
+
openingBalances[row.account] = row.balance ?? 0;
|
|
2879
|
+
for (const row of closingRows)
|
|
2880
|
+
closingBalances[row.account] = row.balance ?? 0;
|
|
2881
|
+
}
|
|
2882
|
+
return { transactions, transferCounterparts, accounts, categories, categoryGroups, payees, openingBalances, closingBalances };
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2823
2885
|
// WHERE-clause translation extracted to ./actual-adapter/query.ts (#166).
|
|
2824
2886
|
// Imported for internal use by runQuery and re-exported (unit-tested directly).
|
|
2825
2887
|
import { parseWhereClause } from './actual-adapter/query.js';
|
|
@@ -3348,6 +3410,7 @@ export async function getPreferences() {
|
|
|
3348
3410
|
export default {
|
|
3349
3411
|
getAccounts,
|
|
3350
3412
|
resolveFilterId,
|
|
3413
|
+
getFinancialAnalysisSnapshot,
|
|
3351
3414
|
getAccountsWithBalances,
|
|
3352
3415
|
addTransactions,
|
|
3353
3416
|
importTransactions,
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// Deterministic financial-analysis primitives: pure functions that turn a snapshot of Actual
|
|
2
|
+
// Budget rows into aggregated, integer-cent totals, so the accounting is computed in server code
|
|
3
|
+
// rather than re-derived by an LLM.
|
|
4
|
+
//
|
|
5
|
+
// Original implementation by @maxvanweenen (PR #399, https://github.com/agigante80/actual-mcp-server/pull/399),
|
|
6
|
+
// requested in #398. This file is the aggregate slice (the `actual_transactions_aggregate` tool,
|
|
7
|
+
// #424); the account-flow and recurring-expense functions land with their own tools (#425, #426).
|
|
8
|
+
//
|
|
9
|
+
// PURE by design: no api session, no module state, so every branch is unit-testable against fixed
|
|
10
|
+
// rows. The adapter owns the impure half (fetching the snapshot) in `getFinancialAnalysisSnapshot`.
|
|
11
|
+
const zeroAggregate = () => ({
|
|
12
|
+
expenseOutflow: 0,
|
|
13
|
+
credits: 0,
|
|
14
|
+
netExpense: 0,
|
|
15
|
+
income: 0,
|
|
16
|
+
uncategorizedInflows: 0,
|
|
17
|
+
adjustments: 0,
|
|
18
|
+
transferInflow: 0,
|
|
19
|
+
transferOutflow: 0,
|
|
20
|
+
transactionCount: 0,
|
|
21
|
+
transferCount: 0,
|
|
22
|
+
});
|
|
23
|
+
function bool(value) {
|
|
24
|
+
return value === true || value === 1;
|
|
25
|
+
}
|
|
26
|
+
// Money is integer cents everywhere. A non-integer amount is a data-shape error, not something to
|
|
27
|
+
// round, so it throws rather than silently corrupting a total.
|
|
28
|
+
function integer(value, field) {
|
|
29
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value)) {
|
|
30
|
+
throw new Error(`${field} must be a safe integer number of cents.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
export function buildMaps(snapshot) {
|
|
35
|
+
return {
|
|
36
|
+
accounts: new Map(snapshot.accounts.map(account => [account.id, account])),
|
|
37
|
+
categories: new Map(snapshot.categories.map(category => [category.id, category])),
|
|
38
|
+
categoryGroups: new Map(snapshot.categoryGroups.map(group => [group.id, group])),
|
|
39
|
+
payees: new Map(snapshot.payees.map(payee => [payee.id, payee])),
|
|
40
|
+
transactions: new Map([...snapshot.transactions, ...(snapshot.transferCounterparts ?? [])].flatMap(transaction => [
|
|
41
|
+
transaction,
|
|
42
|
+
...(transaction.subtransactions ?? []),
|
|
43
|
+
]).map(transaction => [transaction.id, transaction])),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convert Actual's grouped split representation into posting rows. A normal transaction appears
|
|
48
|
+
* once. A split contributes its CHILDREN and never its parent, so a split is counted exactly once.
|
|
49
|
+
* A `seen` set dedups a child that arrives both grouped and top-level, in either order.
|
|
50
|
+
*/
|
|
51
|
+
export function postingRows(transactions) {
|
|
52
|
+
const rows = [];
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
for (const transaction of transactions) {
|
|
55
|
+
if (transaction.is_parent === true || (transaction.subtransactions?.length ?? 0) > 0) {
|
|
56
|
+
for (const child of transaction.subtransactions ?? []) {
|
|
57
|
+
if (seen.has(child.id))
|
|
58
|
+
continue;
|
|
59
|
+
seen.add(child.id);
|
|
60
|
+
rows.push({
|
|
61
|
+
...child,
|
|
62
|
+
account: child.account ?? transaction.account,
|
|
63
|
+
date: child.date ?? transaction.date,
|
|
64
|
+
payee: child.payee ?? transaction.payee,
|
|
65
|
+
parent_id: child.parent_id ?? transaction.id,
|
|
66
|
+
is_child: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (transaction.parent_id != null || transaction.is_child === true) {
|
|
72
|
+
if (!seen.has(transaction.id)) {
|
|
73
|
+
seen.add(transaction.id);
|
|
74
|
+
rows.push(transaction);
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (!seen.has(transaction.id)) {
|
|
79
|
+
seen.add(transaction.id);
|
|
80
|
+
rows.push(transaction);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return rows;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Classify a posting row. A TRANSFER is detected from `transfer_id` FIRST, before any category or
|
|
87
|
+
* income logic, so a transfer is never spending or income regardless of how it is categorized. That
|
|
88
|
+
* is the exact fragility #398 identified in the existing summary tools.
|
|
89
|
+
*/
|
|
90
|
+
export function classifyExternal(transaction, category) {
|
|
91
|
+
if (transaction.transfer_id != null)
|
|
92
|
+
return 'transfer';
|
|
93
|
+
if (transaction.starting_balance_flag === true)
|
|
94
|
+
return 'adjustment';
|
|
95
|
+
const amount = integer(transaction.amount, `Transaction ${transaction.id} amount`);
|
|
96
|
+
if (category && bool(category.is_income))
|
|
97
|
+
return 'income';
|
|
98
|
+
if (amount < 0)
|
|
99
|
+
return 'expense';
|
|
100
|
+
if (amount > 0 && category)
|
|
101
|
+
return 'credit';
|
|
102
|
+
if (amount > 0)
|
|
103
|
+
return 'uncategorized-inflow';
|
|
104
|
+
return 'expense';
|
|
105
|
+
}
|
|
106
|
+
function groupingFields(transaction, dimensions, maps) {
|
|
107
|
+
const category = transaction.category ? maps.categories.get(transaction.category) : undefined;
|
|
108
|
+
const categoryGroup = category?.group ? maps.categoryGroups.get(category.group) : undefined;
|
|
109
|
+
const payee = transaction.payee ? maps.payees.get(transaction.payee) : undefined;
|
|
110
|
+
const account = maps.accounts.get(transaction.account);
|
|
111
|
+
const fields = {};
|
|
112
|
+
for (const dimension of dimensions) {
|
|
113
|
+
if (dimension === 'month')
|
|
114
|
+
fields.month = transaction.date.slice(0, 7);
|
|
115
|
+
if (dimension === 'category') {
|
|
116
|
+
fields.categoryId = category?.id ?? null;
|
|
117
|
+
fields.categoryName = category?.name ?? 'Uncategorized';
|
|
118
|
+
}
|
|
119
|
+
if (dimension === 'category_group') {
|
|
120
|
+
fields.categoryGroupId = categoryGroup?.id ?? null;
|
|
121
|
+
fields.categoryGroupName = categoryGroup?.name ?? 'Uncategorized';
|
|
122
|
+
}
|
|
123
|
+
if (dimension === 'payee') {
|
|
124
|
+
fields.payeeId = payee?.id ?? null;
|
|
125
|
+
fields.payeeName = payee?.name ?? 'Unknown payee';
|
|
126
|
+
}
|
|
127
|
+
if (dimension === 'account') {
|
|
128
|
+
fields.accountId = transaction.account;
|
|
129
|
+
fields.accountName = account?.name ?? transaction.account;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return fields;
|
|
133
|
+
}
|
|
134
|
+
function matchesFilters(transaction, input, maps) {
|
|
135
|
+
if (transaction.date < input.startDate || transaction.date > input.endDate)
|
|
136
|
+
return false;
|
|
137
|
+
if (input.accountIds && !input.accountIds.includes(transaction.account))
|
|
138
|
+
return false;
|
|
139
|
+
if (input.categoryIds && (!transaction.category || !input.categoryIds.includes(transaction.category)))
|
|
140
|
+
return false;
|
|
141
|
+
if (input.payeeIds && (!transaction.payee || !input.payeeIds.includes(transaction.payee)))
|
|
142
|
+
return false;
|
|
143
|
+
if (input.categoryGroupIds) {
|
|
144
|
+
const groupId = transaction.category ? maps.categories.get(transaction.category)?.group : undefined;
|
|
145
|
+
if (!groupId || !input.categoryGroupIds.includes(groupId))
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
function addAggregate(target, source) {
|
|
151
|
+
target.expenseOutflow += source.expenseOutflow;
|
|
152
|
+
target.credits += source.credits;
|
|
153
|
+
target.income += source.income;
|
|
154
|
+
target.uncategorizedInflows += source.uncategorizedInflows;
|
|
155
|
+
target.adjustments += source.adjustments;
|
|
156
|
+
target.transferInflow += source.transferInflow;
|
|
157
|
+
target.transferOutflow += source.transferOutflow;
|
|
158
|
+
target.transactionCount += source.transactionCount;
|
|
159
|
+
target.transferCount += source.transferCount;
|
|
160
|
+
target.netExpense = target.expenseOutflow - target.credits;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Group posting rows over an inclusive date range into integer-cent totals. Transfers are excluded
|
|
164
|
+
* by default (kept in their own inflow/outflow fields when `excludeTransfers` is false); income is
|
|
165
|
+
* excluded unless `includeIncome`. Deliberately groups IN PROCESS rather than via a `.groupBy`
|
|
166
|
+
* query, because a grouped query would flatten splits back to inline and reintroduce double-count.
|
|
167
|
+
*/
|
|
168
|
+
export function aggregateTransactions(snapshot, input) {
|
|
169
|
+
const maps = buildMaps(snapshot);
|
|
170
|
+
const grouped = new Map();
|
|
171
|
+
for (const transaction of postingRows(snapshot.transactions)) {
|
|
172
|
+
if (!matchesFilters(transaction, input, maps))
|
|
173
|
+
continue;
|
|
174
|
+
const category = transaction.category ? maps.categories.get(transaction.category) : undefined;
|
|
175
|
+
const classification = classifyExternal(transaction, category);
|
|
176
|
+
if (classification === 'income' && !input.includeIncome)
|
|
177
|
+
continue;
|
|
178
|
+
if (classification === 'transfer' && input.excludeTransfers)
|
|
179
|
+
continue;
|
|
180
|
+
const dimensions = groupingFields(transaction, input.groupBy, maps);
|
|
181
|
+
const key = JSON.stringify(dimensions);
|
|
182
|
+
const entry = grouped.get(key) ?? { dimensions, values: zeroAggregate() };
|
|
183
|
+
const amount = integer(transaction.amount, `Transaction ${transaction.id} amount`);
|
|
184
|
+
if (classification === 'expense')
|
|
185
|
+
entry.values.expenseOutflow += Math.abs(amount);
|
|
186
|
+
if (classification === 'credit')
|
|
187
|
+
entry.values.credits += amount;
|
|
188
|
+
if (classification === 'income')
|
|
189
|
+
entry.values.income += amount;
|
|
190
|
+
if (classification === 'uncategorized-inflow')
|
|
191
|
+
entry.values.uncategorizedInflows += amount;
|
|
192
|
+
if (classification === 'adjustment')
|
|
193
|
+
entry.values.adjustments += amount;
|
|
194
|
+
if (classification === 'transfer') {
|
|
195
|
+
if (amount >= 0)
|
|
196
|
+
entry.values.transferInflow += amount;
|
|
197
|
+
else
|
|
198
|
+
entry.values.transferOutflow += Math.abs(amount);
|
|
199
|
+
entry.values.transferCount += 1;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
entry.values.transactionCount += 1;
|
|
203
|
+
}
|
|
204
|
+
entry.values.netExpense = entry.values.expenseOutflow - entry.values.credits;
|
|
205
|
+
grouped.set(key, entry);
|
|
206
|
+
}
|
|
207
|
+
const groups = [...grouped.values()]
|
|
208
|
+
.sort((a, b) => JSON.stringify(a.dimensions).localeCompare(JSON.stringify(b.dimensions)))
|
|
209
|
+
.map(entry => ({ ...entry.dimensions, ...entry.values }));
|
|
210
|
+
const totals = zeroAggregate();
|
|
211
|
+
for (const entry of grouped.values())
|
|
212
|
+
addAggregate(totals, entry.values);
|
|
213
|
+
return { dateRange: { startDate: input.startDate, endDate: input.endDate }, groups, totals };
|
|
214
|
+
}
|
|
215
|
+
export function summarizeAccountFlow(snapshot, input) {
|
|
216
|
+
const maps = buildMaps(snapshot);
|
|
217
|
+
const selected = new Set(input.accountIds);
|
|
218
|
+
// Dedupe once. The balance reduces and the accounts list below MUST key off the same unique set
|
|
219
|
+
// the rows are filtered against, or a repeated id (two display names resolving to one account, say)
|
|
220
|
+
// doubles the balances while the Set counts postings once, making reconciliation.difference non-zero
|
|
221
|
+
// and falsifying the tool's exact-by-construction guarantee.
|
|
222
|
+
const uniqueAccountIds = [...selected];
|
|
223
|
+
const rows = postingRows(snapshot.transactions).filter(transaction => selected.has(transaction.account) && transaction.date >= input.startDate && transaction.date <= input.endDate);
|
|
224
|
+
let income = 0;
|
|
225
|
+
let incomeReversals = 0;
|
|
226
|
+
let expenseOutflow = 0;
|
|
227
|
+
let credits = 0;
|
|
228
|
+
let uncategorizedInflows = 0;
|
|
229
|
+
let startingBalance = 0;
|
|
230
|
+
let intoSelection = 0;
|
|
231
|
+
let outOfSelection = 0;
|
|
232
|
+
let withinSelection = 0;
|
|
233
|
+
let withinSelectionTimingEffect = 0;
|
|
234
|
+
let netTransferEffect = 0;
|
|
235
|
+
const seenPairs = new Set();
|
|
236
|
+
const transfersByAccount = [];
|
|
237
|
+
for (const transaction of rows) {
|
|
238
|
+
const amount = integer(transaction.amount, `Transaction ${transaction.id} amount`);
|
|
239
|
+
const category = transaction.category ? maps.categories.get(transaction.category) : undefined;
|
|
240
|
+
const classification = classifyExternal(transaction, category);
|
|
241
|
+
if (classification === 'expense')
|
|
242
|
+
expenseOutflow += Math.abs(amount);
|
|
243
|
+
if (classification === 'credit')
|
|
244
|
+
credits += amount;
|
|
245
|
+
if (classification === 'income') {
|
|
246
|
+
if (amount >= 0)
|
|
247
|
+
income += amount;
|
|
248
|
+
else
|
|
249
|
+
incomeReversals += Math.abs(amount);
|
|
250
|
+
}
|
|
251
|
+
if (classification === 'uncategorized-inflow')
|
|
252
|
+
uncategorizedInflows += amount;
|
|
253
|
+
if (classification === 'adjustment')
|
|
254
|
+
startingBalance += amount;
|
|
255
|
+
if (classification !== 'transfer')
|
|
256
|
+
continue;
|
|
257
|
+
netTransferEffect += amount;
|
|
258
|
+
const counterpart = transaction.transfer_id ? maps.transactions.get(transaction.transfer_id) : undefined;
|
|
259
|
+
const payee = transaction.payee ? maps.payees.get(transaction.payee) : undefined;
|
|
260
|
+
const counterpartAccountId = counterpart?.account ?? payee?.transfer_acct ?? null;
|
|
261
|
+
const counterpartSelected = counterpartAccountId ? selected.has(counterpartAccountId) : false;
|
|
262
|
+
if (counterpartSelected) {
|
|
263
|
+
withinSelectionTimingEffect += amount;
|
|
264
|
+
const pairKey = [transaction.id, transaction.transfer_id ?? transaction.id].sort().join(':');
|
|
265
|
+
if (!seenPairs.has(pairKey)) {
|
|
266
|
+
seenPairs.add(pairKey);
|
|
267
|
+
withinSelection += Math.abs(amount);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else if (amount >= 0) {
|
|
271
|
+
intoSelection += amount;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
outOfSelection += Math.abs(amount);
|
|
275
|
+
}
|
|
276
|
+
const pairKey = [transaction.id, transaction.transfer_id ?? transaction.id].sort().join(':');
|
|
277
|
+
if (!seenPairs.has(`detail:${pairKey}`)) {
|
|
278
|
+
seenPairs.add(`detail:${pairKey}`);
|
|
279
|
+
const fromId = amount < 0 ? transaction.account : counterpartAccountId;
|
|
280
|
+
const toId = amount < 0 ? counterpartAccountId : transaction.account;
|
|
281
|
+
transfersByAccount.push({
|
|
282
|
+
fromAccountId: fromId,
|
|
283
|
+
fromAccountName: fromId ? maps.accounts.get(fromId)?.name ?? fromId : null,
|
|
284
|
+
toAccountId: toId,
|
|
285
|
+
toAccountName: toId ? maps.accounts.get(toId)?.name ?? toId : null,
|
|
286
|
+
amount: Math.abs(amount),
|
|
287
|
+
date: transaction.date,
|
|
288
|
+
withinSelection: counterpartSelected,
|
|
289
|
+
matchedCounterpart: counterpart != null,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// The tool handler always supplies balances (via balanceAccountIds), so difference is exact here.
|
|
294
|
+
// If a future caller omits them, both reduce to 0 and difference reads as a false "exact": #428.
|
|
295
|
+
const openingBalance = uniqueAccountIds.reduce((sum, id) => sum + integer(snapshot.openingBalances?.[id] ?? 0, `Opening balance for ${id}`), 0);
|
|
296
|
+
const closingBalance = uniqueAccountIds.reduce((sum, id) => sum + integer(snapshot.closingBalances?.[id] ?? 0, `Closing balance for ${id}`), 0);
|
|
297
|
+
const balanceChange = closingBalance - openingBalance;
|
|
298
|
+
const netExternalCashFlow = income - incomeReversals + credits + uncategorizedInflows - expenseOutflow;
|
|
299
|
+
const totalAdjustments = startingBalance;
|
|
300
|
+
const calculatedBalanceChange = netExternalCashFlow + netTransferEffect + totalAdjustments;
|
|
301
|
+
return {
|
|
302
|
+
dateRange: { startDate: input.startDate, endDate: input.endDate },
|
|
303
|
+
accounts: uniqueAccountIds.map(id => ({ id, name: maps.accounts.get(id)?.name ?? id })),
|
|
304
|
+
openingBalance,
|
|
305
|
+
closingBalance,
|
|
306
|
+
balanceChange,
|
|
307
|
+
external: {
|
|
308
|
+
income,
|
|
309
|
+
incomeReversals,
|
|
310
|
+
expenseOutflow,
|
|
311
|
+
credits,
|
|
312
|
+
uncategorizedInflows,
|
|
313
|
+
netExternalCashFlow,
|
|
314
|
+
},
|
|
315
|
+
transfers: {
|
|
316
|
+
intoSelection,
|
|
317
|
+
outOfSelection,
|
|
318
|
+
withinSelection,
|
|
319
|
+
withinSelectionTimingEffect,
|
|
320
|
+
netTransferEffect,
|
|
321
|
+
},
|
|
322
|
+
transfersByAccount: transfersByAccount.sort((a, b) => `${a.date}:${a.fromAccountId}:${a.toAccountId}`.localeCompare(`${b.date}:${b.fromAccountId}:${b.toAccountId}`)),
|
|
323
|
+
adjustments: { startingBalance, total: totalAdjustments },
|
|
324
|
+
reconciliation: {
|
|
325
|
+
calculatedBalanceChange,
|
|
326
|
+
actualBalanceChange: balanceChange,
|
|
327
|
+
difference: balanceChange - calculatedBalanceChange,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
@@ -55,6 +55,7 @@ const OPEN_WORLD = new Set(['actual_bank_sync']);
|
|
|
55
55
|
* actual_session_close closes a pooled connection: server state, not budget data.
|
|
56
56
|
*/
|
|
57
57
|
const READ_ONLY = new Set([
|
|
58
|
+
'actual_account_flow_summary',
|
|
58
59
|
'actual_accounts_get_balance',
|
|
59
60
|
'actual_accounts_list',
|
|
60
61
|
'actual_budgets_get_all',
|
|
@@ -77,6 +78,7 @@ const READ_ONLY = new Set([
|
|
|
77
78
|
'actual_server_info',
|
|
78
79
|
'actual_session_list',
|
|
79
80
|
'actual_tags_list',
|
|
81
|
+
'actual_transactions_aggregate',
|
|
80
82
|
'actual_transactions_filter',
|
|
81
83
|
'actual_transactions_get',
|
|
82
84
|
'actual_transactions_search_by_amount',
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// #425: deterministic, read-only account-flow reconciliation.
|
|
2
|
+
//
|
|
3
|
+
// Original implementation by @maxvanweenen (PR #399), the "deferred secondary" tool from #398. The
|
|
4
|
+
// accounting lives in src/lib/financial-analysis.ts (summarizeAccountFlow); this file is the tool
|
|
5
|
+
// surface plus the #388 filter-id resolution.
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { createTool } from '../lib/toolFactory.js';
|
|
8
|
+
import { CommonSchemas } from '../lib/schemas/common.js';
|
|
9
|
+
import adapter from '../lib/actual-adapter.js';
|
|
10
|
+
import { summarizeAccountFlow } from '../lib/financial-analysis.js';
|
|
11
|
+
// Bare-string ids (#388): a NAME resolves via adapter.resolveFilterId rather than being rejected.
|
|
12
|
+
const InputSchema = z.object({
|
|
13
|
+
startDate: CommonSchemas.date,
|
|
14
|
+
endDate: CommonSchemas.date,
|
|
15
|
+
accountIds: z.array(z.string().min(1)).min(1, 'Select at least one account').max(100),
|
|
16
|
+
}).strict().superRefine((input, ctx) => {
|
|
17
|
+
if (input.startDate > input.endDate) {
|
|
18
|
+
ctx.addIssue({ code: 'custom', path: ['endDate'], message: 'endDate must be on or after startDate' });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export default createTool({
|
|
22
|
+
name: 'actual_account_flow_summary',
|
|
23
|
+
description: [
|
|
24
|
+
'Explain the exact balance change across a selected set of accounts over an inclusive date range, in integer cents.',
|
|
25
|
+
'Separates external income, expense outflow, credits, uncategorized inflows, starting-balance adjustments, and transfers into, out of, or within the selection.',
|
|
26
|
+
'Transfers are detected from transfer_id and are never spending or income.',
|
|
27
|
+
'openingBalance is immediately before startDate and closingBalance is at the end of the inclusive endDate; reconciliation.difference is exact and transfersByAccount names the funding counterparties.',
|
|
28
|
+
'Amounts are in cents: $100.00 = 10000. Dates are YYYY-MM-DD.',
|
|
29
|
+
].join(' '),
|
|
30
|
+
schema: InputSchema,
|
|
31
|
+
handler: async (input) => {
|
|
32
|
+
// Fetch with the raw ids so the balance queries run in the same session. A NAME here filters the
|
|
33
|
+
// balance query to nothing (0), which is harmless because the resolveFilterId pass below refuses
|
|
34
|
+
// the name before the result is used.
|
|
35
|
+
const snapshot = await adapter.getFinancialAnalysisSnapshot({
|
|
36
|
+
startDate: input.startDate,
|
|
37
|
+
endDate: input.endDate,
|
|
38
|
+
balanceAccountIds: input.accountIds,
|
|
39
|
+
});
|
|
40
|
+
const accountIds = [];
|
|
41
|
+
for (const id of input.accountIds) {
|
|
42
|
+
accountIds.push(await adapter.resolveFilterId('account', id, { verifyExists: true, rows: snapshot.accounts }));
|
|
43
|
+
}
|
|
44
|
+
return summarizeAccountFlow(snapshot, { startDate: input.startDate, endDate: input.endDate, accountIds });
|
|
45
|
+
},
|
|
46
|
+
examples: [
|
|
47
|
+
{
|
|
48
|
+
description: 'Reconcile the flow across two accounts for a month',
|
|
49
|
+
input: { startDate: '2025-01-01', endDate: '2025-01-31', accountIds: ['<account-uuid-1>', '<account-uuid-2>'] },
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
package/dist/src/tools/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Auto-generated index for all tool modules
|
|
2
2
|
export { default as entities_search } from './entities_search.js';
|
|
3
|
+
export { default as account_flow_summary } from './account_flow_summary.js';
|
|
3
4
|
export { default as accounts_close } from './accounts_close.js';
|
|
4
5
|
export { default as accounts_create } from './accounts_create.js';
|
|
5
6
|
export { default as accounts_delete } from './accounts_delete.js';
|
|
@@ -49,6 +50,7 @@ export { default as schedules_delete } from './schedules_delete.js';
|
|
|
49
50
|
export { default as schedules_get } from './schedules_get.js';
|
|
50
51
|
export { default as schedules_update } from './schedules_update.js';
|
|
51
52
|
export { default as server_info } from './server_info.js';
|
|
53
|
+
export { default as transactions_aggregate } from './transactions_aggregate.js';
|
|
52
54
|
export { default as transactions_create } from './transactions_create.js';
|
|
53
55
|
export { default as transactions_delete } from './transactions_delete.js';
|
|
54
56
|
export { default as transactions_filter } from './transactions_filter.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// #424: deterministic, read-only aggregation of posted transactions.
|
|
2
|
+
//
|
|
3
|
+
// Original implementation by @maxvanweenen (PR #399), requested in #398. The accounting lives in
|
|
4
|
+
// src/lib/financial-analysis.ts; this file is the tool surface plus the #388 filter-id resolution.
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { createTool } from '../lib/toolFactory.js';
|
|
7
|
+
import { CommonSchemas } from '../lib/schemas/common.js';
|
|
8
|
+
import adapter from '../lib/actual-adapter.js';
|
|
9
|
+
import { aggregateTransactions, } from '../lib/financial-analysis.js';
|
|
10
|
+
const GroupDimensionSchema = z.enum(['month', 'category', 'category_group', 'payee', 'account']);
|
|
11
|
+
// The optional id filters are BARE strings, not CommonSchemas ids, on purpose (#388): a NAME is
|
|
12
|
+
// resolved to its id by adapter.resolveFilterId rather than rejected with a bare ZodError, so the
|
|
13
|
+
// caller learns the id. Tightening these to CommonSchemas would delete that accommodation.
|
|
14
|
+
const IdArray = z.array(z.string().min(1)).min(1).max(100);
|
|
15
|
+
const InputSchema = z.object({
|
|
16
|
+
startDate: CommonSchemas.date,
|
|
17
|
+
endDate: CommonSchemas.date,
|
|
18
|
+
groupBy: z.union([GroupDimensionSchema, z.array(GroupDimensionSchema).min(1).max(5)]),
|
|
19
|
+
accountIds: IdArray.optional(),
|
|
20
|
+
categoryIds: IdArray.optional(),
|
|
21
|
+
categoryGroupIds: IdArray.optional(),
|
|
22
|
+
payeeIds: IdArray.optional(),
|
|
23
|
+
includeIncome: z.boolean().optional().default(false),
|
|
24
|
+
excludeTransfers: z.boolean().optional().default(true),
|
|
25
|
+
}).strict().superRefine((input, ctx) => {
|
|
26
|
+
if (input.startDate > input.endDate) {
|
|
27
|
+
ctx.addIssue({ code: 'custom', path: ['endDate'], message: 'endDate must be on or after startDate' });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
// Resolve every element of an optional id filter through the #388 chokepoint, reusing the listing
|
|
31
|
+
// the snapshot already fetched (so no extra listing read per element, no N+1). A well-formed known
|
|
32
|
+
// id passes through unchanged; a NAME throws a refusal carrying the resolved id; an unknown
|
|
33
|
+
// well-formed id throws NotFoundRefusal.
|
|
34
|
+
async function resolveIds(ids, kind, rows) {
|
|
35
|
+
if (!ids)
|
|
36
|
+
return undefined;
|
|
37
|
+
const resolved = [];
|
|
38
|
+
for (const id of ids) {
|
|
39
|
+
resolved.push(await adapter.resolveFilterId(kind, id, { verifyExists: true, rows }));
|
|
40
|
+
}
|
|
41
|
+
return resolved;
|
|
42
|
+
}
|
|
43
|
+
export default createTool({
|
|
44
|
+
name: 'actual_transactions_aggregate',
|
|
45
|
+
description: [
|
|
46
|
+
'Deterministically aggregate posted transactions over an inclusive date range using integer cents.',
|
|
47
|
+
'Split parents are excluded and split children are counted once.',
|
|
48
|
+
'Transfers are identified only by transfer_id and never count as spending or income.',
|
|
49
|
+
'Positive non-income-category transactions are credits; positive uncategorized transactions are reported separately as uncategorizedInflows.',
|
|
50
|
+
'groupBy accepts one dimension or an array of month, category, category_group, payee, and account.',
|
|
51
|
+
'includeIncome defaults to false. excludeTransfers defaults to true; when false, transfers stay in separate transferInflow and transferOutflow fields.',
|
|
52
|
+
'Amounts are in cents: $100.00 = 10000. Dates are YYYY-MM-DD.',
|
|
53
|
+
].join(' '),
|
|
54
|
+
schema: InputSchema,
|
|
55
|
+
handler: async (input) => {
|
|
56
|
+
const snapshot = await adapter.getFinancialAnalysisSnapshot({
|
|
57
|
+
startDate: input.startDate,
|
|
58
|
+
endDate: input.endDate,
|
|
59
|
+
});
|
|
60
|
+
const accountIds = await resolveIds(input.accountIds, 'account', snapshot.accounts);
|
|
61
|
+
const categoryIds = await resolveIds(input.categoryIds, 'category', snapshot.categories);
|
|
62
|
+
const categoryGroupIds = await resolveIds(input.categoryGroupIds, 'category_group', snapshot.categoryGroups);
|
|
63
|
+
const payeeIds = await resolveIds(input.payeeIds, 'payee', snapshot.payees);
|
|
64
|
+
const groupBy = (Array.isArray(input.groupBy) ? [...new Set(input.groupBy)] : [input.groupBy]);
|
|
65
|
+
return aggregateTransactions(snapshot, {
|
|
66
|
+
startDate: input.startDate,
|
|
67
|
+
endDate: input.endDate,
|
|
68
|
+
groupBy,
|
|
69
|
+
accountIds,
|
|
70
|
+
categoryIds,
|
|
71
|
+
categoryGroupIds,
|
|
72
|
+
payeeIds,
|
|
73
|
+
includeIncome: input.includeIncome,
|
|
74
|
+
excludeTransfers: input.excludeTransfers,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
examples: [
|
|
78
|
+
{
|
|
79
|
+
description: 'Total spending per category for a month, transfers excluded',
|
|
80
|
+
input: { startDate: '2025-01-01', endDate: '2025-01-31', groupBy: 'category', includeIncome: false, excludeTransfers: true },
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
description: 'Spending and income per month, transfers kept separate',
|
|
84
|
+
input: { startDate: '2025-01-01', endDate: '2025-03-31', groupBy: 'month', includeIncome: true, excludeTransfers: false },
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actual-mcp-server",
|
|
3
3
|
"displayName": "Actual MCP Server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0",
|
|
7
7
|
"npm": ">=10.0.0"
|
|
8
8
|
},
|
|
9
|
-
"description": "MCP server with
|
|
9
|
+
"description": "MCP server with 76 tools for AI-driven financial management with Actual Budget. HTTP and stdio transports for LibreChat, Claude Desktop, Cursor, VS Code, Gemini CLI",
|
|
10
10
|
"homepage": "https://github.com/agigante80/actual-mcp-server#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"verify-tools": "npm run build && node scripts/verify-tools.js",
|
|
31
31
|
"check:coverage": "node scripts/list-actual-api-methods.mjs",
|
|
32
32
|
"direct-sync": "node scripts/direct-sync/bank-sync-direct.mjs",
|
|
33
|
-
"test:unit-js": "node tests/unit/transactions_create.test.js && node tests/unit/generated_tools.smoke.test.js &&
|
|
33
|
+
"test:unit-js": "node tests/unit/transactions_create.test.js && node tests/unit/transactions_aggregate.test.js && node tests/unit/account_flow_summary.test.js && node tests/unit/generated_tools.smoke.test.js &&node tests/unit/schema_validation.test.js && node tests/unit/schema_json_openai_compat.test.js && node tests/unit/config_https_validation.test.js && node tests/unit/config_data_dir.test.js && node tests/unit/config_drift.test.js && node tests/unit/port_alignment.test.js && node tests/unit/dockerfile_data_dir_alignment.test.js && node tests/unit/unraid_template_alignment.test.js && node tests/unit/entrypoint_invariants.test.js && node tests/unit/e2e_spec_collection.test.js && node tests/unit/compose_profile_sync.test.js && node tests/unit/advertised_tools_sync.test.js && node tests/unit/knip_config.test.js && node tests/unit/readme_stats_sync.test.js && node tests/unit/config_insecure_upstream.test.js && node tests/unit/workflow_release_guards.test.js && node tests/unit/report_train_failure.test.js && node tests/unit/unit_chain_membership.test.js && node tests/unit/api_surface_drift.test.js && node tests/unit/write_effect_audit_staleness.test.js && node tests/unit/write_effect_audit_membership.test.js && node tests/unit/tool_annotations.test.js && node tests/unit/tool_id_schema_drift.test.js && node tests/unit/filter_id_resolution.test.js && node tests/unit/filter_id_tool_wiring.test.js && node tests/unit/api_coverage_baseline.test.js && node tests/unit/train_preflight.test.js && node tests/unit/verify_published_artifacts.test.js && node tests/unit/report_train_stale.test.js && node tests/unit/stdio_framing_check.test.js && node tests/unit/server_info.test.js && node tests/unit/transfers_create.test.js && node tests/unit/bot_target_branch.test.js && node tests/unit/auth_posture.test.js && node tests/unit/auth_posture_wiring.test.js && node tests/unit/auth-acl.test.js && node tests/unit/bug76.test.js && node tests/unit/budgets_setAmount.test.js && node tests/unit/budgets_hold_for_next_month.test.js && node tests/unit/budgets_transfer.test.js && node tests/unit/transactions_uncategorized.test.js && node tests/unit/httpServer_session_init.test.js && node tests/unit/httpServer_session_not_found.test.js && node tests/unit/manual_mcp_client_retry.test.js && node tests/unit/manual_mcp_client_session.test.js && node tests/unit/manual_mcp_client_circuit.test.js && node tests/unit/manual_runner_killswitch.test.js && node tests/unit/adapter_auth_rate_limit.test.js && node tests/unit/adapter_session_reuse.test.js && node tests/unit/retry_classifier.test.js && node tests/unit/adapter_module_surface.test.js && node tests/unit/adapter_nonidempotent_no_retry.test.js && node tests/unit/pool_liveness.test.js && node tests/unit/pool_shutdown_all.test.js && node tests/unit/query_where_operators.test.js && node tests/unit/query_run_validation.test.js && node tests/unit/adapter_with_write_session.test.js && node tests/unit/category_groups_delete.test.js && node tests/unit/rules_delete.test.js && node tests/unit/schedules_delete.test.js && node tests/unit/accounts_delete.test.js && node tests/unit/update_tools_not_found.test.js && node tests/unit/accounts_close.test.js && node tests/unit/accounts_reopen.test.js && node tests/unit/payees_delete.test.js && node tests/unit/payees_merge.test.js && node tests/unit/rules_create_or_update.test.js && node tests/unit/unhandled-rejection.test.js && node tests/unit/rejection-allowlist-purity.test.js && node tests/unit/httpServer_bearer_auth.test.js && node tests/unit/httpServer_oidc_audience.test.js && node tests/unit/httpServer_oidc_auth_verification.test.js && node tests/unit/httpServer_oidc_jwks_discovery.test.js && node tests/unit/httpServer_body_limit.test.js && node tests/unit/httpServer_bind_host.test.js && node tests/unit/adapter_write_pool_cooperation.test.js && node tests/unit/adapter_drain_listing_cache.test.js && node tests/unit/budget_acl_enforcement.test.js && node tests/unit/budget_selection_precondition.test.js && node tests/unit/budget_load_abandonment.test.js && node tests/unit/budget_loader_postcondition.test.js && node tests/unit/budget_loader_import_allowlist.test.js && node tests/unit/budget_import_tracking.test.js && node tests/unit/pool_shutdown_under_lock.test.js && node tests/unit/api_lock_affinity.test.js && node tests/unit/commit_message_closing_keyword.test.js && node tests/unit/write_queue_stranding.test.js && node tests/unit/write_queue_stranded_bound.test.js && node tests/unit/budget_preference_store.test.js && node tests/unit/budget_preference_restore.test.js && node tests/unit/tags_list.test.js && node tests/unit/tags_create.test.js && node tests/unit/tags_update.test.js && node tests/unit/tags_delete.test.js && node tests/unit/notes_get.test.js && node tests/unit/notes_update.test.js && node tests/unit/payees_common_list.test.js && node tests/unit/transactions_update_guard.test.js && node tests/unit/transactions_update_splits.test.js && node tests/unit/entities_search.test.js && node tests/unit/transactions_import_schema.test.js && node tests/unit/tool_schema_shape.test.js && node tests/unit/zod_error_format.test.js && node tests/unit/tool_count_sync.test.js && node tests/unit/stdio_transport.test.js && node tests/unit/stdio_budget_switch.test.js && node tests/unit/logger_structured.test.js && node tests/unit/logger_redaction.test.js && node tests/unit/logger_correlation.test.js && node tests/unit/check_coverage.test.js && node tests/unit/adapter_op_timeout.test.js && node tests/unit/adapter_write_queue_wakeup.test.js && node tests/unit/ci_workflow_guards.test.js && node tests/unit/node_version_guard.test.js && node tests/unit/node_version_drift.test.js && node tests/unit/playwright_version_drift.test.js && node tests/unit/observability_smoke.test.js && node tests/unit/residue_pattern.test.js && node tests/unit/dual_transport_gate.test.js && node tests/unit/manual_assertions_use_helper.test.js && node tests/unit/server_version_guard.test.js && node tests/unit/payee_rules_reference_filter.test.js && node tests/unit/oidc_metadata_discovery.test.js && node tests/unit/httpServer_oauth_metadata_route.test.js && node tests/unit/httpServer_mcp_info_route.test.js && node tests/unit/residue_sweep_balance_account.test.js && node tests/unit/tool_factory.test.js && node tests/unit/budget_registry_parse.test.js && node tests/unit/preferences_get.test.js && node tests/unit/budgets_export.test.js && node tests/unit/budgets_import.test.js && node tests/unit/budgets_import_syncid.test.js && node tests/unit/budget_acl_dynamic.test.js && node tests/unit/budget_acl_identity_map.test.js && node tests/unit/budget_acl_userinfo.test.js && node tests/unit/acl_e2e_fixture_contract.test.js && node tests/unit/budget_acl_middleware.test.js && node tests/unit/rules_stage.test.js",
|
|
34
34
|
"test:adapter": "npm run build && node dist/src/tests_adapter_runner.js",
|
|
35
35
|
"test:e2e": "npx playwright test",
|
|
36
36
|
"test:e2e:docker": "./tests/e2e/run-docker-e2e.sh",
|