@dizzlkheinz/ynab-mcpb 0.16.0 → 0.17.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/.code/agents/0098661e-0fa3-4990-beb9-c0cbf3f123aa/status.txt +1 -0
- package/.code/agents/1324/exec-call_tIpx9uV1TpARbAMZonRQm8AO.txt +757 -0
- package/.code/agents/1572/exec-call_GjVFBFOWcY7lE0idc5nWlLNh.txt +781 -0
- package/.code/agents/1846/exec-call_1YNAVD18RjrMN7JnfkkQhUP3.txt +766 -0
- package/.code/agents/1846/exec-call_lh3lDzE4WJAh1lFiomiiZ73D.txt +766 -0
- package/.code/agents/2038/exec-call_DYwOukaYsL8VCONWmV2rUW5u.txt +766 -0
- package/.code/agents/2038/exec-call_c7fOQ7UrpVcTtvdfGBRM146V.txt +652 -0
- package/.code/agents/2038/exec-call_ySNyq9Mm55jWE480s54r5QcA.txt +766 -0
- package/.code/agents/2256/exec-call_AtPcRWPmFPMcmX6qOFm1fCEY.txt +766 -0
- package/.code/agents/2454/exec-call_aFJpupwjfZeOBm7ixI5Vc8z2.txt +766 -0
- package/.code/agents/2454/exec-call_wogZ4HfXTodTEXvdgXlVUBpv.txt +766 -0
- package/.code/agents/2e905864-aa07-4314-bcf9-c5b32277e4ac/result.txt +36 -0
- package/.code/agents/3073/exec-call_Peeagc9DxGYLgE6pNdMZhqIE.txt +766 -0
- package/.code/agents/3073/exec-call_d2YSE3hXF08KRSoUM3qd8Z3x.txt +766 -0
- package/.code/agents/335aa031-466d-4fb7-925f-3cd864e264d0/result.txt +191 -0
- package/.code/agents/3364/exec-call_NbhIrsM5HhyDZDmJZG5CuCYL.txt +766 -0
- package/.code/agents/3364/exec-call_cKtJg0NrXiwXEFwlsE3uPZRA.txt +766 -0
- package/.code/agents/36d98414-5cde-4d9d-9a67-a240a18c1f07/result.txt +189 -0
- package/.code/agents/4604e866-b7b8-44f5-992f-2f683b0a523b/status.txt +1 -0
- package/.code/agents/5f8dc01c-47b3-4163-b0b3-aa31be89fcdc/status.txt +1 -0
- package/.code/agents/7/exec-call_HltHpkDox0Zm1vGEjdksUgpE.txt +1120 -0
- package/.code/agents/7/exec-call_LCATrOPPAgbxW9Q1z0XaVi2E.txt +2646 -0
- package/.code/agents/7/exec-call_W8DeRfNG9hvbgVFvf0clBf6R.txt +2646 -0
- package/.code/agents/94a0ddf3-a304-4ec3-913e-3cceef509948/error.txt +1 -0
- package/.code/agents/e2c752b7-711d-423a-af57-f53c809deb84/result.txt +160 -0
- package/.code/agents/e6601719-c31f-4a0e-8c71-d70787d0ab71/status.txt +1 -0
- package/.code/agents/f250b7ed-5bd5-4036-aa8c-ce63caee7d61/result.txt +20 -0
- package/AGENTS.md +1 -36
- package/CLAUDE.md +131 -51
- package/NUL +0 -1
- package/README.md +27 -14
- package/dist/bundle/index.cjs +41 -41
- package/dist/server/YNABMCPServer.js +28 -381
- package/dist/server/config.d.ts +2 -0
- package/dist/server/config.js +1 -0
- package/dist/tools/accountTools.d.ts +2 -0
- package/dist/tools/accountTools.js +45 -0
- package/dist/tools/adapters.d.ts +12 -0
- package/dist/tools/adapters.js +25 -0
- package/dist/tools/budgetTools.d.ts +2 -0
- package/dist/tools/budgetTools.js +30 -0
- package/dist/tools/categoryTools.d.ts +2 -0
- package/dist/tools/categoryTools.js +45 -0
- package/dist/tools/monthTools.d.ts +2 -0
- package/dist/tools/monthTools.js +32 -0
- package/dist/tools/payeeTools.d.ts +2 -0
- package/dist/tools/payeeTools.js +32 -0
- package/dist/tools/reconciliation/index.d.ts +2 -0
- package/dist/tools/reconciliation/index.js +33 -0
- package/dist/tools/schemas/common.d.ts +3 -0
- package/dist/tools/schemas/common.js +3 -0
- package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
- package/dist/tools/transactionTools.d.ts +2 -0
- package/dist/tools/transactionTools.js +129 -0
- package/dist/tools/utilityTools.d.ts +3 -1
- package/dist/tools/utilityTools.js +32 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/toolRegistration.d.ts +27 -0
- package/dist/types/toolRegistration.js +1 -0
- package/package.json +2 -2
- package/scripts/run-domain-integration-tests.js +4 -1
- package/src/__tests__/workflows.e2e.test.ts +1 -7
- package/src/server/YNABMCPServer.ts +33 -519
- package/src/server/__tests__/toolRegistration.test.ts +236 -0
- package/src/server/config.ts +1 -0
- package/src/tools/__tests__/adapters.test.ts +113 -0
- package/src/tools/__tests__/transactionTools.test.ts +90 -17
- package/src/tools/__tests__/utilityTools.test.ts +7 -7
- package/src/tools/accountTools.ts +53 -0
- package/src/tools/adapters.ts +74 -0
- package/src/tools/budgetTools.ts +37 -0
- package/src/tools/categoryTools.ts +53 -0
- package/src/tools/monthTools.ts +39 -0
- package/src/tools/payeeTools.ts +39 -0
- package/src/tools/reconciliation/index.ts +45 -0
- package/src/tools/schemas/common.ts +18 -0
- package/src/tools/transactionTools.ts +150 -0
- package/src/tools/utilityTools.ts +42 -2
- package/src/types/index.ts +3 -0
- package/src/types/toolRegistration.ts +88 -0
- package/.dxtignore +0 -57
- package/.github/workflows/pr-description-check.yml +0 -88
- package/CODEREVIEW_RESPONSE.md +0 -128
- package/SCHEMA_IMPROVEMENT_SUMMARY.md +0 -120
- package/TESTING_NOTES.md +0 -217
- package/accountactivity-merged.csv +0 -149
- package/bundle-analysis.html +0 -13110
- package/docs/README.md +0 -72
- package/docs/getting-started/CONFIGURATION.md +0 -175
- package/docs/getting-started/INSTALLATION.md +0 -333
- package/docs/getting-started/QUICKSTART.md +0 -282
- package/docs/guides/ARCHITECTURE.md +0 -533
- package/docs/guides/DEPLOYMENT.md +0 -189
- package/docs/guides/INTEGRATION_TESTING.md +0 -730
- package/docs/guides/TESTING.md +0 -591
- package/docs/plans/2025-11-20-reloadable-config-token-validation.md +0 -93
- package/docs/plans/2025-11-21-fix-transaction-cached-property.md +0 -362
- package/docs/plans/2025-11-21-reconciliation-error-handling.md +0 -90
- package/docs/plans/2025-11-21-v014-hardening.md +0 -153
- package/docs/plans/reconciliation-v2-redesign.md +0 -1571
- package/docs/reconciliation-flow.md +0 -83
- package/docs/reference/EXAMPLES.md +0 -946
- package/docs/reference/TOOLS.md +0 -348
- package/docs/reference/TROUBLESHOOTING.md +0 -481
- package/fix-types.sh +0 -17
- package/test-csv-sample.csv +0 -28
- package/test-exports/sample_bank_statement.csv +0 -7
- package/test-reconcile-autodetect.js +0 -40
- package/test-reconcile-tool.js +0 -152
- package/test-reconcile-with-csv.cjs +0 -89
- package/test-statement.csv +0 -8
- package/test_debug.js +0 -47
- package/test_mcp_tools.mjs +0 -75
- package/test_simple.mjs +0 -16
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Adapter utilities for tool factory functions.
|
|
3
|
+
* Provides createAdapters() to reduce boilerplate when registering tools,
|
|
4
|
+
* and createBudgetResolver() for consistent budget ID resolution.
|
|
5
|
+
* @module tools/adapters
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import type { ToolExecutionPayload, DefaultArgumentResolver } from '../server/toolRegistry.js';
|
|
10
|
+
import { BudgetResolver } from '../server/budgetResolver.js';
|
|
11
|
+
import { DefaultArgumentResolutionError } from '../server/toolRegistry.js';
|
|
12
|
+
import type {
|
|
13
|
+
ToolContext,
|
|
14
|
+
Handler,
|
|
15
|
+
DeltaHandler,
|
|
16
|
+
WriteHandler,
|
|
17
|
+
NoInputHandler,
|
|
18
|
+
} from '../types/toolRegistration.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates adapter functions bound to the provided context. These helpers reduce
|
|
22
|
+
* boilerplate inside tool factory modules by partially applying shared
|
|
23
|
+
* dependencies to handlers.
|
|
24
|
+
*/
|
|
25
|
+
export function createAdapters(context: ToolContext) {
|
|
26
|
+
const { ynabAPI, deltaFetcher, deltaCache, serverKnowledgeStore } = context;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
adapt:
|
|
30
|
+
<TInput extends Record<string, unknown>>(handler: Handler<TInput>) =>
|
|
31
|
+
async ({ input }: ToolExecutionPayload<TInput>): Promise<CallToolResult> =>
|
|
32
|
+
handler(ynabAPI, input),
|
|
33
|
+
|
|
34
|
+
adaptNoInput:
|
|
35
|
+
(handler: NoInputHandler) =>
|
|
36
|
+
async (_payload: ToolExecutionPayload<Record<string, unknown>>): Promise<CallToolResult> =>
|
|
37
|
+
handler(ynabAPI),
|
|
38
|
+
|
|
39
|
+
adaptWithDelta:
|
|
40
|
+
<TInput extends Record<string, unknown>>(handler: DeltaHandler<TInput>) =>
|
|
41
|
+
async ({ input }: ToolExecutionPayload<TInput>): Promise<CallToolResult> =>
|
|
42
|
+
handler(ynabAPI, deltaFetcher, input),
|
|
43
|
+
|
|
44
|
+
adaptWrite:
|
|
45
|
+
<TInput extends Record<string, unknown>>(handler: WriteHandler<TInput>) =>
|
|
46
|
+
async ({ input }: ToolExecutionPayload<TInput>): Promise<CallToolResult> =>
|
|
47
|
+
handler(ynabAPI, deltaCache, serverKnowledgeStore, input),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a budget ID resolver bound to the provided context. The returned
|
|
53
|
+
* resolver matches the ToolRegistry defaultArgumentResolver signature.
|
|
54
|
+
*/
|
|
55
|
+
export function createBudgetResolver(
|
|
56
|
+
context: ToolContext,
|
|
57
|
+
): <TInput extends { budget_id?: string | undefined }>() => DefaultArgumentResolver<TInput> {
|
|
58
|
+
return <TInput extends { budget_id?: string | undefined }>(): DefaultArgumentResolver<TInput> => {
|
|
59
|
+
return ({ rawArguments }) => {
|
|
60
|
+
const provided =
|
|
61
|
+
typeof rawArguments['budget_id'] === 'string' && rawArguments['budget_id'].length > 0
|
|
62
|
+
? rawArguments['budget_id']
|
|
63
|
+
: undefined;
|
|
64
|
+
|
|
65
|
+
const result = BudgetResolver.resolveBudgetId(provided, context.getDefaultBudgetId());
|
|
66
|
+
|
|
67
|
+
if (typeof result === 'string') {
|
|
68
|
+
return { budget_id: result } as Partial<TInput>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new DefaultArgumentResolutionError(result);
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
package/src/tools/budgetTools.ts
CHANGED
|
@@ -5,6 +5,10 @@ import { withToolErrorHandling } from '../types/index.js';
|
|
|
5
5
|
import { responseFormatter } from '../server/responseFormatter.js';
|
|
6
6
|
import type { DeltaFetcher } from './deltaFetcher.js';
|
|
7
7
|
import { resolveDeltaFetcherArgs } from './deltaSupport.js';
|
|
8
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
9
|
+
import { createAdapters } from './adapters.js';
|
|
10
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
11
|
+
import { emptyObjectSchema } from './schemas/common.js';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Schema for ynab:get_budget tool parameters
|
|
@@ -110,3 +114,36 @@ export async function handleGetBudget(
|
|
|
110
114
|
'getting budget details',
|
|
111
115
|
);
|
|
112
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Registers all budget-related tools with the provided registry.
|
|
120
|
+
*/
|
|
121
|
+
export const registerBudgetTools: ToolFactory = (registry, context) => {
|
|
122
|
+
const { adapt, adaptWithDelta } = createAdapters(context);
|
|
123
|
+
|
|
124
|
+
registry.register({
|
|
125
|
+
name: 'list_budgets',
|
|
126
|
+
description: "List all budgets associated with the user's account",
|
|
127
|
+
inputSchema: emptyObjectSchema,
|
|
128
|
+
handler: adaptWithDelta(handleListBudgets),
|
|
129
|
+
metadata: {
|
|
130
|
+
annotations: {
|
|
131
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
132
|
+
title: 'YNAB: List Budgets',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
registry.register({
|
|
138
|
+
name: 'get_budget',
|
|
139
|
+
description: 'Get detailed information for a specific budget',
|
|
140
|
+
inputSchema: GetBudgetSchema,
|
|
141
|
+
handler: adapt(handleGetBudget),
|
|
142
|
+
metadata: {
|
|
143
|
+
annotations: {
|
|
144
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
145
|
+
title: 'YNAB: Get Budget Details',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
};
|
|
@@ -10,6 +10,9 @@ import type { DeltaCache } from '../server/deltaCache.js';
|
|
|
10
10
|
import type { ServerKnowledgeStore } from '../server/serverKnowledgeStore.js';
|
|
11
11
|
import { CacheKeys } from '../server/cacheKeys.js';
|
|
12
12
|
import { resolveDeltaFetcherArgs, resolveDeltaWriteArgs } from './deltaSupport.js';
|
|
13
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
14
|
+
import { createAdapters, createBudgetResolver } from './adapters.js';
|
|
15
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Schema for ynab:list_categories tool parameters
|
|
@@ -336,6 +339,56 @@ export async function handleUpdateCategory(
|
|
|
336
339
|
}
|
|
337
340
|
}
|
|
338
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Registers all category-related tools with the registry.
|
|
344
|
+
*/
|
|
345
|
+
export const registerCategoryTools: ToolFactory = (registry, context) => {
|
|
346
|
+
const { adapt, adaptWithDelta, adaptWrite } = createAdapters(context);
|
|
347
|
+
const budgetResolver = createBudgetResolver(context);
|
|
348
|
+
|
|
349
|
+
registry.register({
|
|
350
|
+
name: 'list_categories',
|
|
351
|
+
description: 'List all categories for a specific budget',
|
|
352
|
+
inputSchema: ListCategoriesSchema,
|
|
353
|
+
handler: adaptWithDelta(handleListCategories),
|
|
354
|
+
defaultArgumentResolver: budgetResolver<ListCategoriesParams>(),
|
|
355
|
+
metadata: {
|
|
356
|
+
annotations: {
|
|
357
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
358
|
+
title: 'YNAB: List Categories',
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
registry.register({
|
|
364
|
+
name: 'get_category',
|
|
365
|
+
description: 'Get detailed information for a specific category',
|
|
366
|
+
inputSchema: GetCategorySchema,
|
|
367
|
+
handler: adapt(handleGetCategory),
|
|
368
|
+
defaultArgumentResolver: budgetResolver<GetCategoryParams>(),
|
|
369
|
+
metadata: {
|
|
370
|
+
annotations: {
|
|
371
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
372
|
+
title: 'YNAB: Get Category Details',
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
registry.register({
|
|
378
|
+
name: 'update_category',
|
|
379
|
+
description: 'Update the budgeted amount for a category in the current month',
|
|
380
|
+
inputSchema: UpdateCategorySchema,
|
|
381
|
+
handler: adaptWrite(handleUpdateCategory),
|
|
382
|
+
defaultArgumentResolver: budgetResolver<UpdateCategoryParams>(),
|
|
383
|
+
metadata: {
|
|
384
|
+
annotations: {
|
|
385
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_UPDATE,
|
|
386
|
+
title: 'YNAB: Update Category Budget',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
|
|
339
392
|
/**
|
|
340
393
|
* Handles errors from category-related API calls
|
|
341
394
|
*/
|
package/src/tools/monthTools.ts
CHANGED
|
@@ -8,6 +8,9 @@ import { cacheManager, CACHE_TTLS, CacheManager } from '../server/cacheManager.j
|
|
|
8
8
|
import type { DeltaFetcher } from './deltaFetcher.js';
|
|
9
9
|
import { CacheKeys } from '../server/cacheKeys.js';
|
|
10
10
|
import { resolveDeltaFetcherArgs } from './deltaSupport.js';
|
|
11
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
12
|
+
import { createAdapters, createBudgetResolver } from './adapters.js';
|
|
13
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Schema for ynab:get_month tool parameters
|
|
@@ -168,3 +171,39 @@ export async function handleListMonths(
|
|
|
168
171
|
'listing months',
|
|
169
172
|
);
|
|
170
173
|
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Registers all month-related tools with the registry.
|
|
177
|
+
*/
|
|
178
|
+
export const registerMonthTools: ToolFactory = (registry, context) => {
|
|
179
|
+
const { adapt, adaptWithDelta } = createAdapters(context);
|
|
180
|
+
const budgetResolver = createBudgetResolver(context);
|
|
181
|
+
|
|
182
|
+
registry.register({
|
|
183
|
+
name: 'get_month',
|
|
184
|
+
description: 'Get budget data for a specific month',
|
|
185
|
+
inputSchema: GetMonthSchema,
|
|
186
|
+
handler: adapt(handleGetMonth),
|
|
187
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof GetMonthSchema>>(),
|
|
188
|
+
metadata: {
|
|
189
|
+
annotations: {
|
|
190
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
191
|
+
title: 'YNAB: Get Month Details',
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
registry.register({
|
|
197
|
+
name: 'list_months',
|
|
198
|
+
description: 'List all months summary data for a budget',
|
|
199
|
+
inputSchema: ListMonthsSchema,
|
|
200
|
+
handler: adaptWithDelta(handleListMonths),
|
|
201
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof ListMonthsSchema>>(),
|
|
202
|
+
metadata: {
|
|
203
|
+
annotations: {
|
|
204
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
205
|
+
title: 'YNAB: List Months',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
};
|
package/src/tools/payeeTools.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { cacheManager, CACHE_TTLS, CacheManager } from '../server/cacheManager.j
|
|
|
7
7
|
import type { DeltaFetcher } from './deltaFetcher.js';
|
|
8
8
|
import { CacheKeys } from '../server/cacheKeys.js';
|
|
9
9
|
import { resolveDeltaFetcherArgs } from './deltaSupport.js';
|
|
10
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
11
|
+
import { createAdapters, createBudgetResolver } from './adapters.js';
|
|
12
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Schema for ynab:list_payees tool parameters
|
|
@@ -144,3 +147,39 @@ export async function handleGetPayee(
|
|
|
144
147
|
'getting payee details',
|
|
145
148
|
);
|
|
146
149
|
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Registers all payee-related tools with the registry.
|
|
153
|
+
*/
|
|
154
|
+
export const registerPayeeTools: ToolFactory = (registry, context) => {
|
|
155
|
+
const { adapt, adaptWithDelta } = createAdapters(context);
|
|
156
|
+
const budgetResolver = createBudgetResolver(context);
|
|
157
|
+
|
|
158
|
+
registry.register({
|
|
159
|
+
name: 'list_payees',
|
|
160
|
+
description: 'List all payees for a specific budget',
|
|
161
|
+
inputSchema: ListPayeesSchema,
|
|
162
|
+
handler: adaptWithDelta(handleListPayees),
|
|
163
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof ListPayeesSchema>>(),
|
|
164
|
+
metadata: {
|
|
165
|
+
annotations: {
|
|
166
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
167
|
+
title: 'YNAB: List Payees',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
registry.register({
|
|
173
|
+
name: 'get_payee',
|
|
174
|
+
description: 'Get detailed information for a specific payee',
|
|
175
|
+
inputSchema: GetPayeeSchema,
|
|
176
|
+
handler: adapt(handleGetPayee),
|
|
177
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof GetPayeeSchema>>(),
|
|
178
|
+
metadata: {
|
|
179
|
+
annotations: {
|
|
180
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
181
|
+
title: 'YNAB: Get Payee Details',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
};
|
|
@@ -8,6 +8,13 @@ import { z } from 'zod/v4';
|
|
|
8
8
|
import type * as ynab from 'ynab';
|
|
9
9
|
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
10
10
|
import { withToolErrorHandling } from '../../types/index.js';
|
|
11
|
+
import type { ToolFactory } from '../../types/toolRegistration.js';
|
|
12
|
+
import { createAdapters, createBudgetResolver } from '../adapters.js';
|
|
13
|
+
import { ToolAnnotationPresets } from '../toolCategories.js';
|
|
14
|
+
import {
|
|
15
|
+
CompareTransactionsSchema,
|
|
16
|
+
handleCompareTransactions,
|
|
17
|
+
} from '../compareTransactions/index.js';
|
|
11
18
|
import { analyzeReconciliation } from './analyzer.js';
|
|
12
19
|
import type { MatchingConfig } from './matcher.js';
|
|
13
20
|
import { buildReconciliationPayload } from '../reconcileAdapter.js';
|
|
@@ -457,6 +464,44 @@ export async function handleReconcileAccount(
|
|
|
457
464
|
);
|
|
458
465
|
}
|
|
459
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Registers reconciliation-domain tools (compare + reconcile) with the registry.
|
|
469
|
+
*/
|
|
470
|
+
export const registerReconciliationTools: ToolFactory = (registry, context) => {
|
|
471
|
+
const { adapt, adaptWithDelta } = createAdapters(context);
|
|
472
|
+
const budgetResolver = createBudgetResolver(context);
|
|
473
|
+
|
|
474
|
+
registry.register({
|
|
475
|
+
name: 'compare_transactions',
|
|
476
|
+
description:
|
|
477
|
+
'Compare bank transactions from CSV with YNAB transactions to find missing entries',
|
|
478
|
+
inputSchema: CompareTransactionsSchema,
|
|
479
|
+
handler: adapt(handleCompareTransactions),
|
|
480
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof CompareTransactionsSchema>>(),
|
|
481
|
+
metadata: {
|
|
482
|
+
annotations: {
|
|
483
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
484
|
+
title: 'YNAB: Compare Transactions',
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
registry.register({
|
|
490
|
+
name: 'reconcile_account',
|
|
491
|
+
description:
|
|
492
|
+
'Guided reconciliation workflow with human narrative, insight detection, and optional execution (create/update/unclear). Set include_structured_data=true to also get full JSON output (large).',
|
|
493
|
+
inputSchema: ReconcileAccountSchema,
|
|
494
|
+
handler: adaptWithDelta(handleReconcileAccount),
|
|
495
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof ReconcileAccountSchema>>(),
|
|
496
|
+
metadata: {
|
|
497
|
+
annotations: {
|
|
498
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_UPDATE,
|
|
499
|
+
title: 'YNAB: Reconcile Account',
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
|
|
460
505
|
function mapCsvDateFormatToHint(
|
|
461
506
|
format: string | undefined,
|
|
462
507
|
): ParseCSVOptions['dateFormat'] | undefined {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared Zod schemas used across multiple tool domains.
|
|
3
|
+
* @module tools/schemas/common
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Strict empty object schema used for tools that do not accept input params.
|
|
10
|
+
* Examples: list_budgets, get_user, get_default_budget, clear_cache
|
|
11
|
+
*/
|
|
12
|
+
export const emptyObjectSchema = z.object({}).strict();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Permissive object schema used when hosts require a top-level object but we
|
|
16
|
+
* intentionally allow passthrough properties (e.g., mutation tool outputs).
|
|
17
|
+
*/
|
|
18
|
+
export const looseObjectSchema = z.object({}).passthrough();
|
|
@@ -6,6 +6,9 @@ import type { SaveTransactionsResponseData } from 'ynab/dist/models/SaveTransact
|
|
|
6
6
|
import { z } from 'zod/v4';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
8
8
|
import { ValidationError, withToolErrorHandling } from '../types/index.js';
|
|
9
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
10
|
+
import { createAdapters, createBudgetResolver } from './adapters.js';
|
|
11
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
9
12
|
import { responseFormatter } from '../server/responseFormatter.js';
|
|
10
13
|
import { amountToMilliunits, milliunitsToAmount } from '../utils/amountUtils.js';
|
|
11
14
|
import { cacheManager, CACHE_TTLS, CacheManager } from '../server/cacheManager.js';
|
|
@@ -14,6 +17,7 @@ import type { DeltaFetcher } from './deltaFetcher.js';
|
|
|
14
17
|
import type { DeltaCache } from '../server/deltaCache.js';
|
|
15
18
|
import type { ServerKnowledgeStore } from '../server/serverKnowledgeStore.js';
|
|
16
19
|
import { resolveDeltaFetcherArgs, resolveDeltaWriteArgs } from './deltaSupport.js';
|
|
20
|
+
import { handleExportTransactions, ExportTransactionsSchema } from './exportTransactions.js';
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Utility function to ensure transaction is not null/undefined
|
|
@@ -755,6 +759,16 @@ export async function handleListTransactions(
|
|
|
755
759
|
let usedDelta = false;
|
|
756
760
|
|
|
757
761
|
if (params.account_id) {
|
|
762
|
+
// Validate that the account exists before fetching transactions
|
|
763
|
+
// YNAB API returns empty array for invalid account IDs instead of an error
|
|
764
|
+
const accountsResult = await deltaFetcher.fetchAccounts(params.budget_id);
|
|
765
|
+
const accountExists = accountsResult.data.some(
|
|
766
|
+
(account) => account.id === params.account_id,
|
|
767
|
+
);
|
|
768
|
+
if (!accountExists) {
|
|
769
|
+
throw new Error(`Account ${params.account_id} not found in budget ${params.budget_id}`);
|
|
770
|
+
}
|
|
771
|
+
|
|
758
772
|
const result = await deltaFetcher.fetchTransactionsByAccount(
|
|
759
773
|
params.budget_id,
|
|
760
774
|
params.account_id,
|
|
@@ -2496,3 +2510,139 @@ function handleTransactionError(error: unknown, defaultMessage: string): CallToo
|
|
|
2496
2510
|
],
|
|
2497
2511
|
};
|
|
2498
2512
|
}
|
|
2513
|
+
|
|
2514
|
+
/**
|
|
2515
|
+
* Registers transaction-domain tools with the provided registry.
|
|
2516
|
+
*/
|
|
2517
|
+
export const registerTransactionTools: ToolFactory = (registry, context) => {
|
|
2518
|
+
const { adapt, adaptWithDelta, adaptWrite } = createAdapters(context);
|
|
2519
|
+
const budgetResolver = createBudgetResolver(context);
|
|
2520
|
+
|
|
2521
|
+
registry.register({
|
|
2522
|
+
name: 'list_transactions',
|
|
2523
|
+
description: 'List transactions for a budget with optional filtering',
|
|
2524
|
+
inputSchema: ListTransactionsSchema,
|
|
2525
|
+
handler: adaptWithDelta(handleListTransactions),
|
|
2526
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof ListTransactionsSchema>>(),
|
|
2527
|
+
metadata: {
|
|
2528
|
+
annotations: {
|
|
2529
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
2530
|
+
title: 'YNAB: List Transactions',
|
|
2531
|
+
},
|
|
2532
|
+
},
|
|
2533
|
+
});
|
|
2534
|
+
|
|
2535
|
+
registry.register({
|
|
2536
|
+
name: 'export_transactions',
|
|
2537
|
+
description: 'Export all transactions to a JSON file with descriptive filename',
|
|
2538
|
+
inputSchema: ExportTransactionsSchema,
|
|
2539
|
+
handler: adapt(handleExportTransactions),
|
|
2540
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof ExportTransactionsSchema>>(),
|
|
2541
|
+
metadata: {
|
|
2542
|
+
annotations: {
|
|
2543
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
2544
|
+
title: 'YNAB: Export Transactions',
|
|
2545
|
+
},
|
|
2546
|
+
},
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
registry.register({
|
|
2550
|
+
name: 'get_transaction',
|
|
2551
|
+
description: 'Get detailed information for a specific transaction',
|
|
2552
|
+
inputSchema: GetTransactionSchema,
|
|
2553
|
+
handler: adapt(handleGetTransaction),
|
|
2554
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof GetTransactionSchema>>(),
|
|
2555
|
+
metadata: {
|
|
2556
|
+
annotations: {
|
|
2557
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
2558
|
+
title: 'YNAB: Get Transaction Details',
|
|
2559
|
+
},
|
|
2560
|
+
},
|
|
2561
|
+
});
|
|
2562
|
+
|
|
2563
|
+
registry.register({
|
|
2564
|
+
name: 'create_transaction',
|
|
2565
|
+
description: 'Create a new transaction in the specified budget and account',
|
|
2566
|
+
inputSchema: CreateTransactionSchema,
|
|
2567
|
+
handler: adaptWrite(handleCreateTransaction),
|
|
2568
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof CreateTransactionSchema>>(),
|
|
2569
|
+
metadata: {
|
|
2570
|
+
annotations: {
|
|
2571
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_CREATE,
|
|
2572
|
+
title: 'YNAB: Create Transaction',
|
|
2573
|
+
},
|
|
2574
|
+
},
|
|
2575
|
+
});
|
|
2576
|
+
|
|
2577
|
+
registry.register({
|
|
2578
|
+
name: 'create_transactions',
|
|
2579
|
+
description:
|
|
2580
|
+
'Create multiple transactions in a single batch (1-100 items) with duplicate detection, dry-run validation, and automatic response size management with correlation metadata.',
|
|
2581
|
+
inputSchema: CreateTransactionsSchema,
|
|
2582
|
+
handler: adaptWrite(handleCreateTransactions),
|
|
2583
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof CreateTransactionsSchema>>(),
|
|
2584
|
+
metadata: {
|
|
2585
|
+
annotations: {
|
|
2586
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_CREATE,
|
|
2587
|
+
title: 'YNAB: Create Multiple Transactions',
|
|
2588
|
+
},
|
|
2589
|
+
},
|
|
2590
|
+
});
|
|
2591
|
+
|
|
2592
|
+
registry.register({
|
|
2593
|
+
name: 'create_receipt_split_transaction',
|
|
2594
|
+
description: 'Create a split transaction from receipt items with proportional tax allocation',
|
|
2595
|
+
inputSchema: CreateReceiptSplitTransactionSchema,
|
|
2596
|
+
handler: adaptWrite(handleCreateReceiptSplitTransaction),
|
|
2597
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof CreateReceiptSplitTransactionSchema>>(),
|
|
2598
|
+
metadata: {
|
|
2599
|
+
annotations: {
|
|
2600
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_CREATE,
|
|
2601
|
+
title: 'YNAB: Create Split Transaction from Receipt',
|
|
2602
|
+
},
|
|
2603
|
+
},
|
|
2604
|
+
});
|
|
2605
|
+
|
|
2606
|
+
registry.register({
|
|
2607
|
+
name: 'update_transaction',
|
|
2608
|
+
description: 'Update an existing transaction',
|
|
2609
|
+
inputSchema: UpdateTransactionSchema,
|
|
2610
|
+
handler: adaptWrite(handleUpdateTransaction),
|
|
2611
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof UpdateTransactionSchema>>(),
|
|
2612
|
+
metadata: {
|
|
2613
|
+
annotations: {
|
|
2614
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_UPDATE,
|
|
2615
|
+
title: 'YNAB: Update Transaction',
|
|
2616
|
+
},
|
|
2617
|
+
},
|
|
2618
|
+
});
|
|
2619
|
+
|
|
2620
|
+
registry.register({
|
|
2621
|
+
name: 'update_transactions',
|
|
2622
|
+
description:
|
|
2623
|
+
'Update multiple transactions in a single batch (1-100 items) with dry-run validation, automatic cache invalidation, and response size management. Supports optional original_account_id and original_date metadata for efficient cache invalidation.',
|
|
2624
|
+
inputSchema: UpdateTransactionsSchema,
|
|
2625
|
+
handler: adaptWrite(handleUpdateTransactions),
|
|
2626
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof UpdateTransactionsSchema>>(),
|
|
2627
|
+
metadata: {
|
|
2628
|
+
annotations: {
|
|
2629
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_UPDATE,
|
|
2630
|
+
title: 'YNAB: Update Multiple Transactions',
|
|
2631
|
+
},
|
|
2632
|
+
},
|
|
2633
|
+
});
|
|
2634
|
+
|
|
2635
|
+
registry.register({
|
|
2636
|
+
name: 'delete_transaction',
|
|
2637
|
+
description: 'Delete a transaction from the specified budget',
|
|
2638
|
+
inputSchema: DeleteTransactionSchema,
|
|
2639
|
+
handler: adaptWrite(handleDeleteTransaction),
|
|
2640
|
+
defaultArgumentResolver: budgetResolver<z.infer<typeof DeleteTransactionSchema>>(),
|
|
2641
|
+
metadata: {
|
|
2642
|
+
annotations: {
|
|
2643
|
+
...ToolAnnotationPresets.WRITE_EXTERNAL_DELETE,
|
|
2644
|
+
title: 'YNAB: Delete Transaction',
|
|
2645
|
+
},
|
|
2646
|
+
},
|
|
2647
|
+
});
|
|
2648
|
+
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import * as ynab from 'ynab';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
|
-
import { withToolErrorHandling } from '../types/index.js';
|
|
5
4
|
import { responseFormatter } from '../server/responseFormatter.js';
|
|
5
|
+
import { withToolErrorHandling } from '../types/index.js';
|
|
6
|
+
import { createAdapters } from './adapters.js';
|
|
7
|
+
import { emptyObjectSchema } from './schemas/common.js';
|
|
8
|
+
import { ToolAnnotationPresets } from './toolCategories.js';
|
|
9
|
+
import type { ToolFactory } from '../types/toolRegistration.js';
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* Schema for ynab:convert_amount tool parameters
|
|
@@ -48,7 +52,10 @@ export async function handleGetUser(ynabAPI: ynab.API): Promise<CallToolResult>
|
|
|
48
52
|
* Handles the ynab:convert_amount tool call
|
|
49
53
|
* Converts between dollars and milliunits with integer arithmetic for precision
|
|
50
54
|
*/
|
|
51
|
-
export async function handleConvertAmount(
|
|
55
|
+
export async function handleConvertAmount(
|
|
56
|
+
_ynabAPI: ynab.API,
|
|
57
|
+
params: ConvertAmountParams,
|
|
58
|
+
): Promise<CallToolResult> {
|
|
52
59
|
return await withToolErrorHandling(
|
|
53
60
|
async () => {
|
|
54
61
|
const { amount, to_milliunits } = params;
|
|
@@ -88,3 +95,36 @@ export async function handleConvertAmount(params: ConvertAmountParams): Promise<
|
|
|
88
95
|
'converting amount',
|
|
89
96
|
);
|
|
90
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Registers utility tools (get_user, convert_amount) using the shared factory pattern.
|
|
101
|
+
*/
|
|
102
|
+
export const registerUtilityTools: ToolFactory = (registry, context) => {
|
|
103
|
+
const { adapt, adaptNoInput } = createAdapters(context);
|
|
104
|
+
|
|
105
|
+
registry.register({
|
|
106
|
+
name: 'get_user',
|
|
107
|
+
description: 'Get information about the authenticated user',
|
|
108
|
+
inputSchema: emptyObjectSchema,
|
|
109
|
+
handler: adaptNoInput(handleGetUser),
|
|
110
|
+
metadata: {
|
|
111
|
+
annotations: {
|
|
112
|
+
...ToolAnnotationPresets.READ_ONLY_EXTERNAL,
|
|
113
|
+
title: 'YNAB: Get User Information',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
registry.register({
|
|
119
|
+
name: 'convert_amount',
|
|
120
|
+
description: 'Convert between dollars and milliunits with integer arithmetic for precision',
|
|
121
|
+
inputSchema: ConvertAmountSchema,
|
|
122
|
+
handler: adapt(handleConvertAmount),
|
|
123
|
+
metadata: {
|
|
124
|
+
annotations: {
|
|
125
|
+
...ToolAnnotationPresets.UTILITY_LOCAL,
|
|
126
|
+
title: 'YNAB: Convert Amount',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -65,3 +65,6 @@ export type { MCPToolAnnotations } from './toolAnnotations.js';
|
|
|
65
65
|
|
|
66
66
|
// Re-export tool registry types for convenience
|
|
67
67
|
export type { ToolDefinition } from '../server/toolRegistry.js';
|
|
68
|
+
|
|
69
|
+
// Re-export tool registration factory types
|
|
70
|
+
export type { ToolContext, ToolFactory, BudgetIdResolverFactory } from './toolRegistration.js';
|