@baruchiro/actual-mcp
Version:
Actual Budget MCP server exposing API functionality
37 lines • 1.35 kB
JavaScript
// ----------------------------
// GET ACCOUNTS TOOL
// ----------------------------
import { successWithJson, errorFromCatch } from '../../utils/response.js';
import { fetchAllAccounts } from '../../core/data/fetch-accounts.js';
import { getAccountBalance } from '@actual-app/api';
import { formatAmount } from '../../utils.js';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
// Define an empty schema with zod
const GetAccountsArgsSchema = z.object({});
export const schema = {
name: 'get-accounts',
description: 'Retrieve a list of all accounts with their current balance and ID.',
inputSchema: zodToJsonSchema(GetAccountsArgsSchema),
};
export async function handler() {
try {
const accounts = await fetchAllAccounts();
for (const account of accounts) {
account.balance = await getAccountBalance(account.id);
}
const structured = accounts.map((account) => ({
id: account.id,
name: account.name,
type: account.type || 'Account',
balance: formatAmount(account.balance),
closed: account.closed,
offBudget: account.offbudget,
}));
return successWithJson(structured);
}
catch (err) {
return errorFromCatch(err);
}
}
//# sourceMappingURL=index.js.map