summarize
Summarize expenses by category within a specified date range to analyze spending patterns and track financial data from the Expense Tracker MCP Server.
Instructions
Summarize expenses by category within the inclusive date range. Returns list of {"category": ..., "total": ...} ordered by total descending.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | ||
| end_date | Yes | ||
| category | No |
Implementation Reference
- main.py:88-110 (handler)The implementation of the 'summarize' MCP tool which queries a SQLite database to aggregate expenses by category.
@mcp.tool() def summarize(start_date, end_date, category=None): """ Summarize expenses by category within the inclusive date range. Returns list of {"category": ..., "total": ...} ordered by total descending. """ try: with sqlite3.connect(DB_PATH) as conn: params = [start_date, end_date] query = """ SELECT category, SUM(amount) as total FROM expenses WHERE date BETWEEN ? AND ? """ if category: query += " AND category = ?" params.append(category) query += " GROUP BY category ORDER BY total DESC" cursor = conn.cursor() cursor.execute(query, params) cols = [desc[0] for desc in cursor.description] return {"status": "ok", "summary": [dict(zip(cols, row)) for row in cursor.fetchall()]}