Skip to main content
Glama
index.ts1.45 kB
// ---------------------------- // GET ACCOUNTS TOOL // ---------------------------- import { successWithJson, errorFromCatch } from '../../utils/response.js'; import { fetchAllAccounts } from '../../core/data/fetch-accounts.js'; import type { Account } from '../../core/types/domain.js'; import { getAccountBalance } from '@actual-app/api'; import { formatAmount } from '../../utils.js'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; import { type ToolInput } from '../../types.js'; // 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) as ToolInput, }; export async function handler(): Promise<ReturnType<typeof successWithJson> | ReturnType<typeof errorFromCatch>> { try { const accounts: Account[] = 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); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/s-stefanov/actual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server