summarize
Summarize expenses by category within a specified date range to analyze spending patterns and track financial data.
Instructions
Summarize expenses by category within an inclusive date range.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | ||
| end_date | Yes | ||
| category | No |
Implementation Reference
- main.py:78-99 (handler)The main handler function for the 'summarize' MCP tool. It queries the SQLite database for expenses between start_date and end_date, optionally filtered by category, groups by category, computes total amount and count per category, and returns the results as a list of dictionaries.async def summarize(start_date, end_date, category=None): # Changed: added async '''Summarize expenses by category within an inclusive date range.''' try: async with aiosqlite.connect(DB_PATH) as c: # Changed: added async query = """ SELECT category, SUM(amount) AS total_amount, COUNT(*) as count FROM expenses WHERE date BETWEEN ? AND ? """ params = [start_date, end_date] if category: query += " AND category = ?" params.append(category) query += " GROUP BY category ORDER BY total_amount DESC" cur = await c.execute(query, params) # Changed: added await 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 summarizing expenses: {str(e)}"}
- main.py:77-77 (registration)The @mcp.tool() decorator registers the subsequent 'summarize' function as an MCP tool with FastMCP.@mcp.tool()