Skip to main content
Glama

add_flow

Record or update a single cash flow entry (income or expense) for a specific period. Supports predefined categories like salary, rent, insurance, and debt repayment.

Instructions

Upsert a single cash flow entry for a period (also edits — same composite key overwrites). Use this when recording just one or two flow items; prefer add_monthly for full month-end settlement. VALID FLOW CATEGORIES — income (sub_type=employment): salary, business. Income (sub_type=investment): dividends, interest. Income (sub_type=other): income_other. Expense (sub_type=consumption): personal. Expense (sub_type=fixed): insurance, phone, utilities. Expense (sub_type=housing): rent, maintenance. Expense (sub_type=debt): loan_repayment. Expense (sub_type=other): expense_other. Use ONLY these category strings — do NOT invent your own.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodYesYYYY-MM
dateYesYYYY-MM-DD (typically month-end)
typeYes
sub_typeYesMust match the category sub_type. Income: employment, investment, other. Expense: consumption, fixed, housing, debt, other.
categoryYesMust be one of the predefined flow categories. Income: salary, business, dividends, interest, income_other. Expense: personal, insurance, phone, utilities, rent, maintenance, loan_repayment, expense_other.
amountYesAmount in `currency` units (whole units)
currencyNoCurrency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Non-USD converted via historical FX at `date`.USD
memoNo

Implementation Reference

  • Handler function for the 'add_flow' tool. Upserts a single cash flow entry with currency conversion via nativeToUsd and onConflictDoUpdate composite key strategy.
      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(flowEntries)
          .values({
            period,
            date,
            type,
            sub_type,
            category,
            amount: conv.usd,
            currency: 'USD',
            memo: memo ?? null,
          })
          .onConflictDoUpdate({
            target: [flowEntries.period, flowEntries.type, flowEntries.sub_type, flowEntries.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 the 'add_flow' tool defining period, date, type, sub_type, category, amount, currency, and memo fields.
    {
      period: z.string().describe('YYYY-MM'),
      date: z.string().describe('YYYY-MM-DD (typically month-end)'),
      type: z.enum(['income', 'expense']),
      sub_type: z
        .string()
        .describe(
          'Must match the category sub_type. Income: employment, investment, other. Expense: consumption, fixed, housing, debt, other.',
        ),
      category: z
        .string()
        .describe(
          'Must be one of the predefined flow categories. Income: salary, business, dividends, interest, income_other. Expense: personal, insurance, phone, utilities, rent, maintenance, loan_repayment, expense_other.',
        ),
      amount: z.number().int().describe('Amount in `currency` units (whole units)'),
      currency: z
        .string()
        .default('USD')
        .describe('Currency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Non-USD converted via historical FX at `date`.'),
      memo: z.string().optional(),
    },
  • Registration of 'add_flow' tool with the MCP server via server.tool() in registerMutateTools function.
    server.tool(
      'add_flow',
      'Upsert a single cash flow entry for a period (also edits — same composite key overwrites). Use this when recording just one or two flow items; prefer add_monthly for full month-end settlement. VALID FLOW CATEGORIES — income (sub_type=employment): salary, business. Income (sub_type=investment): dividends, interest. Income (sub_type=other): income_other. Expense (sub_type=consumption): personal. Expense (sub_type=fixed): insurance, phone, utilities. Expense (sub_type=housing): rent, maintenance. Expense (sub_type=debt): loan_repayment. Expense (sub_type=other): expense_other. Use ONLY these category strings — do NOT invent your own.',
      {
        period: z.string().describe('YYYY-MM'),
        date: z.string().describe('YYYY-MM-DD (typically month-end)'),
        type: z.enum(['income', 'expense']),
        sub_type: z
          .string()
          .describe(
            'Must match the category sub_type. Income: employment, investment, other. Expense: consumption, fixed, housing, debt, other.',
          ),
        category: z
          .string()
          .describe(
            'Must be one of the predefined flow categories. Income: salary, business, dividends, interest, income_other. Expense: personal, insurance, phone, utilities, rent, maintenance, loan_repayment, expense_other.',
          ),
        amount: z.number().int().describe('Amount in `currency` units (whole units)'),
        currency: z
          .string()
          .default('USD')
          .describe('Currency of `amount` (USD/KRW/JPY/EUR/CNY/GBP). Non-USD converted via historical FX at `date`.'),
        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(flowEntries)
          .values({
            period,
            date,
            type,
            sub_type,
            category,
            amount: conv.usd,
            currency: 'USD',
            memo: memo ?? null,
          })
          .onConflictDoUpdate({
            target: [flowEntries.period, flowEntries.type, flowEntries.sub_type, flowEntries.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 } : {}),
        });
      },
    );
  • Parent function that registers all mutate tools including add_flow.
    export function registerMutateTools(server: McpServer): void {
  • Helper function nativeToUsd used by the add_flow handler to convert amounts from native currency to USD using cached FX rates.
    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?

Discloses upsert behavior (overwrites on duplicate composite key) and lists valid category strings. No annotations present, so description carries full burden; lacks details on permissions or side effects, but sufficient for use.

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?

Front-loaded with purpose, then lists necessary categories. Slightly long due to category enumeration, but each sentence contributes value without redundancy.

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?

Covers usage, category constraints, and upsert behavior. Lacks output schema description (no mention of return value) and explicit composite key definition, but sufficient for a mutation tool with many parameters.

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

Parameters5/5

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

Adds significant value beyond schema: explains composite key overwrite, enumerates all valid category/sub_type combinations, warns against inventing categories. Schema has 75% coverage but leaves gaps that description fills.

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?

Clearly states it upserts a single cash flow entry and can edit via composite key. Distinguishes from sibling 'add_monthly' by specifying use case (single items vs. full settlement).

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

Usage Guidelines5/5

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

Explicitly says when to use this tool (one or two items) and when to prefer 'add_monthly' for full month-end settlement. No ambiguity.

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