Expense Tracker MCP Server
Stores parsed receipt data, expense items, and purchase history in a local SQLite database with support for querying transactions, item categories, and spending statistics.
Parses PDF receipts from Target stores to extract line items, prices, and purchase metadata for expense tracking.
Parses PDF receipts from Walmart stores to extract line items, prices, and purchase metadata for expense tracking.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Expense Tracker MCP Server When did I last buy eggs?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Related MCP server: Expense Tracker MCP Server
Installation
Prerequisites
Python 3.11 or higher
uv (recommended) or pip
Step 1: Clone or Download
cd /Users/sharan/Desktop/expense_tracker_mcpStep 2: Install Dependencies
Using uv (recommended):
uv syncUsing pip:
pip install -r requirements.txtStep 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.pyor with uv:
uv run main.pyThe 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.jsonWindows:
%APPDATA%/Claude/claude_desktop_config.jsonLinux:
~/.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.pdfExample 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 monthsExample 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 itemsProvides better accuracy for unusual or new items
Automatically adapts to items not in static mappings
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_typeForeign 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 correctRestart 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.dbMake 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.pyNew receipt formats: Update patterns in
expense_tracker/pdf_parser.pyNew MCP tools: Add tool functions to
main.pywith@mcp.tooldecoratorDatabase 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
Available Tools
3 toolsget_item_historyA
Query purchase history for a specific item type.
Returns detailed purchase history including:
List of all purchases with dates, stores, quantities, and prices
Statistics: total purchases, date range, average frequency, total spent
Args: item_type: Category to query (e.g., 'milk', 'bread', 'eggs') time_range_days: Number of days to look back (default: 365)
Returns: Dictionary with purchases list and aggregated statistics
Inputs: item_type (required), time_range_days. Returns: object
import_receipt_from_pdfA
Import and parse a receipt from a PDF file.
This tool:
Extracts text from the PDF
Parses receipt metadata (store, date, totals)
Extracts line items with prices
Categorizes each item using hybrid approach (static rules + LLM)
Stores everything in SQLite database
Args: pdf_path: Absolute path to the PDF receipt file ctx: FastMCP context for logging and LLM access
Returns: Summary of imported receipt including store, date, item count, and category breakdown
Inputs: pdf_path (required). Returns: object
list_item_typesA
List all item types/categories in the database with statistics.
Returns summary statistics for each item type including:
Total number of purchases
Most recent purchase date
Total amount spent
Useful for getting an overview of all tracked expense categories.
Returns: Dictionary with list of all item types and their statistics
Inputs: no named parameters. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: get_item_history retrieves detailed purchase history for a specific item, import_receipt_from_pdf processes new receipts into the database, and list_item_types provides an overview of all tracked categories. There is no overlap in functionality, and an agent could easily select the appropriate tool based on the task.
The tool names follow a consistent verb_noun pattern (get_item_history, import_receipt_from_pdf, list_item_types), making them predictable and readable. The minor deviation is that 'import_receipt_from_pdf' includes a preposition ('from'), but this does not significantly impact consistency or clarity.
With only 3 tools, the server feels slightly thin for an expense tracker domain, as it lacks operations like updating or deleting entries, or querying by other criteria (e.g., date ranges or stores). However, the tools cover core functionalities (import, query history, list categories), so it is borderline but functional.
The tool set covers basic import and query operations but has notable gaps: there are no tools for updating or deleting data, managing stores or receipts beyond import, or advanced filtering (e.g., by date or store). This could lead to agent failures if such operations are needed, though core workflows (adding receipts and viewing history) are supported.
Related MCP Connectors
Capture and organize receipts from your AI chat: totals, categories, ledgers.
Track expenses from receipt photos, then search, summarize and update them from your AI assistant.
Convert PDF bank statements into structured transactions, accounts, and balances.
Turn bank statement PDFs into categorized, balance-checked transactions and reports.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables extraction of structured data from documents like invoices, receipts, and bank statements using local Vision AI (Ollama) or cloud providers (Gemini), with data stored in a local SQLite database.MIT
- FlicenseAqualityDmaintenanceEnables AI assistants like Claude to manage personal expenses locally using SQLite. Supports adding, categorizing, summarizing expenses, setting budgets, and exporting data without cloud services.8-
- FlicenseAqualityDmaintenanceParses Italian INAZ payslip PDFs into a local SQLite database, enabling AI clients to analyze salary history, search items, and get detailed breakdowns while keeping data on your machine.51-
- FlicenseAqualityDmaintenanceEnables natural language management of personal expenses, including adding, updating, deleting, searching, and summarizing expenses stored in a local SQLite database.6-