add_expense
Add a new expense to the Expense Tracker MCP Server database by specifying date, amount, category, and optional details to record financial transactions.
Instructions
Add a new expense to the database.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"date": "<date>",
"amount": "<amount>",
"category": "<category>"
},
"name": "add_expense"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| amount | Yes | ||
| category | Yes | ||
| subcategory | No | ||
| note | No |
Implementation Reference
- main.py:55-67 (handler)The add_expense tool is defined with the @mcp.tool() decorator and uses sqlite3 to insert new entries into the expenses table.
@mcp.tool() def add_expense(date, amount, category, subcategory="", note=""): """Add a new expense to the database.""" try: with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute(""" INSERT INTO expenses (date, amount, category, subcategory, note) VALUES (?, ?, ?, ?, ?) """, (date, float(amount), category, subcategory, note)) return {"status": "ok", "id": cursor.lastrowid} except Exception as e: return {"status": "error", "error": str(e)}