Skip to main content
Glama
neev-25

Smart Expense Management MCP

by neev-25
README.md
# ๐Ÿ’ฐ Smart Expense โ€” AI-Powered Expense Management MCP

Track expenses, split bills with friends, manage group trips, and get spending analytics โ€” all through natural conversation with **Claude** or **ChatGPT**. No app to open, no forms to fill. Just talk.

Built with [FastMCP](https://gofastmcp.com) + SQLite, and hosted on **FastMCP Cloud**.

---

## โœจ What You Can Do

Just talk to Claude or ChatGPT naturally:

> "Add โ‚น450 expense at Domino's, Food category, paid via UPI, tags: dinner, friends"
> "How much did I spend on food this month?"
> "I paid โ‚น600 for Rahul for petrol"
> "Who owes me money?"
> "Create a Girnar Trip event with Rahul, Prince, and Jay"
> "Add โ‚น4000 hotel expense to Girnar Trip, split equally"
> "Who owes what in the Girnar trip?"
> "Set a โ‚น5000 budget for Food in July 2026"
> "Export July 2026 expenses to Excel"

The assistant figures out which tool to call and handles the rest.

---

## ๐Ÿงฉ Features

| Module | What it does |
|---|---|
| **Expenses** | Full CRUD, soft-delete/restore, tags, merchant, location, receipt URL |
| **Categories** | Dynamic categories & subcategories with emoji icons |
| **Filtering Engine** | 15+ dimensions โ€” date, category, amount range, merchant, tags, payment method, event |
| **Analytics** | Monthly/yearly summaries, category breakdown with %, budget utilization with alerts |
| **Splitwise (General)** | Record "I paid for X" / "X paid for me" โ€” net balance tracking per friend |
| **Splitwise (Events)** | Group trips with equal / percentage / custom splits, auto-settlement computation |
| **Settlement Engine** | Greedy two-pointer algorithm โ€” minimizes the number of settle-up transactions |
| **Budgets** | Per-category monthly budgets with ๐ŸŸข ๐ŸŸก ๐Ÿ”ด alert levels |
| **Recurring Expenses** | Auto-create entries for Netflix, Rent, Gym, etc. |
| **Reports** | Export to CSV and Excel (`.xlsx`) |

---

## ๐Ÿš€ Quick Start โ€” Connect to Your Assistant

This server is hosted on **FastMCP Cloud**, so there's nothing to install โ€” you just point your assistant at the server URL below.

> Replace `https://your-project.fastmcp.app/mcp` with your actual FastMCP Cloud deployment URL throughout this section.

### Connect with Claude (Desktop, Web, or Mobile)

1. Open **Settings โ†’ Connectors** in Claude (web/desktop) or ask Claude to open its connector settings.
2. Click **Add custom connector**.
3. Paste the server URL: `https://your-project.fastmcp.app/mcp`
4. Give it a name, e.g. `Smart Expense`.
5. Save, then enable it for your conversation.
6. Start chatting โ€” e.g. *"Add a โ‚น200 coffee expense today, paid by cash."*

**Claude Desktop (local config) alternative** โ€” add this to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "smart-expense-mcp": {
      "url": "https://expense-manager-mcp.fastmcp.app/mcp"
    }
  }
}
```

### Connect with ChatGPT

ChatGPT calls remote MCP servers through **Developer Mode** (currently available on Plus, Pro, Business, Enterprise, and Edu plans):

1. In ChatGPT, go to **Settings โ†’ Apps & Connectors โ†’ Advanced Settings**.
2. Toggle **Developer mode** ON.
3. Go back to **Apps**, click **Create**, and choose to add a custom app/connector.
4. Fill in:
   - **Name:** `Smart Expense`
   - **MCP server URL:** `https://expense-manager-mcp.fastmcp.app/mcp`
5. Click **Create**. ChatGPT will list the tools the server exposes.
6. In a new chat, click the **+** button โ†’ **More** โ†’ select **Smart Expense** to enable it for that conversation.
7. Start chatting โ€” e.g. *"Show my quick stats for this month."*

> Note: the connector must be re-enabled per conversation โ€” this is a ChatGPT behavior, not a limitation of this server.

---

## ๐Ÿ› ๏ธ Local Development

If you want to run or modify the server yourself:

```bash
git clone https://github.com/<your-username>/expense-agent.git
cd expense-agent
uv sync
uv run python src/server.py
```

Then point Claude Desktop at your local instance:

```json
{
  "mcpServers": {
    "smart-expense-mcp": {
      "command": "uv",
      "args": ["run", "python", "src/server.py"],
      "cwd": "/path/to/expense-agent"
    }
  }
}
```

### Environment Variables

| Variable | Purpose | Default |
|---|---|---|
| `DB_DIR` | Directory where `expenses.db` is stored | project root (local) |
| `REPORTS_DIR` | Directory where generated CSV/Excel reports are saved | `<DB_DIR>/reports` |

> โš ๏ธ **On FastMCP Cloud**, the local filesystem is not guaranteed to persist across restarts/redeploys. For production use with real user data, back this server with a hosted database (e.g. Turso/libSQL or Postgres) rather than a local SQLite file. See [`docs/persistence.md`](docs/persistence.md) if you're migrating.

---

## ๐Ÿ“ Project Structure

