Skip to main content
Glama

add_balance

Add or edit one balance sheet line item by providing period, category, amount, and currency. Non-USD amounts are converted to USD using historical rates.

Instructions

Upsert a single balance sheet entry for a period (also edits — same composite key overwrites). Use this when recording just one or two balance items; prefer add_monthly for full month-end settlement. sub_type: cash|investment|other (assets) or short_term|long_term (liabilities). VALID BALANCE CATEGORIES — assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other. Use ONLY these category strings — do NOT invent your own. For non-USD users: pass currency as the native currency (e.g. "KRW") and amount in that currency — converted to USD via historical FX at date. Use category="usd_cash" (currency="USD") for USD-denominated assets held alongside home-currency ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodYesYYYY-MM
dateYesYYYY-MM-DD (typically month-end)
typeYes
sub_typeYescash | investment | other | short_term | long_term
categoryYesMust be one of the predefined balance categories: assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other.
amountYesAmount in `currency` units (whole units, no decimals)
currencyNoCurrency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Defaults to USD. Non-USD values are converted to USD via historical FX at `date` for storage.USD
memoNo

Implementation Reference

  • The 'add_balance' MCP tool handler: Upserts a single balance sheet entry. Validates inputs via Zod schema (period, date, type, sub_type, category, amount, currency, memo), converts non-USD amounts via nativeToUsd helper using historical FX at the given date, then inserts/upserts into the balanceEntries table using onConflictDoUpdate on the composite key (period, type, sub_type, category). Returns the stored USD amount along with native amount/currency if conversion occurred.
    server.tool(
      'add_balance',
      'Upsert a single balance sheet entry for a period (also edits — same composite key overwrites). Use this when recording just one or two balance items; prefer add_monthly for full month-end settlement. sub_type: cash|investment|other (assets) or short_term|long_term (liabilities). VALID BALANCE CATEGORIES — assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other. Use ONLY these category strings — do NOT invent your own. For non-USD users: pass `currency` as the native currency (e.g. "KRW") and `amount` in that currency — converted to USD via historical FX at `date`. Use category="usd_cash" (currency="USD") for USD-denominated assets held alongside home-currency ones.',
      {
        period: z.string().describe('YYYY-MM'),
        date: z.string().describe('YYYY-MM-DD (typically month-end)'),
        type: z.enum(['asset', 'liability']),
        sub_type: z.string().describe('cash | investment | other | short_term | long_term'),
        category: z
          .string()
          .describe(
            'Must be one of the predefined balance categories: assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other.',
          ),
        amount: z.number().int().describe('Amount in `currency` units (whole units, no decimals)'),
        currency: z
          .string()
          .default('USD')
          .describe(
            'Currency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Defaults to USD. Non-USD values are converted to USD via historical FX at `date` for storage.',
          ),
        memo: z.string().optional(),
      },
      async ({ period, date, type, sub_type, category, amount, currency, memo }) => {
        const conv = nativeToUsd(amount, currency, date);
        if (!conv.ok) return err(conv.error);
        const db = getDb();
        db.insert(balanceEntries)
          .values({
            period,
            date,
            type,
            sub_type,
            category,
            amount: conv.usd,
            currency: 'USD',
            memo: memo ?? null,
          })
          .onConflictDoUpdate({
            target: [
              balanceEntries.period,
              balanceEntries.type,
              balanceEntries.sub_type,
              balanceEntries.category,
            ],
            set: { amount: conv.usd, currency: 'USD', date, memo: memo ?? null },
          })
          .run();
        const cur = currency.toUpperCase();
        return ok({
          period,
          type,
          sub_type,
          category,
          amount: conv.usd,
          currency: 'USD',
          ...(cur !== 'USD' ? { native_amount: amount, native_currency: cur } : {}),
        });
      },
    );
  • Zod input schema for 'add_balance': period (YYYY-MM), date (YYYY-MM-DD), type (asset|liability), sub_type (string), category (string from predefined lists), amount (integer in currency units), currency (defaults to USD), and optional memo.
    {
      period: z.string().describe('YYYY-MM'),
      date: z.string().describe('YYYY-MM-DD (typically month-end)'),
      type: z.enum(['asset', 'liability']),
      sub_type: z.string().describe('cash | investment | other | short_term | long_term'),
      category: z
        .string()
        .describe(
          'Must be one of the predefined balance categories: assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other.',
        ),
      amount: z.number().int().describe('Amount in `currency` units (whole units, no decimals)'),
      currency: z
        .string()
        .default('USD')
        .describe(
          'Currency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Defaults to USD. Non-USD values are converted to USD via historical FX at `date` for storage.',
        ),
      memo: z.string().optional(),
    },
  • Tool registration via server.tool('add_balance', ...) inside registerMutateTools(), which is called from apps/mcp/src/index.ts at line 21.
    server.tool(
      'add_balance',
      'Upsert a single balance sheet entry for a period (also edits — same composite key overwrites). Use this when recording just one or two balance items; prefer add_monthly for full month-end settlement. sub_type: cash|investment|other (assets) or short_term|long_term (liabilities). VALID BALANCE CATEGORIES — assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other. Use ONLY these category strings — do NOT invent your own. For non-USD users: pass `currency` as the native currency (e.g. "KRW") and `amount` in that currency — converted to USD via historical FX at `date`. Use category="usd_cash" (currency="USD") for USD-denominated assets held alongside home-currency ones.',
      {
        period: z.string().describe('YYYY-MM'),
        date: z.string().describe('YYYY-MM-DD (typically month-end)'),
        type: z.enum(['asset', 'liability']),
        sub_type: z.string().describe('cash | investment | other | short_term | long_term'),
        category: z
          .string()
          .describe(
            'Must be one of the predefined balance categories: assets: cash, savings, housing_sub, usd_cash, cash_other, domestic_stock, overseas_stock, real_estate, pension, vehicle, deposit, asset_other. Liabilities: credit_card, short_term_other, loan, long_term_other.',
          ),
        amount: z.number().int().describe('Amount in `currency` units (whole units, no decimals)'),
        currency: z
          .string()
          .default('USD')
          .describe(
            'Currency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Defaults to USD. Non-USD values are converted to USD via historical FX at `date` for storage.',
          ),
        memo: z.string().optional(),
      },
      async ({ period, date, type, sub_type, category, amount, currency, memo }) => {
        const conv = nativeToUsd(amount, currency, date);
        if (!conv.ok) return err(conv.error);
        const db = getDb();
        db.insert(balanceEntries)
          .values({
            period,
            date,
            type,
            sub_type,
            category,
            amount: conv.usd,
            currency: 'USD',
            memo: memo ?? null,
          })
          .onConflictDoUpdate({
            target: [
              balanceEntries.period,
              balanceEntries.type,
              balanceEntries.sub_type,
              balanceEntries.category,
            ],
            set: { amount: conv.usd, currency: 'USD', date, memo: memo ?? null },
          })
          .run();
        const cur = currency.toUpperCase();
        return ok({
          period,
          type,
          sub_type,
          category,
          amount: conv.usd,
          currency: 'USD',
          ...(cur !== 'USD' ? { native_amount: amount, native_currency: cur } : {}),
        });
      },
    );
  • Top-level registration call: registerMutateTools(server) which registers all mutation tools including 'add_balance'.
    registerMutateTools(server);
  • The nativeToUsd helper used by add_balance: converts amount from a given currency to USD using historical FX rates from the data repository at the given date.
    type ConvertResult = { ok: true; usd: number } | { ok: false; error: string };
    export const nativeToUsd = (amount: number, currency: string, date: string): ConvertResult => {
      const cur = currency.toUpperCase();
      if (cur === 'USD') return { ok: true, usd: amount };
      const row = getRepository().fx.getRateOnOrBefore(date, cur);
      if (!row || row.rate_to_usd == null) {
        return {
          ok: false,
          error: `No FX rate cached for ${cur} on or before ${date}. Run sync_fx_rates first, or pass currency="USD" with the converted amount.`,
        };
      }
      return { ok: true, usd: Math.round(amount / row.rate_to_usd) };
    };
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses upsert behavior (overwrites on same composite key), currency conversion via historical FX at date, and data constraints (category strings). Missing information about response or potential side effects, but otherwise transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is multiple sentences but each serves a purpose, front-loading the main action (Upsert). It could be slightly more structured to separate usage guidance from parameter details, but no superfluous text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 8 parameters (6 required), no output schema, and no annotations, the description is quite thorough: covers all parameters, provides valid enums, gives currency conversion rules, and offers usage context. It lacks full specification of the composite key and return value, but overall complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 75%, and the description adds significant value beyond the schema: it lists all valid categories in detail, explains sub_type options with examples, describes currency handling and defaults, and notes the composite key overwrite behavior. However, it does not explicitly list which fields form the composite key.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it 'Upsert a single balance sheet entry for a period (also edits — same composite key overwrites)', using a specific verb 'Upsert' and resource 'balance sheet entry'. It distinguishes from sibling 'add_monthly' by noting 'use this when recording just one or two balance items; prefer add_monthly for full month-end settlement'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says when to use: 'when recording just one or two balance items' and suggests alternative 'add_monthly' for full month-end settlement. However, it does not address other siblings like 'add_balances' for batch operations, leaving a partial gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/evan-moon/firma'

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