Expense Tracker MCP Server
Parses PDF receipts to extract grocery and shopping expenses, automatically categorizes items using smart rules and LLM fallback, and stores them in a local SQLite database for querying purchase history and spending patterns.
README
Expense Tracker MCP Server
A local Model Context Protocol (MCP) server that helps you track grocery and shopping expenses by parsing PDF receipts, automatically categorizing items, and storing them in a SQLite database for easy querying.
Features
- PDF Receipt Parsing: Extract line items, prices, and metadata from PDF receipts
- Smart Categorization: Hybrid approach using static rules + LLM fallback for item classification
- SQLite Storage: Persistent local database for all your expense data
- Query Tools: Ask questions like "When did I last buy milk?" or "How often do I buy bread?"
- Multi-Store Support: Works with receipts from Walmart, Costco, Target, and more
Installation
Prerequisites
- Python 3.11 or higher
- uv (recommended) or pip
Step 1: Clone or Download
cd /Users/sharan/Desktop/expense_tracker_mcp
Step 2: Install Dependencies
Using uv (recommended):
uv sync
Using pip:
pip install -r requirements.txt
Step 3: Initialize Database
The database is automatically initialized when you first run the server. The SQLite database will be created at data/expenses.db.
Running Locally
To test the server locally:
python main.py
or with uv:
uv run main.py
The server will start and listen on stdin/stdout (MCP protocol).
Connecting to Claude Desktop
Step 1: Locate Claude Desktop Config
The configuration file is located at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Step 2: Add MCP Server Configuration
Edit the config file and add this entry to mcpServers:
{
"mcpServers": {
"expense-tracker": {
"command": "uv",
"args": [
"--directory",
"/Users/sharan/Desktop/expense_tracker_mcp",
"run",
"main.py"
]
}
}
}
Alternative (using python directly):
{
"mcpServers": {
"expense-tracker": {
"command": "/Users/sharan/Desktop/expense_tracker_mcp/.venv/bin/python",
"args": [
"/Users/sharan/Desktop/expense_tracker_mcp/main.py"
]
}
}
}
Step 3: Restart Claude Desktop
After saving the config, restart Claude Desktop to load the MCP server.
Usage
Once connected to Claude Desktop, you can use these tools:
1. Import a Receipt
Upload a PDF receipt and the server will parse it:
Import this receipt: /path/to/walmart_receipt.pdf
Example Response:
{
"status": "success",
"receipt_id": 1,
"store_name": "Walmart",
"purchase_date": "2025-01-15",
"total": 45.67,
"items_count": 12,
"item_types": {
"milk": 1,
"bread": 1,
"eggs": 1,
"veggies": 3,
"snacks": 2,
"beverages": 2,
"meat": 2
}
}
2. Query Item History
Ask when you last bought something:
When did I last buy milk?
or
Show me all my milk purchases in the last 6 months
Example Response:
{
"item_type": "milk",
"purchases": [
{
"date": "2025-01-15",
"store": "Walmart",
"item_name": "Organic Milk 2%",
"quantity": 1.0,
"price": 4.99
},
{
"date": "2024-12-28",
"store": "Costco",
"item_name": "Kirkland Milk",
"quantity": 2.0,
"price": 6.99
}
],
"stats": {
"total_purchases": 2,
"last_purchase_date": "2025-01-15",
"first_purchase_date": "2024-12-28",
"average_days_between": 18.0,
"total_spent": 11.98
}
}
3. List All Categories
See all item types you've purchased:
What categories of items have I bought?
Example Response:
{
"item_types": [
{
"item_type": "milk",
"total_purchases": 12,
"last_purchase_date": "2025-01-15",
"total_spent": 59.88
},
{
"item_type": "bread",
"total_purchases": 8,
"last_purchase_date": "2025-01-10",
"total_spent": 27.92
}
],
"total_categories": 15
}
Supported Item Categories
The categorizer recognizes these item types out of the box:
Dairy: milk, oatmilk, eggs, cheese, yogurt, butter
Grains: bread, rice, lentils, pasta, cereal
Produce: veggies, fruits, potatoes
Proteins: meat, fish
Snacks & Beverages: snacks, beverages
Pantry: oil, spices, sauce
Household: cleaning, paper
Fallback: other (for unrecognized items)
Adding New Categories
Edit expense_tracker/categorizer.py and add patterns to the ITEM_TYPE_MAPPINGS dictionary:
ITEM_TYPE_MAPPINGS = {
# ... existing categories ...
"tofu": ["tofu", "bean curd", "soy protein"],
}
Database Schema
The SQLite database (data/expenses.db) contains two main tables:
receipts
id: Auto-increment primary keystore_name: Store name (e.g., "Walmart")purchase_date: ISO format date (YYYY-MM-DD)subtotal: Subtotal amount (nullable)tax: Tax amount (nullable)total: Total amount (required)created_at: Timestamp
items
id: Auto-increment primary keyreceipt_id: Foreign key to receipts tableitem_name_raw: Original item name from receiptitem_type: Normalized categoryquantity: Item quantity (default: 1.0)unit_price: Price per unit (nullable)line_total: Total price for this linecreated_at: Timestamp
How It Works
1. PDF Parsing
Uses pdfplumber to extract text from PDF files, then applies regex patterns to identify:
- Store name (Walmart, Costco, Target, etc.)
- Purchase date (multiple date formats supported)
- Line items with quantities and prices
- Totals (subtotal, tax, total)
2. Item Categorization
Hybrid approach:
-
Static Rules (fast, deterministic)
- Checks item name against pre-defined patterns
- Handles common grocery items with keyword matching
- ~90% accuracy for typical grocery items
-
LLM Fallback (smart, adaptive)
- Uses Claude via FastMCP's
Context.sample()for unknown items - Provides better accuracy for unusual or new items
- Automatically adapts to items not in static mappings
- Uses Claude via FastMCP's
3. Database Storage
All data is stored in a local SQLite database with proper indexing for fast queries:
- Indexes on
purchase_date,store_name,item_type - Foreign key constraints for data integrity
- Support for aggregate queries and statistics
Troubleshooting
Server not appearing in Claude Desktop
- Check that the path in
claude_desktop_config.jsonis correct - Restart Claude Desktop completely
- Check Claude Desktop logs for errors
PDF parsing errors
- Ensure the PDF is text-based (not a scanned image)
- Try opening the PDF in a viewer to verify it contains selectable text
- Check that the file path is absolute, not relative
Database locked errors
- Close any other tools accessing
data/expenses.db - Make sure only one instance of the server is running
Development
Running Tests
pytest tests/
Adding New Features
The modular architecture makes it easy to extend:
- New categorization rules: Edit
expense_tracker/categorizer.py - New receipt formats: Update patterns in
expense_tracker/pdf_parser.py - New MCP tools: Add tool functions to
main.pywith@mcp.tooldecorator - Database changes: Modify schema in
expense_tracker/database.py
License
MIT License - feel free to use and modify for your needs.
Contributing
Contributions welcome! Areas for improvement:
- Support for more receipt formats
- Better item categorization rules
- Export to CSV/Excel functionality
- Visualization dashboards
- Multi-user support
Support
For issues or questions:
- Check the FastMCP documentation
- Review MCP protocol docs
- File an issue on GitHub
Built with FastMCP - The fast, Pythonic way to build MCP servers
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。