list_expenses
Retrieve expense entries for a specific date range to track spending patterns and manage budgets effectively.
Instructions
List expense entries within an inclusive date range.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | ||
| end_date | Yes |
Implementation Reference
- main.py:58-75 (handler)The handler function for the 'list_expenses' tool, decorated with @mcp.tool() for registration in FastMCP. It asynchronously queries the SQLite database for expenses within the given date range and returns a list of expense dictionaries.
@mcp.tool() async def list_expenses(start_date, end_date): # Changed: added async '''List expense entries within an inclusive date range.''' try: async with aiosqlite.connect(DB_PATH) as c: # Changed: added async cur = await c.execute( # Changed: added await """ SELECT id, date, amount, category, subcategory, note FROM expenses WHERE date BETWEEN ? AND ? ORDER BY date DESC, id DESC """, (start_date, end_date) ) cols = [d[0] for d in cur.description] return [dict(zip(cols, r)) for r in await cur.fetchall()] # Changed: added await except Exception as e: return {"status": "error", "message": f"Error listing expenses: {str(e)}"}