edit_expense
Update existing expense records in the Expense Tracker database to correct errors, modify categories, adjust amounts, or add notes.
Instructions
Edit an existing expense in the database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| date | Yes | ||
| amount | Yes | ||
| category | Yes | ||
| subcategory | No | ||
| note | No |
Implementation Reference
- main.py:116-131 (handler)The edit_expense tool is defined and registered using the @mcp.tool() decorator, and contains the logic to update an existing expense entry in the SQLite database.
@mcp.tool() def edit_expense(id, date, amount, category, subcategory="", note=""): """Edit an existing expense in the database.""" try: with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute(""" UPDATE expenses SET date = ?, amount = ?, category = ?, subcategory = ?, note = ? WHERE id = ? """, (date, float(amount), category, subcategory, note, id)) if cursor.rowcount == 0: return {"status": "error", "error": "No expense with that id"} return {"status": "ok"} except Exception as e: return {"status": "error", "error": str(e)}