UNPKG

actual-mcp

Version:

Actual Budget MCP server exposing API functionality

42 lines 1.99 kB
// ---------------------------- // IMPORT TRANSACTIONS TOOL // ---------------------------- import { utils } from '@actual-app/api'; import { toJSONSchema } from 'zod'; import { success, errorFromCatch } from '../../utils/response.js'; import { importTransactions } from '../../actual-api.js'; import { ImportTransactionsArgsSchema } from '../../types.js'; export const schema = { name: 'import-transactions', description: 'Import a list of transactions into an account using reconciliation logic. ' + 'Deduplicates via imported_id to prevent duplicates on repeated imports. ' + 'Supports dry-run mode to preview changes without persisting them.', inputSchema: toJSONSchema(ImportTransactionsArgsSchema), }; export async function handler(args) { try { const { accountId, transactions, defaultCleared, dryRun } = ImportTransactionsArgsSchema.parse(args); // Reason: decimal amounts (e.g. 3.24) from the tool input are converted to integers (e.g. 324) // here before being passed to the API, which expects integer cents. const entities = transactions.map((t) => ({ ...t, account: accountId, amount: utils.amountToInteger(t.amount), subtransactions: t.subtransactions?.map((s) => ({ ...s, amount: utils.amountToInteger(s.amount), })), })); const result = await importTransactions(accountId, entities, { defaultCleared, dryRun }); const prefix = dryRun ? '[DRY RUN] ' : ''; const summary = `${prefix}Import complete.\n` + `Added: ${result.added.length} transaction(s)\n` + `Updated: ${result.updated.length} transaction(s)\n` + (result.errors.length > 0 ? `Errors: ${result.errors.map((e) => e.message).join(', ')}` : 'Errors: none'); return success(summary); } catch (err) { return errorFromCatch(err); } } //# sourceMappingURL=index.js.map