add_credit
Increase available funds in your Expense Tracker account to manage spending and maintain accurate financial records.
Instructions
Add credit to the user's account. By default updates 'default' user. Returns new credit amount.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| user_name | No | default |
Implementation Reference
- main.py:150-166 (handler)The add_credit function is decorated with @mcp.tool() and handles adding credit to a user's account in the database.
@mcp.tool() def add_credit(amount, user_name="default"): """ Add credit to the user's account. By default updates 'default' user. Returns new credit amount. """ try: with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() # ensure user exists cursor.execute("INSERT OR IGNORE INTO users (name, credit) VALUES (?, ?)", (user_name, 0.0)) cursor.execute("UPDATE users SET credit = credit + ? WHERE name = ?", (float(amount), user_name)) cursor.execute("SELECT credit FROM users WHERE name = ?", (user_name,)) new_credit = cursor.fetchone()[0] return {"status": "ok", "credit": new_credit} except Exception as e: return {"status": "error", "error": str(e)}