Skip to main content
Glama
rprashar21

FastMCP Demo Server

by rprashar21

add_expense

Record a new expense by providing description, amount, and category. Optionally add subcategory and note.

Instructions

Add an expense to the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
amountYes
categoryYes
subcategoryNo
noteNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:45-60 (handler)
    The main handler function for the 'add_expense' tool. Decorated with @mcp.tool, it accepts description, amount, category, subcategory (optional), and note (optional). Inserts the expense into a SQLite database and returns a dict with status and the new record's id.
    async def add_expense(description: str, amount: float, category: str, subcategory: str = '', note: str = '') -> dict:
        """ Add an expense to the database """
        try:
            async with aiosqlite.connect(DB_PATH) as conn:
                now = datetime.now().isoformat()
                cursor = await conn.execute("""
                INSERT INTO expenses (description, amount, category, subcategory, date, note, created_at, updated_at)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?)
                """, (description, amount, category, subcategory, datetime.now().strftime('%Y-%m-%d'), note, now, now))
                last_id = cursor.lastrowid
                await conn.commit()
                return {"status": "OK", "id": last_id}
        except aiosqlite.Error as e:
            return {"status": "ERROR", "message": f"Database error: {str(e)}"}
        except Exception as e:
            return {"status": "ERROR", "message": f"Unexpected error: {str(e)}"}
  • main.py:44-44 (registration)
    Tool registration via the @mcp.tool decorator. The FastMCP instance 'mcp' registers 'add_expense' as an MCP tool.
    @mcp.tool
  • main.py:45-45 (schema)
    Input parameter definitions (type hints): description (str), amount (float), category (str), subcategory (str, default ''), note (str, default ''). Output is dict.
    async def add_expense(description: str, amount: float, category: str, subcategory: str = '', note: str = '') -> dict:
  • main.py:17-36 (helper)
    Database initialization helper that creates the 'expenses' table with all required columns (id, description, amount, category, subcategory, date, note, created_at, updated_at) if it doesn't already exist.
    async def init_db():
        try:
            async with aiosqlite.connect(DB_PATH) as conn:
                await conn.execute("""
                    CREATE TABLE IF NOT EXISTS expenses (
                        id INTEGER PRIMARY KEY AUTOINCREMENT,
                        description TEXT NOT NULL,
                        amount REAL NOT NULL,
                        category TEXT NOT NULL,
                        subcategory TEXT DEFAULT '',
                        date TEXT NOT NULL,
                        note TEXT DEFAULT '',
                        created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
                        updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
                    )
                """)
                await conn.commit()
        except aiosqlite.Error as e:
            print(f"Error initializing database: {e}")
            raise
Behavior2/5

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

No annotations exist, and description fails to reveal any behavioral traits (e.g., side effects, required permissions, idempotency). 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.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no redundancy. Could be more helpful with details, but it is concise.

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

Completeness2/5

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

Given 5 parameters and no annotations, description is too brief. Missing details like validation, behavior on duplicate, return value, or requirements.

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

Parameters2/5

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

Parameter names are self-explanatory, but description offers no additional meaning beyond schema. Schema coverage is 0%, so description does not compensate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states action (add) and resource (expense), distinguishing it from sibling list_expenses. It is specific and unambiguous.

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?

No explicit guidance on when to use vs list_expenses, but usage is implied by the verb 'add'. No alternatives or exclusions mentioned.

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/rprashar21/mcp'

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