Skip to main content
Glama
abhisek0407

Expense Tracker Remote MCP Server

by abhisek0407
README.md
# ๐Ÿ’ฐ Expense Tracker Remote MCP Server
 
A simple **Model Context Protocol (MCP) server** built with **Python and FastMCP** that provides tools for managing and analyzing personal expenses through an SQLite database.
 
The server supports adding expenses, retrieving expenses within a date range, summarizing expenses by category, and accessing available expense categories as an MCP resource.
 
---
 
## ๐Ÿš€ Features
 
- โž• Add new expense records
- ๐Ÿ“‹ List expenses within a specific date range
- ๐Ÿ“Š Summarize expenses by category
- ๐Ÿ—‚๏ธ Expose expense categories through an MCP resource
- ๐Ÿ’พ Persistent storage using SQLite
- ๐ŸŒ Runs as a remote/HTTP MCP server
- ๐Ÿ”Œ Compatible with MCP clients and MCP Inspector
- โšก Built with FastMCP
---
 
## ๐Ÿ› ๏ธ Tech Stack
 
- **Python**
- **FastMCP**
- **Model Context Protocol (MCP)**
- **SQLite**
- **uv** โ€“ Python package/project manager
- **JSON**
---
 
## ๐Ÿ“ Project Structure
 
```text
Expense_Tracker_Remote_MCP_Server/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ test_remote_mcp_server/
โ”‚       โ””โ”€โ”€ __init__.py
โ”‚
โ”œโ”€โ”€ categories.json
โ”œโ”€โ”€ expenses.db
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ uv.lock
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md
```
 
### Important Files
 
| File | Purpose |
|---|---|
| `main.py` | Main MCP server implementation |
| `expenses.db` | SQLite database containing expense records |
| `categories.json` | Expense category data |
| `pyproject.toml` | Project dependencies and configuration |
| `uv.lock` | Locked dependency versions |
| `.gitignore` | Files excluded from Git |
| `README.md` | Project documentation |
 
---
 
## โš™๏ธ How It Works
 
The MCP server uses FastMCP to expose expense-management functionality as MCP tools.
 
```
                    MCP Client
                        โ”‚
                        โ–ผ
                FastMCP MCP Server
                        โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ–ผ             โ–ผ             โ–ผ
    add_expense    list_expenses   summarize
          โ”‚             โ”‚             โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ–ผ
                   SQLite DB
                  expenses.db
```
 
The server also exposes:
 
```
expense://categories
```
 
as an MCP resource for retrieving available expense categories.
 
---
 
## ๐Ÿ”ง MCP Tools
 
### 1. `add_expense`
 
Adds a new expense to the SQLite database.
 
**Parameters**
 
| Parameter | Type | Required | Description |
|---|---|---|---|
| `date` | string | Yes | Date of the expense |
| `amount` | number | Yes | Expense amount |
| `category` | string | Yes | Expense category |
| `subcategory` | string | No | Expense subcategory |
| `note` | string | No | Additional note |
 
**Example**
 
```python
add_expense(
    date="2026-08-29",
    amount=250,
    category="Food",
    subcategory="Lunch",
    note="Lunch at college"
)
```
 
Example response:
 
```json
{
  "status": "ok",
  "id": 1
}
```
 
### ๐Ÿ“‹ 2. `list_expenses`
 
Returns expense records within an inclusive date range.
 
**Parameters**
 
| Parameter | Type | Required | Description |
|---|---|---|---|
| `start_date` | string | Yes | Starting date |
| `end_date` | string | Yes | Ending date |
 
**Example**
 
```python
list_expenses(
    start_date="2026-08-01",
    end_date="2026-08-29"
)
```
 
Example response:
 
```json
[
  {
    "id": 1,
    "date": "2026-08-29",
    "amount": 250,
    "category": "Food",
    "subcategory": "Lunch",
    "note": "Lunch at college"
  }
]
```
 
### ๐Ÿ“Š 3. `summarize`
 
Summarizes expenses by category within an inclusive date range.
 
An optional category can be provided to filter the results.
 
**Parameters**
 
| Parameter | Type | Required | Description |
|---|---|---|---|
| `start_date` | string | Yes | Starting date |
| `end_date` | string | Yes | Ending date |
| `category` | string | No | Optional category filter |
 
**Example**
 
```python
summarize(
    start_date="2026-08-01",
    end_date="2026-08-29"
)
```
 
Example response:
 
```json
[
  {
    "category": "Food",
    "total_amount": 2500
  },
  {
    "category": "Transport",
    "total_amount": 1200
  }
]
```
 
You can also filter by category:
 
```python
summarize(
    start_date="2026-08-01",
    end_date="2026-08-29",
    category="Food"
)
```
 
---
 
## ๐Ÿ—‚๏ธ MCP Resource
 
The server exposes the following resource:
 
```
expense://categories
```
 
This resource reads the contents of:
 
```
categories.json
```
 
The file is read each time the resource is requested, meaning category changes can be reflected without restarting the server.
 
---
 
## ๐Ÿ’พ Database
 
