Skip to main content
Glama

add_expense

Record an expense against a trip budget by specifying trip, category, amount, and description.

Instructions

Record an expense against a trip budget.

Args: trip_id: The trip identifier used when creating the budget category: Expense category — flights, hotels, food, activities, transport, shopping, or misc amount: Amount spent description: Brief description of the expense (e.g. "ANA flight JFK→NRT")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trip_idYes
categoryYes
amountYes
descriptionYes

Implementation Reference

  • Core implementation of add_expense: validates trip_id exists, appends expense to in-memory budget record, and returns the updated budget summary via get_summary().
    def add_expense(trip_id: str, category: str, amount: float, description: str) -> dict:
        if trip_id not in _budgets:
            return {"error": f"No budget found for trip_id '{trip_id}'. Use create_trip_budget first."}
        cat = category if category in CATEGORIES else "misc"
        _budgets[trip_id].expenses.append(Expense(category=cat, amount=amount, description=description))
        return get_summary(trip_id)
  • Registers add_expense as an MCP tool via @mcp.tool() decorator, with typed parameters (trip_id, category as Literal of valid categories, amount, description) and delegates to budget.add_expense().
    @mcp.tool()
    def add_expense(
        trip_id: str,
        category: Literal["flights", "hotels", "food", "activities", "transport", "shopping", "misc"],
        amount: float,
        description: str,
    ) -> dict:
        """
        Record an expense against a trip budget.
    
        Args:
            trip_id: The trip identifier used when creating the budget
            category: Expense category — flights, hotels, food, activities, transport, shopping, or misc
            amount: Amount spent
            description: Brief description of the expense (e.g. "ANA flight JFK→NRT")
        """
        return budget.add_expense(trip_id, category, amount, description)
  • Registers add_expense as an HTTP API endpoint via @mcp.custom_route('/api/tools/add_expense', methods=['POST']), parsing JSON body and delegating to budget.add_expense().
    @mcp.custom_route("/api/tools/add_expense", methods=["POST"])
    async def api_add_expense(request: Request) -> JSONResponse:
        body = await request.json()
        result = budget.add_expense(body["trip_id"], body["category"], body["amount"], body["description"])
        return JSONResponse(result)
  • Defines the Expense and BudgetRecord Pydantic models (schemas) used internally by add_expense, along with the CATEGORIES constant.
    from __future__ import annotations
    
    from pydantic import BaseModel
    
    CATEGORIES = ["flights", "hotels", "food", "activities", "transport", "shopping", "misc"]
    
    
    class Expense(BaseModel):
        category: str
        amount: float
        description: str
    
    
    class BudgetRecord(BaseModel):
        trip_id: str
        total_budget: float
        currency: str
        expenses: list[Expense] = []
  • Itinerary planning references add_expense in a docstring/note, instructing users to use trip_id with add_expense and get_budget_summary.
    budget_module.create(trip_id, total_budget)
    result["budget"] = {
        "trip_id": trip_id,
        "total_budget": total_budget,
        "currency": "USD",
        "suggested_allocation": allocation,
        "note": f"Use trip_id '{trip_id}' with add_expense and get_budget_summary to track spending.",
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It only says 'Record an expense', implying mutation, but does not disclose behavior on missing trip_id, error handling, idempotency, or return value. Minimal transparency.

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?

Description is concise: a one-line header followed by bullet-pointed args. No redundant words, front-loaded, every sentence adds value.

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 4 required params, no output schema, and no annotations, the description explains parameters adequately but lacks behavioral context (side effects, what happens on failure, success response). There are gaps for a mutation tool.

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?

With 0% schema description coverage, the description adds meaning to all parameters: trip_id (identifier), category (enum list), amount (spent), description (brief with example). It adds value beyond the schema, but could be more detailed (e.g., unit, constraints).

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 'Record an expense against a trip budget', using a specific verb and resource. It distinguishes from siblings like 'create_trip_budget' (which creates the budget) and 'get_budget_summary' (which retrieves 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?

The description does not explicitly state when to use this tool versus alternatives, nor does it mention prerequisites (e.g., budget must exist) or exclusions. Usage is implied from context but not provided.

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/ismailrz/travel-mcp-server'

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