Skip to main content
Glama

add_txn

Record a stock transaction: buy, sell, deposit, dividend, or tax. Specify ticker, date, shares, price, and optional reason for trade analysis.

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

  • The 'add_txn' tool handler: registers the MCP tool with server.tool(), defines the Zod schema (ticker, date, type, shares, price, currency, reason), and implements the logic to insert a stock transaction into the database via Drizzle ORM. Returns the inserted transaction id and fields.
    export function registerMutateTools(server: McpServer): void {
      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 });
        },
      );
  • Zod schema definition for add_txn: ticker (string), date (YYYY-MM-DD), type (enum: buy/sell/deposit/dividend/tax), shares (positive number), price (non-negative number, USD), currency (default USD), reason (optional string).
    export function registerMutateTools(server: McpServer): void {
      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 });
        },
      );
  • Import of registerMutateTools from the mutate.ts module where add_txn is defined.
    import { registerMutateTools } from './tools/mutate.ts';
  • Registration call: registerMutateTools(server) which registers the add_txn tool on the MCP server.
    registerMutateTools(server);
  • Instruction referencing add_txn in the server instructions: 'A buy/sell is recorded via add_txn and the conversation contains a rationale → save the decision + reason as a project note.'
    - A buy/sell is recorded via add_txn and the conversation contains a rationale → save the decision + reason as a project note.
Behavior4/5

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

With no annotations, the description bears full burden. It discloses that insertion order affects average cost, defines behavior for each type (e.g., deposit adds shares, dividend/tax record cash events), and explains the reason field's utility. It doesn't mention error handling or idempotency, but it covers key behaviors.

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 roughly 6 sentences and front-loaded with the main purpose. Each sentence adds value, from bulk import procedure to type definitions. It is dense but could be slightly more concise by omitting minor details like the 'one short sentence' advice.

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 7 parameters and no output schema, the description covers the transaction types, reason field, currency clarification, and bulk import process. However, it does not mention the return value or side effects, which are important for an insert operation.

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?

The description adds significant meaning beyond the input schema: it explains the effect of each type (buy/sell move shares, deposit adds shares, etc.), clarifies that for dividend/tax 'price = total amount' and 'shares = 1', and defines 'currency' as the trade's native currency. This compensates for the 57% schema description coverage.

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 starts with 'Insert one stock transaction,' clearly stating the verb and resource. It distinguishes itself from 'add_txns' for bulk imports and explains the process, making it specific and unique among sibling tools.

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?

The description provides explicit guidance for bulk imports: show column mapping, wait for confirmation, call per row in chronological order. It also explains when to use each transaction type, though it does not explicitly list alternative tools or state when not to use this tool.

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