Skip to main content
Glama

add_flows

Bulk-upsert income and expense entries across months and categories in one call. Overwrites duplicates by period, type, sub_type, and category.

Instructions

Bulk-upsert cash flow entries (income + expenses) across multiple months and categories in one call. Use when importing an income/expense spreadsheet with rows = months and columns = categories. Each entry overwrites if (period, type, sub_type, category) already exists.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entriesYes

Implementation Reference

  • The `add_flows` tool definition and handler. Registers the tool with the MCP server, defines the Zod schema for input validation (period, date, type, sub_type, category, amount, memo), and implements the bulk-upsert logic by iterating entries and doing INSERT ... ON CONFLICT DO UPDATE using the flowEntries table.
    server.tool(
      'add_flows',
      'Bulk-upsert cash flow entries (income + expenses) across multiple months and categories in one call. Use when importing an income/expense spreadsheet with rows = months and columns = categories. Each entry overwrites if (period, type, sub_type, category) already exists.',
      {
        entries: z
          .array(
            z.object({
              period: z.string().describe('YYYY-MM'),
              date: z.string().describe('YYYY-MM-DD'),
              type: z.enum(['income', 'expense']),
              sub_type: z
                .string()
                .describe(
                  'income: salary|business|dividends|interest|income_other; expense: personal|insurance|phone|utilities|rent|maintenance|loan_repayment|expense_other',
                ),
              category: z.string(),
              amount: z.number().int().describe('Amount in USD (whole dollars)'),
              memo: z.string().optional(),
            }),
          )
          .min(1),
      },
      async ({ entries }) => {
        const db = getDb();
        const byPeriod = new Map<string, number>();
    
        for (const e of entries) {
          db.insert(flowEntries)
            .values({
              period: e.period,
              date: e.date,
              type: e.type,
              sub_type: e.sub_type,
              category: e.category,
              amount: e.amount,
              currency: 'USD',
              memo: e.memo ?? null,
            })
            .onConflictDoUpdate({
              target: [
                flowEntries.period,
                flowEntries.type,
                flowEntries.sub_type,
                flowEntries.category,
              ],
              set: { amount: e.amount, currency: 'USD', date: e.date, memo: e.memo ?? null },
            })
            .run();
          byPeriod.set(e.period, (byPeriod.get(e.period) ?? 0) + 1);
        }
    
        return ok({
          upserted: entries.length,
          periods: byPeriod.size,
          by_period: Object.fromEntries(byPeriod),
        });
      },
    );
  • Drizzle ORM schema for the `flow_entries` SQLite table, including columns (id, period, date, type, sub_type, category, amount, currency, memo) and a unique index on (period, type, sub_type, category).
    export const flowEntries = sqliteTable(
      'flow_entries',
      {
        id: integer('id').primaryKey({ autoIncrement: true }),
        period: text('period').notNull(),
        date: text('date').notNull(),
        type: text('type').notNull(),
        sub_type: text('sub_type').notNull(),
        category: text('category').notNull(),
        amount: integer('amount').notNull().default(0),
        currency: text('currency').notNull().default('KRW'),
        memo: text('memo'),
      },
      (t) => [uniqueIndex('flow_uq').on(t.period, t.type, t.sub_type, t.category)],
  • Registration function `registerMutateTools` that receives the McpServer instance and registers all mutate tools including `add_flows`.
    export function registerMutateTools(server: McpServer): void {
  • Prompt instructing the AI to call add_flows ONCE with the full array after user confirms the category mapping.
    4. Once I confirm, flatten into one array of entries and call add_flows ONCE with the full array. Don't loop add_flow.
    5. Report the upserted count and number of months.
Behavior4/5

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

No annotations provided, so description carries burden. Discloses upsert behavior: entries overwrite if (period, type, sub_type, category) exist. Provides key behavioral insight.

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

Conciseness5/5

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

Two short sentences, front-loaded with purpose, usage, and behavior. No redundant 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?

Covers purpose, usage context, and overwrite logic. Lacks error handling and return details, but acceptable for a bulk-upsert tool given schema and no output schema.

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?

Top-level parameter 'entries' lacks schema description, but description clarifies structure (array of entries) and upsert semantics, compensating for the gap.

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 the tool bulk-upserts cash flow entries across multiple months and categories, distinguishing it from singular add_flow and other siblings like add_balance.

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 states use case: importing a spreadsheet with rows=months and columns=categories. Does not explicitly exclude single-entry imports but implies that via sibling tool add_flow.

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