add_expense
Add a new expense to the Expense Tracker MCP Server database by specifying date, amount, category, and optional details to record financial transactions.
Instructions
Add a new expense to the database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| amount | Yes | ||
| category | Yes | ||
| subcategory | No | ||
| note | No |
Implementation Reference
- main.py:55-67 (handler)The add_expense tool is defined with the @mcp.tool() decorator and uses sqlite3 to insert new entries into the expenses table.
@mcp.tool() def add_expense(date, amount, category, subcategory="", note=""): """Add a new expense to the database.""" try: with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute(""" INSERT INTO expenses (date, amount, category, subcategory, note) VALUES (?, ?, ?, ?, ?) """, (date, float(amount), category, subcategory, note)) return {"status": "ok", "id": cursor.lastrowid} except Exception as e: return {"status": "error", "error": str(e)}