An MCP (Model Context Protocol) server for managing and analyzing personal expenses from CSV files.
- Add expenses to a CSV file with categorization
- Get recent expenses with day-based filtering
- MCP Resource for direct access to all expenses
- Specialized prompt that generates automatic analytical summaries
- Analysis by category and payment method
- Trend detection and spending patterns
pip install fastmcp mcpexpenses-mcp-server/
βββ server.py # Main MCP server
βββ data/
β βββ expenses.csv # Expenses file (created automatically)
βββ requirements.txt
βββ README.md
mkdir expenses-mcp-server
cd expenses-mcp-serverpython -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windowspip install fastmcp mcppython server.pyAdds a new expense to the system.
Parameters:
fecha: Date in 'YYYY-MM-DD' formatcategoria: Expense category (e.g., "Food", "Transport")cantidad: Expense amount (float)metodo_pago: Payment method used
Example:
agregar_gasto("2024-01-15", "Groceries", 150.75, "Debit Card")Gets expenses from the last N days.
Parameters:
dias: Number of days to query (default: 5)
Example:
obtener_gastos_recientes(7) # Last 7 daysDirect access to all stored expenses.
Generates a prompt with structured data for AI to create a complete analysis including:
- π Statistical calculations (totals, averages)
- π·οΈ Category analysis
- π³ Payment method distribution
- π Trend identification
- π‘ Personalized recommendations
The data/expenses.csv file has the following structure:
fecha,categoria,cantidad,metodo_pago
2024-01-15,Groceries,150.75,Debit Card
2024-01-16,Transport,45.50,Cash
2024-01-17,Entertainment,89.99,Credit Card
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
server_params = StdioServerParameters(
command="python",
args=["server.py"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize session
await session.initialize()
# Add expense
result = await session.call_tool(
"agregar_gasto",
{
"fecha": "2024-01-18",
"categoria": "Restaurant",
"cantidad": 85.50,
"metodo_pago": "Credit Card"
}
)
print(result)
# Get recent expenses
expenses = await session.call_tool(
"obtener_gastos_recientes",
{"dias": 5}
)
print(expenses)
if __name__ == "__main__":
asyncio.run(main())# Add transport expense
agregar_gasto("2024-01-18", "Transport", 35.00, "Cash")
# Add food expense
agregar_gasto("2024-01-18", "Food", 120.00, "Debit Card")# Get last week summary
obtener_gastos_recientes(7)# Complete 30-day analysis
obtener_gastos_recientes(30)The specialized prompt generates analysis like:
π EXPENSE SUMMARY - LAST 5 DAYS
π° TOTAL SPENT: $1,245.75
π
DAILY AVERAGE: $249.15
π’ TRANSACTIONS: 8 purchases
π·οΈ CATEGORY DISTRIBUTION:
β’ Groceries: 45% ($560.25)
β’ Transport: 25% ($311.44)
β’ Entertainment: 20% ($249.15)
β’ Restaurant: 10% ($124.58)
π³ PAYMENT METHODS:
β’ Credit Card: 60%
β’ Debit Card: 30%
β’ Cash: 10%
π OBSERVATIONS:
β’ Highest spending on Wednesday ($420.50)
β’ "Groceries" category represents almost half of expenses
β’ Growing trend in credit card usage
π‘ RECOMMENDATIONS:
β’ Consider bulk purchases to reduce grocery expenses
β’ Diversify payment methods for better control
β’ Set weekly limit for entertainment
- Ensure the
data/directory exists - Server creates the file automatically with the first expense
- Server uses UTF-8 for special character compatibility
- Use exact format:
YYYY-MM-DD - Example:
2024-01-18
MIT License
For issues and questions, open a ticket in the project repository.
Start tracking your expenses intelligently! π