update
Modify existing expense records by updating specific fields like amount, date, category, or notes while keeping other information unchanged.
Instructions
Update an expense.Only provided fields will be updated.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | ||
| date | No | ||
| amount | No | ||
| category | No | ||
| subcategory | No | ||
| note | No |
Implementation Reference
- main.py:81-129 (handler)The @mcp.tool() decorated 'update' function implements the MCP tool named 'update'. It conditionally updates fields (date, amount, category, subcategory, note) for an expense by ID in the SQLite database and returns the updated record or error.@mcp.tool() def update( cid: int, date: Optional[str] = None, amount: Optional[float] = None, category: Optional[str] = None, subcategory: Optional[str] = None, note: Optional[str] = None ) -> list[dict]: """Update an expense.Only provided fields will be updated.""" with sqlite3.connect(DB_PATH) as c: update_fields=[] params=[] if date is not None: update_fields.append("date=?") params.append(date) if amount is not None: update_fields.append("amount=?") params.append(amount) if category is not None: update_fields.append("category=?") params.append(category) if subcategory is not None: update_fields.append("subcategory=?") params.append(subcategory) if note is not None: update_fields.append("note=?") params.append(note) if not update_fields: return {"No fields provided to update"} params.append(cid) query=f"UPDATE expenses SET {', '.join(update_fields)} WHERE id=?" c.execute(query,params) c.commit() select_query="select * from expenses where id=?" cur=c.execute(select_query,[cid]) cols = [d[0] for d in cur.description] rows = cur.fetchall() if rows: return [dict(zip(cols, r)) for r in rows] else: return {"error": f"No expense found with id {cid}"}