Skip to main content
Glama
mrmohdmaaz0786-cell

SpendWise MCP

README.md
# SpendWise MCP ๐Ÿ“Š

[![CI](https://github.com/mrmohdmaaz0786-cell/spendwise-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/mrmohdmaaz0786-cell/spendwise-mcp/actions/workflows/ci.yml)

**SpendWise** is a secure, multi-tenant expense-tracking server exposed through the **Model Context Protocol (MCP)**. It allows AI agents (like Claude, Grok, or Cursor) to manage personal finances, analyze spending habits, enforce budgets, and send real-time Telegram alerts.

Built with a focus on production-grade security, strict data validation, and multi-tenant data isolation.

## โœจ Key Features

### ๐Ÿงพ Core Expense Management
- **Full CRUD**: Create, read, update, and soft-delete expenses.
- **Idempotency & Safety**: Prevents accidental duplicate entries and safely handles network retries using idempotency keys.
- **Multi-Currency Support**: Tracks expenses in any 3-letter currency code (INR, USD, EUR, etc.) without mixing them.

### ๐Ÿ“ˆ Financial Analytics
- **Spending Summaries**: Aggregate active spending by category, month, or merchant over custom date ranges.
- **Period Comparison**: Compare spending across two date ranges with absolute and percentage changes.

### ๐Ÿ’ฐ Budget Management & Alerts
- **Dynamic Budgets**: Set weekly or monthly spending limits per category (upsert logic).
- **Status Tracking**: Automatically calculates budget health (๐ŸŸข Healthy, ๐ŸŸก Warning at 80%, ๐Ÿ”ด Over Budget at 100%).
- **Telegram Alerts**: Sends real-time notifications via the **CallMeBot API** when budgets are at risk.

### ๐Ÿ” Multi-Tenant Security
- **Strict Isolation**: Every expense and budget is scoped to the authenticated user.
- **Dual Auth**: Supports Auth0 RS256 JWTs for production and legacy API keys for local testing.
- **Server-Side Identity**: User identity is derived strictly from verified JWT claims, preventing client-side spoofing.

---

## ๐Ÿ›  Tech Stack

- **Core**: Python 3.12, MCP SDK (Streamable HTTP), Starlette, Uvicorn
- **Database**: SQLAlchemy 2.0, Alembic (Migrations), SQLite (Local), PostgreSQL (Production)
- **Validation**: Pydantic V2 (Strict schemas, custom validators)
- **Auth**: Auth0 (OAuth2 / JWT RS256)
- **Notifications**: CallMeBot (Telegram API), httpx
- **Testing & CI**: Pytest, Ruff (Lint/Format), GitHub Actions

---

## ๐Ÿš€ Quick Start

### Requirements
- Python 3.12+
- [uv](https://docs.astral.sh/uv/) (Python package manager)

### Local Setup

1. **Install dependencies:**
   ```powershell
   uv sync


### PROJECT STRUCTURE

spendwise-mcp/
โ”œโ”€โ”€ .github/workflows/     # CI/CD pipeline (lint, test, migration checks)
โ”œโ”€โ”€ alembic/versions/      # Database schema migrations
โ”œโ”€โ”€ src/spendwise/
โ”‚   โ”œโ”€โ”€ app.py             # Starlette ASGI app & Auth middleware
โ”‚   โ”œโ”€โ”€ auth.py            # Auth0 JWT & API key verification
โ”‚   โ”œโ”€โ”€ db.py              # SQLAlchemy engine & session management
โ”‚   โ”œโ”€โ”€ models.py          # Expense & Budget ORM models
โ”‚   โ”œโ”€โ”€ notifications.py   # CallMeBot Telegram client
โ”‚   โ”œโ”€โ”€ schemas.py         # Pydantic V2 validation schemas
โ”‚   โ””โ”€โ”€ server.py          # MCP server & 14 tool definitions
โ”œโ”€โ”€ tests/                 # 66 isolated Pytest cases
โ”œโ”€โ”€ render.yaml            # Infrastructure as Code for Render
โ””โ”€โ”€ pyproject.toml         # Project metadata & dependencies