Smart Expense Management MCP
# ๐ฐ 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
Scored across 38 tools
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.
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.
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.
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.