Skip to main content
Glama
naveen6768

Expense Tracker MCP

by naveen6768

add_expense

Record a new expense with amount, category, and optional description and date. The data is saved locally for tracking personal or business spending.

Instructions

Add a new expense and persist it locally.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYes
categoryYes
descriptionNo
expense_dateNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
amountYes
categoryYes
descriptionYes
expense_dateYes
created_atYes

Implementation Reference

  • main.py:174-197 (handler)
    The 'add_expense' tool handler function. It is decorated with @mcp.tool, loads existing expenses, creates a new Expense with parsed/validated fields, appends it, saves, and returns it.
    @mcp.tool
    def add_expense(
        amount: float,
        category: str,
        description: str = "",
        expense_date: str | None = None,
    ) -> Expense:
        """Add a new expense and persist it locally."""
        expenses = _load_expenses()
        normalized_category = _normalize_text(category, "category")
        normalized_description = description.strip()
    
        expense = Expense(
            id=str(uuid4()),
            amount=_parse_amount(amount),
            category=normalized_category,
            description=normalized_description,
            expense_date=_parse_expense_date(expense_date),
            created_at=datetime.now(timezone.utc).replace(microsecond=0).isoformat(),
        )
    
        expenses.append(expense)
        _save_expenses(expenses)
        return expense
  • main.py:18-25 (schema)
    The Expense Pydantic model that serves as the return type (and schema) for the add_expense tool.
    class Expense(BaseModel):
        id: str
        amount: str
        category: str
        description: str
        expense_date: str
        created_at: str
  • main.py:174-175 (registration)
    The @mcp.tool decorator registers the add_expense function as a FastMCP tool.
    @mcp.tool
    def add_expense(
  • Helper function _parse_amount used by add_expense to validate and format the amount to 2 decimal places.
    def _parse_amount(amount: float) -> str:
        try:
            decimal_amount = Decimal(str(amount))
        except InvalidOperation as exc:
            raise ValueError("amount must be a valid number.") from exc
    
        if decimal_amount <= 0:
            raise ValueError("amount must be greater than 0.")
    
        normalized = decimal_amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
        return format(normalized, ".2f")
  • Helper function _parse_expense_date used by add_expense to parse or default the expense date.
    def _parse_expense_date(expense_date: str | None) -> str:
        if expense_date is None:
            return date.today().isoformat()
    
        try:
            return date.fromisoformat(expense_date).isoformat()
        except ValueError as exc:
            raise ValueError("expense_date must use YYYY-MM-DD format.") from exc
Behavior2/5

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

No annotations, so description must disclose behavioral traits. Only states 'persist locally' but lacks detail on side effects, error handling, or whether it returns the created expense.

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?

One concise sentence without redundancy. Could include more parameter guidance but remains efficient.

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?

Simple tool with output schema, but missing parameter descriptions. Adequate but not thorough; e.g., does not mention date format or amount constraints.

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

Parameters1/5

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

Schema coverage 0%, but description provides no extra meaning for any of the 4 parameters (amount, category, description, expense_date).

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?

Clearly states verb 'add' and resource 'expense', with 'persist it locally' distinguishing from potential in-memory operations. Different from siblings delete, list, and summary.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implied usage for creating a new expense, but no explicit when-to-use or when-not-to-use compared to siblings.

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/naveen6768/MCP'

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