Skip to main content
Glama

add_txns

Import multiple transactions at once for bulk entries like CSV or brokerage exports. Automatically sorts by date and returns a summary per ticker and type for confirmation.

Instructions

Bulk-insert transactions in one call. Use this for any import larger than ~5 rows (CSV / brokerage export / paste). Sorts by date ascending automatically — average cost depends on insertion order. Returns a per-ticker / per-type summary so you can confirm the import to the user. For one-off entries during conversation, prefer add_txn.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
transactionsYes

Implementation Reference

  • Registration of the 'add_txns' tool on the MCP server via server.tool(). Defines the tool name, description, and input schema.
    server.tool(
      'add_txns',
      'Bulk-insert transactions in one call. Use this for any import larger than ~5 rows (CSV / brokerage export / paste). Sorts by date ascending automatically — average cost depends on insertion order. Returns a per-ticker / per-type summary so you can confirm the import to the user. For one-off entries during conversation, prefer add_txn.',
      {
        transactions: z
          .array(
            z.object({
              ticker: z.string(),
              date: z.string().describe('YYYY-MM-DD'),
              type: z.enum(['buy', 'sell', 'deposit', 'dividend', 'tax']),
              shares: z.number().positive(),
              price: z.number().min(0),
              currency: z.string().default('USD'),
              reason: z.string().optional(),
            }),
          )
          .min(1),
      },
      async ({ transactions: txns }) => {
        const db = getDb();
        const sorted = [...txns].sort((a, b) => a.date.localeCompare(b.date));
        const byTicker = new Map<string, number>();
        const byType = new Map<string, number>();
    
        for (const t of sorted) {
          const ticker = t.ticker.toUpperCase();
          db.insert(transactions)
            .values({
              ticker,
              date: t.date,
              type: t.type,
              shares: t.shares,
              price: t.price,
              currency: t.currency ?? 'USD',
              reason: t.reason ?? null,
            })
            .run();
          byTicker.set(ticker, (byTicker.get(ticker) ?? 0) + 1);
          byType.set(t.type, (byType.get(t.type) ?? 0) + 1);
        }
    
        return ok({
          inserted: sorted.length,
          first_date: sorted[0].date,
          last_date: sorted[sorted.length - 1].date,
          by_ticker: Object.fromEntries(byTicker),
          by_type: Object.fromEntries(byType),
        });
      },
    );
  • Input schema for add_txns: expects an array of transactions with fields ticker, date, type (enum), shares, price, currency (default USD), and optional reason.
    {
      transactions: z
        .array(
          z.object({
            ticker: z.string(),
            date: z.string().describe('YYYY-MM-DD'),
            type: z.enum(['buy', 'sell', 'deposit', 'dividend', 'tax']),
            shares: z.number().positive(),
            price: z.number().min(0),
            currency: z.string().default('USD'),
            reason: z.string().optional(),
          }),
        )
        .min(1),
    },
  • Handler function that bulk-inserts transactions. Sorts by date ascending, inserts each row into the 'transactions' table via Drizzle ORM, and returns a summary with inserted count, date range, by_ticker and by_type breakdowns.
    async ({ transactions: txns }) => {
      const db = getDb();
      const sorted = [...txns].sort((a, b) => a.date.localeCompare(b.date));
      const byTicker = new Map<string, number>();
      const byType = new Map<string, number>();
    
      for (const t of sorted) {
        const ticker = t.ticker.toUpperCase();
        db.insert(transactions)
          .values({
            ticker,
            date: t.date,
            type: t.type,
            shares: t.shares,
            price: t.price,
            currency: t.currency ?? 'USD',
            reason: t.reason ?? null,
          })
          .run();
        byTicker.set(ticker, (byTicker.get(ticker) ?? 0) + 1);
        byType.set(t.type, (byType.get(t.type) ?? 0) + 1);
      }
    
      return ok({
        inserted: sorted.length,
        first_date: sorted[0].date,
        last_date: sorted[sorted.length - 1].date,
        by_ticker: Object.fromEntries(byTicker),
        by_type: Object.fromEntries(byType),
      });
    },
  • Top-level registration: registerMutateTools(server) is called from index.ts, which registers both add_txn and add_txns on the McpServer.
    registerPortfolioTools(server);
    registerReportTools(server);
    registerMutateTools(server);
  • Helper functions used by the handler: ok() for successful responses, err() for error responses.
    export const ok = (data: unknown) => ({
      content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
    });
    
    export const err = (msg: string) => ({
      content: [{ type: 'text' as const, text: `Error: ${msg}` }],
      isError: true,
    });
    
    export const toDateStr = (d: Date) => d.toISOString().slice(0, 10);
    
    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?

No annotations are provided, so the description carries the burden. It discloses automatic date sorting, average cost dependency on insertion order, and return summary. However, it omits details on idempotency, error handling, or limits.

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 concise sentences directly address purpose, usage, and behavior. Every sentence adds value with no 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?

Given the tool's complexity (bulk array, sorting, average cost), the description covers key behavioral aspects and return format. It could mention error handling or maximum size, but is largely complete for correct usage.

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

Parameters3/5

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

The input schema has one parameter 'transactions' with nested object, and schema descriptions for date, type, shares, price are adequate. The description adds bulk-insert context but does not elaborate on individual field meanings beyond what the schema provides.

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 states 'Bulk-insert transactions in one call' and clearly distinguishes from the sibling tool 'add_txn' for one-off entries. The verb 'insert' and resource 'transactions' are specific, and the scope is well-defined.

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 tells when to use ('any import larger than ~5 rows') and when not to ('for one-off entries during conversation, prefer add_txn'). Also provides context about automatic date sorting and return summary.

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