The server uses SQLite for persistent expense storage.
 
The database contains the following table:
 
**expenses**
 
with the following columns:
 
| Column | Type | Description |
|---|---|---|
| `id` | INTEGER | Primary key |
| `date` | TEXT | Expense date |
| `amount` | REAL | Expense amount |
| `category` | TEXT | Expense category |
| `subcategory` | TEXT | Expense subcategory |
| `note` | TEXT | Additional information |
 
The database table is automatically created when the server starts if it does not already exist.
 
---
 
## ๐Ÿงฐ Installation
 
### Prerequisites
 
Make sure you have:
 
- Python 3.10+
- uv
- Git
### 1. Clone the repository
 
```bash
git clone https://github.com/abhisek0407/Expense_Tracker_Remote_MCP_Server.git
cd Expense_Tracker_Remote_MCP_Server
```
 
### 2. Install dependencies
 
If the project already contains `pyproject.toml` and `uv.lock`:
 
```bash
uv sync
```
 
---
 
## โ–ถ๏ธ Run the MCP Server
 
The server is configured to run using Streamable HTTP on port 8000.
 
Start the server with:
 
```bash
uv run python main.py
```
 
The server will listen on:
 
```
http://localhost:8000
```
 
The MCP endpoint is:
 
```
http://localhost:8000/mcp
```
 
---
 
## ๐Ÿ” Test With MCP Inspector
 
You can test the server locally using MCP Inspector.
 
In another terminal:
 
```bash
uv run fastmcp dev inspector main.py
```
 
Then configure the Inspector with:
 
- **Transport Type:** Streamable HTTP
- **URL:** `http://localhost:8000/mcp`
- **Connection Type:** Via Proxy
Click **Connect**.
 
Once connected, the Inspector should expose:
 
**Tools**
- `add_expense`
- `list_expenses`
- `summarize`
**Resource**
- `expense://categories`
---
 
## ๐ŸŒ Remote Deployment
 
This project can be deployed as a remote MCP server using a platform such as FastMCP Cloud.
 
The server uses:
 
```python
mcp.run(
    transport="http",
    host="0.0.0.0",
    port=8000
)
```
 
This allows the MCP server to accept HTTP connections instead of only operating through STDIO.
 
After deployment, the MCP server can be accessed through the remote endpoint provided by the hosting platform.
 
For example:
 
```
https://your-server.fastmcp.app/mcp
```
 
The actual URL depends on the server name and deployment configuration.
 
---
 
## ๐Ÿ” Environment Variables
 
Currently, the server does not require any external API keys or authentication credentials.
 
If authentication or external services are added in the future, environment variables can be configured through the deployment platform.
 
---
 
## ๐Ÿงช Example Workflow
 
A typical interaction with the MCP server can look like:
 
```
User
 โ”‚
 โ”‚ "Add โ‚น500 spent on food today"
 โ–ผ
MCP Client
 โ”‚
 โ”‚ add_expense()
 โ–ผ
Expense Tracker MCP Server
 โ”‚
 โ–ผ
SQLite Database
 โ”‚
 โ”‚ Expense stored
 โ–ผ
MCP Response
 โ”‚
 โ–ผ
MCP Client
```
 
For analysis:
 
```
User
 โ”‚
 โ”‚ "How much did I spend by category this month?"
 โ–ผ
MCP Client
 โ”‚
 โ”‚ summarize()
 โ–ผ
Expense Tracker MCP Server
 โ”‚
 โ–ผ
SQLite
 โ”‚
 โ”‚ GROUP BY category
 โ–ผ
Category-wise totals
```
 
---
 
## ๐Ÿ“Œ Current Limitations
 
- No authentication mechanism is currently implemented.
- The server currently uses a local SQLite database.
- No user/account separation is implemented.
- Date values are stored as text and should follow a consistent date format such as `YYYY-MM-DD`.
- Categories are loaded from a local `categories.json` file.
---
 
## ๐Ÿšง Future Improvements
 
Possible improvements include:
 
- ๐Ÿ” Authentication and authorization
- ๐Ÿ‘ค Multiple user support
- โ˜๏ธ Cloud database integration
- ๐Ÿ“ˆ Advanced expense analytics
- ๐Ÿ’ฐ Budget tracking
- ๐Ÿ”” Budget alerts
- ๐Ÿ“… Monthly and yearly reports
- ๐Ÿ“Š Spending visualization
- ๐Ÿท๏ธ Custom categories
- ๐Ÿค– AI-powered spending insights
- ๐Ÿงพ Receipt processing
- ๐Ÿ’ฑ Multi-currency support
---
 
## ๐ŸŽฏ Purpose of the Project
 
This project was created to learn and demonstrate the implementation of an MCP server using FastMCP, including:
 
- MCP tools
- MCP resources
- SQLite integration
- HTTP/Streamable HTTP transport
- Local MCP server testing
- MCP Inspector
- Remote MCP server deployment
It serves as a practical example of connecting an AI/MCP client with a persistent backend application.
 
---
 
## ๐Ÿ“„ License
 
This project is available for educational and personal use.