Expense Tracker MCP Server
An MCP server that lets Claude track, list, and summarize personal expenses through natural conversation, backed by SQLite and deployable locally or to FastMCP Cloud.
README
Expense Tracker MCP Server
A Model Context Protocol (MCP) server that lets Claude track, list, and summarize personal expenses through natural conversation — no spreadsheet or app UI required. Built with FastMCP, backed by SQLite, and deployable both locally and to FastMCP Cloud.
Why this project
MCP is how LLMs like Claude connect to real tools and data sources instead of just generating text. This project implements a complete, working MCP server end-to-end: tool definitions, a structured resource, an async database layer, and a client-connection story — from local stdio transport all the way to a cloud-hosted HTTP deployment proxied back into Claude Desktop.
What it does
Once connected, Claude can:
- Log an expense — "I spent ₹450 on groceries today" → written to the database with date, amount, category, subcategory, and note
- List expenses — "What did I spend last week?" → returns every expense in a date range
- Summarize spending — "How much did I spend on food this month?" → aggregates total amount and count per category over a date range
- Discover valid categories — Claude reads a structured category resource to know what categories/subcategories are valid before logging an expense, rather than guessing
MCP Components
Tools (main.py)
| Tool | Description |
|---|---|
add_expense(date, amount, category, subcategory, note) |
Inserts a new expense row; returns the new row's ID or a structured error |
list_expenses(start_date, end_date) |
Returns all expenses in an inclusive date range, most recent first |
summarize(start_date, end_date, category=None) |
Returns total amount and count per category in a date range, optionally filtered to one category |
Resource
expense:///categories— exposescategories.json, a structured taxonomy of 20 top-level categories (food, transport, housing, utilities, health, education, family & kids, entertainment, shopping, subscriptions, personal care, gifts & donations, finance fees, business, travel, home, pet, taxes, investments, misc), each with realistic subcategories. Falls back to a sensible default category list if the file isn't found.
Data layer
- SQLite database (
expenses.db), withWALjournal mode for better concurrent read/write behavior - Synchronous
sqlite3used once at startup to initialize the schema and verify write access; all runtime tool calls useaiosqlitefor non-blocking async I/O - Database path resolved via the system temp directory, making the server safe to run in ephemeral/cloud filesystem environments
Transport & Deployment (proxy.py)
- The server runs over Streamable HTTP when deployed (
mcp.run(transport="http", ...)) - A separate proxy (
proxy.py) wraps the deployed FastMCP Cloud endpoint and re-exposes it over STDIO, which is the transport Claude Desktop expects for local MCP connections — bridging a cloud-hosted server into a local desktop client
Architecture
flowchart LR
subgraph Local["Local Machine"]
CD[Claude Desktop] -->|STDIO| PX["proxy.py<br/>FastMCP.as_proxy"]
end
PX -->|Streamable HTTP| Cloud
subgraph Cloud["FastMCP Cloud"]
SRV["main.py<br/>FastMCP Server"]
SRV --> T1[add_expense]
SRV --> T2[list_expenses]
SRV --> T3[summarize]
SRV --> R1["expense:///categories<br/>resource"]
end
T1 --> DB[(SQLite<br/>expenses.db<br/>WAL mode)]
T2 --> DB
T3 --> DB
R1 --> CAT[categories.json]
Tech Stack
| Layer | Technology |
|---|---|
| Protocol | Model Context Protocol (MCP) |
| Server framework | FastMCP |
| Database | SQLite, aiosqlite (async), sqlite3 (sync init) |
| Transport | Streamable HTTP (cloud), STDIO (local proxy → Claude Desktop) |
| Deployment | FastMCP Cloud |
| Package management | uv (pyproject.toml + uv.lock) |
| Language | Python 3.11+ |
Getting Started
Prerequisites
- Python 3.11+
uvfor dependency management- Claude Desktop (to connect via the local proxy)
Installation
git clone <your-repo-url>
cd <repo-name>
uv sync
Run the server locally
uv run main.py
The server starts on http://0.0.0.0:8000 using Streamable HTTP transport, and initializes the SQLite schema on first run.
Connect Claude Desktop via the proxy
Add the proxy to your Claude Desktop MCP config (claude_desktop_config.json):
{
"mcpServers": {
"expense-tracker": {
"command": "uv",
"args": ["run", "python", "proxy.py"]
}
}
}
The proxy connects to the deployed FastMCP Cloud endpoint over Streamable HTTP and re-exposes it to Claude Desktop over STDIO — restart Claude Desktop after adding the config.
Deploying your own instance
- Push the repo to a Git provider
- Deploy
main.pyon FastMCP Cloud (or any host that can run a Streamable HTTP server) - Update the URL in
proxy.pyto point to your deployed endpoint
Project Structure
.
├── main.py # MCP server: tools, resource, DB init
├── proxy.py # STDIO proxy → deployed FastMCP Cloud server
├── categories.json # Expense category/subcategory taxonomy
├── expenses.db # SQLite database (created/used at runtime)
├── pyproject.toml # Project metadata + dependencies (uv)
├── uv.lock # Locked dependency versions
└── .python-version # Pinned Python version
Design Notes
- Sync init, async runtime. Schema creation and a write-access check happen synchronously once at startup (fail fast, fail loud); all subsequent tool calls are fully async so the server doesn't block under concurrent requests.
- Resource-driven category discovery. Rather than hardcoding categories into the tool schema, Claude is expected to read the
expense:///categoriesresource first — keeping category logic in one editable JSON file instead of scattered across tool code. - Cloud-safe file paths. Using the system temp directory for the database avoids permission issues on read-only or ephemeral cloud filesystems.
License
Add a license of your choice (e.g., MIT).
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。