Skip to main content
Glama
AdvancedExpenseTracker

AdvancedExpenseTracker

README.md

# AdvancedExpenseTracker (FastMCP)

An **AI-powered Expense & Budget Management MCP Server** built using **FastMCP**, **SQLite**, and Python.  
This project exposes structured financial tools (expenses, income, budgets, recurring bills, analytics) that can be used by an LLM (like Claude Desktop or Cursor) as a **personal financial advisor**.

---

## ๐Ÿš€ Features Overview

- โœ… **Expense Tracking:** Categories, subcategories, tags, notes, and payment methods.
- โœ… **Income & Cashflow:** Log earnings and analyze net savings in real-time.
- โœ… **Recurring Engine:** Auto-generate daily, weekly, monthly, or yearly bills.
- โœ… **Smart Budgeting:** Set limits per category and get "Over Budget" warnings.
- โœ… **Search & Filtering:** Find transactions by note, tag, or amount.
- โœ… **Metadata Management:** Dynamic control over valid categories & payment methods.
- โœ… **Zero-Setup Database:** SQLite database initializes automatically.

---

## ๐Ÿ—๏ธ Architecture

```text
AdvancedExpenseTracker
โ”‚
โ”œโ”€โ”€ expenses.db        # SQLite database (auto-created on first run)
โ”œโ”€โ”€ metadata.json      # Categories & payment methods (auto-created)
โ”œโ”€โ”€ main.py            # MCP server implementation
โ””โ”€โ”€ README.md
```

---

## ๐Ÿ“ฆ Tech Stack

- **Python 3.10+**
- **FastMCP** (The only external dependency)
- **SQLite** (Built-in, serverless storage)
- **uv** (For ultra-fast dependency management)

---

## โš™๏ธ Installation (using uv)

This project is designed to run instantly with **[uv](https://github.com/astral-sh/uv)**. You do not need to manually create virtual environments.

### 1๏ธโƒฃ Install uv (if not installed)
```bash
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
```

### 2๏ธโƒฃ Clone the Repository
```bash
git clone <your-repo-url>
cd AdvancedExpenseTracker
```

### 3๏ธโƒฃ Test Run
You can verify the script works without installing anything globally:

```bash
uv run --with fastmcp main.py
```
*On the first run, this will create `expenses.db` and `metadata.json` automatically.*

---

## ๐Ÿ”Œ Configuration (Connect to AI)

To use this with Claude Desktop or Cursor, you need to tell them where the script is.

### Option A: Claude Desktop App

1.  Open your config file:
    *   **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
    *   **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
2.  Add the following (Replace `/ABSOLUTE/PATH/TO/` with your real file path):

```json
{
  "mcpServers": {
    "finance": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "fastmcp",
        "/ABSOLUTE/PATH/TO/main.py"
      ]
    }
  }
}
```

### Option B: Cursor (IDE)

1.  Go to **Cursor Settings** > **Features** > **MCP**.
2.  Click **+ Add New MCP Server**.
3.  **Name:** `Expense Tracker`
4.  **Type:** `command`
5.  **Command:** `uv run --with fastmcp /ABSOLUTE/PATH/TO/main.py`

---

## ๐Ÿง  MCP Capabilities (Detailed)

### ๐Ÿ“Œ Expense Management

#### โž• Add Expense
```python
add_expense(
  date="2026-01-05",
  amount=250,
  category="Food",
  subcategory="Dining",
  payment_method="Credit Card",
  note="Dinner with friends",
  tags="restaurant,weekend"
)
```

#### โœ๏ธ Update Expense
Update only the fields you want to change:
```python
update_expense(expense_id=1, amount=300, note="Updated bill amount")
```

#### โŒ Delete Expense
```python
delete_expense(expense_id=1)
```

#### ๐Ÿ“„ List Expenses
```python
list_expenses(
  start_date="2026-01-01",
  end_date="2026-01-31",
  category="Food",
  limit=50
)
```

#### ๐Ÿ” Search Expenses
Search across category, subcategory, notes, and tags:
```python
search_expenses(query="restaurant")
```

---

### ๐Ÿ’ฐ Income & Cashflow

#### โž• Add Income
```python
add_income(
  date="2026-01-01",
  amount=5000,
  source="Salary",
  note="January Paycheck"
)
```

#### ๐Ÿ“Š Cashflow Analysis
```python
get_cashflow(start_date="2026-01-01", end_date="2026-01-31")
```
**Returns:**
```json
{
  "total_income": 5000,
  "total_expenses": 1800,
  "net_savings": 3200,
  "savings_rate": "64.0%"
}
```

---

### ๐Ÿ” Recurring Expenses Engine

#### โž• Add Recurring Expense
```python
add_recurring_expense(
  name="Netflix",
  amount=15.99,
  category="Entertainment",
  frequency="monthly",
  start_date="2026-01-01"
)
```
*Supported frequencies: `daily`, `weekly`, `monthly`, `yearly`.*

#### ๐Ÿ”„ Process/Refresh Bills
Run this to generate actual expense entries from your templates:
```python
process_recurring_expenses(target_date="2026-03-31")
```

---

### ๐Ÿ“‰ Budgeting & Alerts

#### ๐ŸŽฏ Set Monthly Budget
```python
set_monthly_budget(category="Food", amount=500)
```

#### ๐Ÿ“‘ Budget Report
```python
get_budget_report(month_str="2026-01")
```
*Status logic:*
* โœ… **OK**
* โš ๏ธ **WARNING** (>90% used)
* โŒ **OVER BUDGET**

---

### ๐Ÿงพ Metadata Management

#### ๐Ÿ“ฅ Get Metadata (Resource)
The AI reads this to know which categories are allowed.
```text
expense://metadata
```

#### โž• Manage Categories/Methods
```python
manage_metadata(action="add", type="categories", value="Education")
manage_metadata(action="remove", type="payment_methods", value="Cash")
```

---

## ๐Ÿค– Built-in LLM Prompt

### ๐Ÿง  Financial Advisor Prompt
```python
financial_advisor()
```
This prompt instructs the LLM to:
* Act as a data-driven financial advisor.
* Always validate metadata before logging.
* Prioritize cashflow health and budget warnings.
* Proactively manage recurring subscriptions.

---

## ๐Ÿ” Data Safety

* All data is stored **locally** in `expenses.db`.
* No external API calls or cloud syncing.
* To backup your data, simply copy the `.db` file.

---

## ๐Ÿ“œ License

MIT License โ€“ free to use, modify, and distribute.

---

## ๐Ÿ™Œ Author
**Anubhab Das**

TDQS

B3.2/5.0

Scored across 12 tools

Disambiguation4/5

Each tool targets a fairly distinct resource+action (expense CRUD, income, budget, recurring, metadata), and descriptions clarify the tricky pairs like add_recurring_expense vs process_recurring_expenses. The main soft spots are list_expenses vs search_expenses (both return filtered expense sets) and get_cashflow being derivable from expense/income data, but these are reasonably separable.

Naming Consistency5/5

All twelve names are snake_case verb_noun (add_expense, update_expense, set_monthly_budget, get_budget_report), with no style mixing. The pattern reads predictably and maps cleanly to actions.

Tool Count5/5

Twelve tools is squarely in the ideal 3-15 range and each maps to a real workflow (expenses, income, recurring bills, budgets, metadata). No tool appears redundant or filler.

Completeness3/5

Expense lifecycle is fully covered (add/update/delete/list/search), but income only has add_income with no update/delete/list, and recurring bills have no way to list or cancel templates once created. Budget also lacks a remove/clear operation, leaving several dead ends an agent will hit.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues