Skip to main content
Glama

add_txn

Add a single stock transaction (buy, sell, deposit, dividend, or tax) with ticker, date, shares, price, currency, and optional reason for trading.

Instructions

Insert one stock transaction. For bulk imports: first show the user your detected column mapping and total row count, wait for their confirmation, then call once per row in chronological order (average cost depends on insertion order). Types: buy/sell move shares; deposit adds shares (set price=0 for grants/transfers, or actual cost basis); dividend/tax record cash events (price = total amount, shares = 1). For buy/sell, capture the user's reason (the why behind the trade) when they share it — even one short sentence helps later analysis cross-check thesis vs outcome. The currency arg is the trade's native currency, not the user's home currency.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tickerYesStock ticker symbol (e.g. AAPL)
dateYesTransaction date (YYYY-MM-DD)
typeYes
sharesYes
priceYesPrice per share in USD (use 0 for price=unknown deposits)
currencyNoUSD
reasonNoWhy this trade? (free-form). Most useful on buy/sell — leave blank for dividends/grants/etc.

Implementation Reference

  • Handler for the 'add_txn' tool. Inserts a single transaction into the database with the provided ticker, date, type, shares, price, currency, and optional reason. Returns the inserted record's id and details.
    async ({ ticker, date, type, shares, price, currency, reason }) => {
      const db = getDb();
      const result = db
        .insert(transactions)
        .values({
          ticker: ticker.toUpperCase(),
          date,
          type,
          shares,
          price,
          currency,
          reason: reason ?? null,
        })
        .returning({ id: transactions.id })
        .get();
      return ok({ id: result?.id, ticker: ticker.toUpperCase(), date, type, shares, price });
    },
  • Zod schema for 'add_txn' input validation: ticker (string), date (string YYYY-MM-DD), type (enum: buy/sell/deposit/dividend/tax), shares (positive number), price (non-negative number), currency (default USD), reason (optional string).
      ticker: z.string().describe('Stock ticker symbol (e.g. AAPL)'),
      date: z.string().describe('Transaction date (YYYY-MM-DD)'),
      type: z.enum(['buy', 'sell', 'deposit', 'dividend', 'tax']),
      shares: z.number().positive(),
      price: z.number().min(0).describe('Price per share in USD (use 0 for price=unknown deposits)'),
      currency: z.string().default('USD'),
      reason: z
        .string()
        .optional()
        .describe(
          'Why this trade? (free-form). Most useful on buy/sell — leave blank for dividends/grants/etc.',
        ),
    },
  • Registration of 'add_txn' as an MCP tool via server.tool() on the McpServer instance, called from registerMutateTools().
    server.tool(
      'add_txn',
      "Insert one stock transaction. For bulk imports: first show the user your detected column mapping and total row count, wait for their confirmation, then call once per row in chronological order (average cost depends on insertion order). Types: buy/sell move shares; deposit adds shares (set price=0 for grants/transfers, or actual cost basis); dividend/tax record cash events (price = total amount, shares = 1). For buy/sell, capture the user's reason (the why behind the trade) when they share it — even one short sentence helps later analysis cross-check thesis vs outcome. The currency arg is the trade's native currency, not the user's home currency.",
      {
        ticker: z.string().describe('Stock ticker symbol (e.g. AAPL)'),
        date: z.string().describe('Transaction date (YYYY-MM-DD)'),
        type: z.enum(['buy', 'sell', 'deposit', 'dividend', 'tax']),
        shares: z.number().positive(),
        price: z.number().min(0).describe('Price per share in USD (use 0 for price=unknown deposits)'),
        currency: z.string().default('USD'),
        reason: z
          .string()
          .optional()
          .describe(
            'Why this trade? (free-form). Most useful on buy/sell — leave blank for dividends/grants/etc.',
          ),
      },
      async ({ ticker, date, type, shares, price, currency, reason }) => {
        const db = getDb();
        const result = db
          .insert(transactions)
          .values({
            ticker: ticker.toUpperCase(),
            date,
            type,
            shares,
            price,
            currency,
            reason: reason ?? null,
          })
          .returning({ id: transactions.id })
          .get();
        return ok({ id: result?.id, ticker: ticker.toUpperCase(), date, type, shares, price });
      },
    );
  • Entry point where registerMutateTools is called, which registers 'add_txn' (and other mutate tools) on the MCP server.
    registerMutateTools(server);
  • Helper function 'ok' used to format successful responses as MCP content blocks.
    export const ok = (data: unknown) => ({
      content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
    });
Behavior4/5

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

No annotations exist, so the description carries full burden. It discloses key behaviors: insertion order affects average cost, currency is the trade's native currency, and reason capture aids later analysis. Does not cover idempotency or error handling, but provides sufficient transparency for typical 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?

The description is dense but each sentence adds value. It front-loads the core action ('Insert one stock transaction') and then provides structured guidance on bulk, types, and currency. Somewhat lengthy but efficient for the information conveyed.

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?

No output schema; description does not explain what the tool returns (e.g., success or error). However, for a simple insertion tool, this may be acceptable. It covers transaction semantics well but could improve by noting expected outcomes or response structure.

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 description coverage is 57% (4 of 7 params have descriptions). The description adds substantial meaning beyond the schema: it explains how 'type' affects meaning of 'price' and 'shares' (e.g., price = total amount for dividend, shares = 1 for dividend/tax), clarifies 'currency' is native trade currency, and advises on 'reason' usage. This compensates for missing schema descriptions on other params.

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?

Description states 'Insert one stock transaction', which is a specific verb and resource. It explicitly distinguishes from bulk imports by advising to use the tool once per row for bulk, implying a sibling 'add_txns' for batch operations. This clarity helps the agent select the correct tool.

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?

Provides explicit guidance: when to use (single transaction), for bulk imports it details a two-step process (show mapping, then call once per row). Explains different transaction types and how to handle each (e.g., 'deposit adds shares', 'dividend/tax record cash events'). Offers concrete instructions for capturing user's reason on buy/sell. Alternative tools like 'add_txns' are implied for bulk.

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