add_expense
Record a new expense by specifying amount and category, with optional description, to track spending in the Expense Tracker MCP Server.
Instructions
Add a new expense
Args: amount: Expense amount category: Expense category (e.g., 'food', 'transport', 'utilities') description: Optional description
Returns: ID of the added expense
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| category | Yes | ||
| description | No |
Implementation Reference
- main.py:36-58 (handler)The main handler function for the 'add_expense' tool. It is decorated with @mcp.tool for registration and includes input schema via type annotations and docstring. Inserts a new expense record into the SQLite database and returns the ID.@mcp.tool async def add_expense(amount: float, category: str, description: str = "") -> int: """ Add a new expense Args: amount: Expense amount category: Expense category (e.g., 'food', 'transport', 'utilities') description: Optional description Returns: ID of the added expense """ await init_db() date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') cursor = conn.cursor() cursor.execute(''' INSERT INTO expenses (amount, category, description, date) VALUES (?, ?, ?, ?) ''', (amount, category, description, date)) conn.commit() return cursor.lastrowid