expense-tracker

expense-tracker

Enables natural language expense logging, parsing amounts, currencies, and dates, and storing entries in an Excel file.

Category
访问服务器

README

Expense Tracker MCP Server

Enterprise-grade documentation for a Python-based Model Context Protocol (MCP) expense tracking server.

⚠️ Proof of Concept (PoC)

This is a quick and dirty implementation based on frameworks and libraries available as of February 2026.

Behavior, APIs, and integration patterns may evolve in future versions of FastMCP, OpenAI Codex, and related tooling. This is just for demonstrative purposes


Table of Contents

  1. Introduction
  2. Architecture Overview
  3. Environment Setup (uv-based)
  4. Installed Packages
  5. Project Structure
  6. MCP Server Overview
  7. Core Functional Components
  8. Excel Storage Layer
  9. Running the Server
  10. Testing with MCP Inspector
  11. Integrating with Codex in VS Code
  12. Operational Considerations
  13. Future Improvements

1. Introduction

This project implements a local Model Context Protocol (MCP) server using Python and FastMCP.

📢 Educational Proof of Concept

This repository contains intentionally simple and demonstrative code designed to get started with MCP servers and understand how they work. The implementation prioritizes clarity and approachability over production-grade architecture, advanced patterns, or highly optimized design.

The server allows natural-language expense logging such as:

"I spent 20 dollars on a Batman figure yesterday"

The server:

  • Parses the amount
  • Detects currency
  • Extracts relative or explicit dates
  • Stores the result in an Excel file
  • Exposes tools via MCP for AI agents (e.g., OpenAI Codex in VS Code)

This project demonstrates:

  • Local stdio-based MCP server design
  • Natural language parsing
  • Structured data persistence
  • Tool registration via FastMCP
  • Integration with OpenAI Codex UI

Example result in Codex on VS Code

MCP Architecture


2. Architecture Overview

The solution consists of:

  • FastMCP stdio server
  • Natural language parser
  • Excel persistence layer (openpyxl)
  • Tool registration via decorators
  • Local stdio transport for MCP communication

Transport Type: - STDIO (standard input/output)

Data Storage: - Excel file (expenses.xlsx)

Execution Model: - Event-driven tool invocation


3. Environment Setup (uv-based)

The environment was configured using uv for fast dependency management.

Initialize project

uv init

Add required packages

uv add fastmcp openpyxl dateparser pypandoc

This creates:

  • Virtual environment
  • Dependency resolution
  • Lockfile
  • Reproducible environment

4. Installed Packages

Package Purpose


fastmcp MCP server implementation openpyxl Excel read/write operations dateparser Natural language date parsing pypandoc Documentation generation re Regex amount parsing pathlib File handling datetime Timestamp management


5. Project Structure

project-root/
│
├── server.py
├── expenses.xlsx
├── README.md
└── .venv/

6. MCP Server Overview

The server is initialized as:

mcp = FastMCP("expense-tracker")

Tools are registered using:

@mcp.tool

The server starts via:

if __name__ == "__main__":
    mcp.run()

The server communicates using STDIO and must not print to stdout.


7. Core Functional Components

7.1 _parse_amount(raw)

Extracts numeric amount using regex. Handles: - 12.000,16 - 12,000.16 - 12000

Returns:

float

7.2 _parse_currency(raw)

Detects: - $ → USD - € → EUR - £ → GBP - keyword matches (dollars, euro, etc.)

Returns ISO currency code.


7.3 _parse_date_iso(raw)

Uses:

dateparser.search.search_dates()

Configuration: - PREFER_DATES_FROM = "past" - RELATIVE_BASE = datetime.now() - RETURN_AS_TIMEZONE_AWARE = False

Returns:

YYYY-MM-DD

Fallback: - If no date detected → today


7.4 _parse_expense(text)

Combines: - amount - currency - date - description

Returns structured dictionary:

{
    "amount": float,
    "currency": str,
    "date_iso": str,
    "description": str
}

8. Excel Storage Layer

Excel file created if missing:

expenses.xlsx

Header structure:

["Date", "Description", "Amount", "Currency", "Raw Text", "Logged At"]

Append logic ensures: - Workbook exists - Correct sheet name - ISO timestamp logging

Read logic: - Dynamically maps header row - Avoids tuple index errors - Skips blank rows


9. Running the Server

Direct execution

.\.venv\Scripts\python.exe server.py

The process should remain running (stdio server).


10. Testing with MCP Inspector

Launch:

npx @modelcontextprotocol/inspector python server.py

Steps: 1. Open browser UI 2. View tools 3. Call log_expense 4. Call list_expenses


11. Integrating with Codex in VS Code

Open Codex MCP UI

"Connect to a custom MCP"

Select: - STDIO

Configuration

Command to launch:

C:\Users\andre\Documents\Python\MCP\Python\Stdio Server\.venv\Scripts\python.exe

Arguments:

C:\Users\andre\Documents\Python\MCP\Python\Stdio Server\server.py

No environment variables required.

After saving: - Enable the MCP tool - Use in Codex chat:

Example:

Log this expense: I spent 50 dollars on groceries yesterday

12. Operational Considerations

  • Do not print to stdout
  • Use stderr for debugging
  • Always use absolute python path
  • Ensure virtual environment consistency
  • Keep Excel closed during writes
  • Consider file locking for production use

13. Future Improvements

  • Category auto-detection
  • Deduplication logic
  • CSV export
  • SQLite backend
  • Multi-user storage
  • Authentication layer
  • Cloud deployment (HTTP MCP)
  • Structured validation with Pydantic

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选