```
expense-agent/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ server.py                 โ† FastMCP entry point
โ”‚   โ”œโ”€โ”€ config.py                 โ† All constants & paths
โ”‚   โ”œโ”€โ”€ database/
โ”‚   โ”‚   โ”œโ”€โ”€ db.py                 โ† Connection manager (context-manager)
โ”‚   โ”‚   โ”œโ”€โ”€ models.py             โ† 11 table definitions
โ”‚   โ”‚   โ””โ”€โ”€ migrations.py         โ† Default categories seed
โ”‚   โ”œโ”€โ”€ schemas/
โ”‚   โ”‚   โ”œโ”€โ”€ expense.py            โ† ExpenseCreate, ExpenseUpdate, ExpenseFilters
โ”‚   โ”‚   โ”œโ”€โ”€ category.py           โ† CategoryCreate, SubcategoryCreate
โ”‚   โ”‚   โ”œโ”€โ”€ splitwise.py          โ† FriendCreate, BalanceCreate, EventExpenseCreate
โ”‚   โ”‚   โ””โ”€โ”€ analytics.py          โ† Response shapes
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ expense_service.py    โ† CRUD + dynamic filter engine
โ”‚   โ”‚   โ”œโ”€โ”€ analytics_service.py  โ† Summary, budget tracking
โ”‚   โ”‚   โ”œโ”€โ”€ split_service.py      โ† Balances + event splits
โ”‚   โ”‚   โ””โ”€โ”€ settlement_service.py โ† Minimal transactions algorithm
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ expense_tools.py      โ† MCP: create, get, update, delete, restore, list
โ”‚       โ”œโ”€โ”€ category_tools.py     โ† MCP: categories & subcategories
โ”‚       โ”œโ”€โ”€ analytics_tools.py    โ† MCP: summaries, budgets, recurring
โ”‚       โ”œโ”€โ”€ splitwise_tools.py    โ† MCP: friends, balances, settle
โ”‚       โ”œโ”€โ”€ event_tools.py        โ† MCP: events, splits, settlements
โ”‚       โ””โ”€โ”€ search_tools.py       โ† MCP: search, quick_stats, CSV, Excel
โ””โ”€โ”€ reports/                       โ† Generated CSV / Excel files (local dev only)
```

---

## ๐Ÿ“š MCP Tools Reference

### Expense Tools
| Tool | Description |
|---|---|
| `create_expense` | Add an expense with full metadata |
| `get_expense` | Get one expense by ID |
| `update_expense` | Update any fields of an expense |
| `delete_expense` | Soft-delete (recoverable) |
| `restore_expense` | Undo a delete |
| `list_expenses` | Filter by 15+ dimensions |

### Category Tools
`create_category` ยท `update_category` ยท `delete_category` ยท `list_categories` ยท `create_subcategory` ยท `move_subcategory`

### Analytics Tools
`expense_summary` ยท `monthly_summary` ยท `yearly_summary` ยท `payment_summary` ยท `budget_summary` ยท `set_budget`

### Recurring Tools
`add_recurring` ยท `list_recurring` ยท `process_recurring`

### Splitwise Tools
`add_friend` ยท `list_friends` ยท `record_balance` ยท `settle` ยท `friend_summary` ยท `overall_balance`

### Event Tools
`create_event` ยท `add_event_member` ยท `add_event_expense` ยท `event_summary` ยท `close_event`

### Search & Report Tools
`search_expenses` ยท `quick_stats` ยท `generate_csv` ยท `generate_excel`

---

## ๐Ÿงฎ The Settlement Algorithm

`event_summary` uses a **greedy two-pointer algorithm** to minimize the number of transactions needed to settle all debts in a group:

```
A owes B โ‚น100,  B owes C โ‚น100
โ†’ Naive:    A โ†’ B, B โ†’ C            (2 transactions)
โ†’ Optimal:  A โ†’ C                    (1 transaction)
```

Ask your assistant to *"explain the settlement algorithm"* for the full walkthrough.

---

## ๐Ÿ“ฆ Dependencies

```toml
fastmcp>=3.4.4
pydantic>=2.0
openpyxl
python-dateutil
```

---

## ๐Ÿ”’ Data & Privacy

This server stores your expense data in a database controlled by the deployment. Do not commit database files (`expenses.db`, `*.db-wal`, `*.db-shm`) to version control โ€” see `.gitignore`. If you're hosting this for multiple users, review your storage backend's data isolation and backup guarantees before relying on it for real financial records.

## ๐Ÿ“„ License

MIT โ€” see [`LICENSE`](LICENSE) for details.

TDQS

B3.4/5.0

Scored across 38 tools

Disambiguation5/5

Each tool serves a distinct purpose: CRUD operations for expenses, categories, friends, events, recurring expenses, plus various summaries and reports. Even overlapping tools like list_expenses and search_expenses have clear differentiators (structured filtering vs natural language). No ambiguity between tools.

Naming Consistency4/5

Most tools follow a consistent verb_noun pattern (e.g., add_event_expense, list_expenses, create_category). Summary tools use a noun_summary pattern (e.g., budget_summary, monthly_summary), which is also consistent. Minor exceptions like quick_stats (should be get_quick_stats) and settle (verb only) slightly break the pattern, but overall naming is predictable.

Tool Count3/5

With 38 tools, the set is quite large for an expense management server. While each tool has a specific role, the abundance of summary/report tools (8+) and separate list/search functions suggests some redundancy. A more streamlined set (25-30) could reduce cognitive load without losing functionality.

Completeness4/5

The tool surface covers core CRUD for expenses, categories, friends, events, and recurring expenses, along with settlement, budget tracking, and export features. Notable gaps: missing update/delete for friends, events, and recurring expenses, but these can be worked around. Overall, the essential workflows are supported.

Maintenance

ActivityMaintained
ResponsivenessNo issues