Skip to main content
Glama
elcukro

bank-mcp

by elcukro

spending_summary

Analyze spending patterns by grouping expenses into merchant or category breakdowns with totals to identify where money is being spent.

Instructions

Group expenses by merchant or category with totals. Shows where money is being spent. Use groupBy "merchant" for vendor breakdown, "category" for category breakdown.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdNo
dateFromNo
dateToNo
groupByNoGroup expenses by "merchant" (default) or "category".
limitNoMax groups to return (default 20, sorted by total spent).

Implementation Reference

  • Main handler function that fetches debit transactions, groups them by merchant or category, calculates totals, sorts by amount, and returns a spending summary with grouped expenses, total spent, currency, and period.
    export async function spendingSummary(
      args: z.infer<typeof spendingSummarySchema>,
    ): Promise<{ groups: SpendingGroup[]; totalSpent: number; currency: string; period: string }> {
      const transactions = await listTransactions({
        connectionId: args.connectionId,
        dateFrom: args.dateFrom,
        dateTo: args.dateTo,
        type: "debit",
      });
    
      const groupBy = args.groupBy || "merchant";
      const limit = args.limit || 20;
    
      // Group expenses
      const groups = new Map<string, { total: number; count: number; currency: string }>();
    
      for (const tx of transactions) {
        const key =
          groupBy === "merchant"
            ? tx.merchantName || tx.description || "Unknown"
            : tx.category || "uncategorized";
    
        const existing = groups.get(key) || { total: 0, count: 0, currency: tx.currency };
        existing.total += Math.abs(tx.amount);
        existing.count += 1;
        groups.set(key, existing);
      }
    
      // Sort by total spent descending
      const sorted = [...groups.entries()]
        .map(([name, data]) => ({
          name,
          totalSpent: Math.round(data.total * 100) / 100,
          transactionCount: data.count,
          currency: data.currency,
        }))
        .sort((a, b) => b.totalSpent - a.totalSpent)
        .slice(0, limit);
    
      const totalSpent =
        Math.round(transactions.reduce((sum, t) => sum + Math.abs(t.amount), 0) * 100) / 100;
    
      const currency = transactions[0]?.currency || "PLN";
      const dateFrom = args.dateFrom || defaultDateFrom(90);
      const dateTo = args.dateTo || today();
    
      return {
        groups: sorted,
        totalSpent,
        currency,
        period: `${dateFrom} to ${dateTo}`,
      };
    }
  • Input schema defined with zod, specifying optional parameters: connectionId, dateFrom, dateTo, groupBy (enum: 'merchant' or 'category'), and limit (default 20).
    export const spendingSummarySchema = z.object({
      connectionId: z.string().optional(),
      dateFrom: z.string().optional(),
      dateTo: z.string().optional(),
      groupBy: z
        .enum(["merchant", "category"])
        .optional()
        .describe('Group expenses by "merchant" (default) or "category".'),
      limit: z
        .number()
        .optional()
        .describe("Max groups to return (default 20, sorted by total spent)."),
    });
  • Output interface definition for SpendingGroup containing name, totalSpent, transactionCount, and currency fields.
    interface SpendingGroup {
      name: string;
      totalSpent: number;
      transactionCount: number;
      currency: string;
    }
  • src/server.ts:50-54 (registration)
    Tool registration in the TOOLS array, defining the tool name 'spending_summary', description, and inputSchema.
      name: "spending_summary",
      description:
        'Group expenses by merchant or category with totals. Shows where money is being spent. Use groupBy "merchant" for vendor breakdown, "category" for category breakdown.',
      inputSchema: z.toJSONSchema(spendingSummarySchema),
    },
  • src/server.ts:66-67 (registration)
    Handler mapping in the handlers object that connects the 'spending_summary' tool name to the spendingSummary function with schema validation.
    spending_summary: (args) =>
      spendingSummary(spendingSummarySchema.parse(args)),
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the grouping functionality and default behaviors (e.g., 'merchant' as default, sorting by total spent), but lacks details on permissions, rate limits, error handling, or what the output format looks like (no output schema).

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?

The description is front-loaded with the core purpose, followed by specific usage examples. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (5 parameters, no output schema, no annotations), the description covers the basic functionality and key parameters adequately. However, it lacks information on authentication needs, error cases, or output structure, leaving gaps for an agent to infer behavior.

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 low (40%), but the description compensates by explaining the semantics of the 'groupBy' parameter ('merchant' for vendor breakdown, 'category' for category breakdown) and implying date range usage. It does not cover other parameters like 'connectionId' or 'limit' in detail, but adds meaningful context beyond the schema.

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's purpose with specific verbs ('Group expenses by merchant or category with totals') and resource ('expenses'). It distinguishes from sibling tools like 'get_balance' or 'list_transactions' by focusing on aggregation and summarization rather than raw data listing or balance retrieval.

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 clear context for when to use this tool ('Shows where money is being spent') and offers guidance on how to use it with 'groupBy' options. However, it does not explicitly state when not to use it or name alternatives among sibling tools (e.g., 'search_transactions' for detailed filtering).

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/elcukro/bank-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server