费用追踪MCP服务

一个通过自然语言与Claude交互的远程MCP服务器,用于管理和追踪个人支出,数据存储在本地SQLite数据库中。

  • by Rohan171819
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 Rohan171819/Expense_Tracker-MCP-Server

使用说明

💸 费用跟踪器——远程MCP服务器

一个生产就绪的MCP服务器,让Claude通过自然语言管理您的费用

"Add ₹500 午餐费用”→克劳德打电话给你的MCP→ SQLite已更新。不需要UI。


📌 它的作用

费用跟踪MCP服务器 是一个 远程MCP(模型上下文协议)服务器 它将费用管理工具直接暴露给Claude,让您使用简单的英语对话记录、查询和总结您的费用,所有数据都保存在本地SQLite数据库中。

没有前端。没有表格。没有仪表板。跟克劳德谈谈。

🎯 你能做什么(通过克劳德)

自然语言 幕后发生了什么
"Add ₹450 for groceries today" add_expense(amount=450, category="groceries", date=today)
"How much did I spend this week?" get_expenses(date_range="this_week") → 求和并返回
"Show all food expenses in April" get_expenses(category="food", month="April")
"Delete that duplicate taxi entry" delete_expense(id=42)
"What's my biggest spending category?" summarize_expenses() → 按类别分组
"Give me a monthly breakdown" monthly_summary() → 每月总计

🏛️ 建筑

MCP的工作原理——全流程

  YOU (talking to Claude)
        │
        │  "Add ₹500 lunch expense for today"
        │
        ▼
  ┌─────────────────────────────────────────────────┐
  │               CLAUDE (AI Client)                │
  │                                                 │
  │  Understands intent → selects the right tool    │
  │  → formats arguments → calls MCP server         │
  └─────────────────────┬───────────────────────────┘
                        │
                        │  HTTP/SSE  (Remote MCP Protocol)
                        │
                        ▼
  ┌─────────────────────────────────────────────────┐
  │         EXPENSE TRACKER MCP SERVER              │
  │              (main.py — FastMCP)                │
  │                                                 │
  │  Registered Tools:                              │
  │  ┌──────────────────────────────────────────┐   │
  │  │  @mcp.tool()  add_expense()              │   │
  │  │  @mcp.tool()  get_expenses()             │   │
  │  │  @mcp.tool()  delete_expense()           │   │
  │  │  @mcp.tool()  summarize_expenses()       │   │
  │  │  @mcp.tool()  monthly_summary()          │   │
  │  └──────────────────────────────────────────┘   │
  │                                                 │
  │  Tool execution → SQL query built & run         │
  └─────────────────────┬───────────────────────────┘
                        │
                        │  SQL (read / write)
                        │
                        ▼
  ┌─────────────────────────────────────────────────┐
  │              expenses.db (SQLite)               │
  │                                                 │
  │  Table: expenses                                │
  │  ┌────┬────────┬──────────┬────────┬──────────┐ │
  │  │ id │ amount │ category │  date  │  notes   │ │
  │  ├────┼────────┼──────────┼────────┼──────────┤ │
  │  │  1 │  450   │ groceries│2025-04 │ Big Bazar│ │
  │  │  2 │  150   │ food     │2025-04 │ lunch    │ │
  │  └────┴────────┴──────────┴────────┴──────────┘ │
  └─────────────────────────────────────────────────┘
                        │
                        │  JSON result
                        │
                        ▼
  ┌─────────────────────────────────────────────────┐
  │               CLAUDE (AI Client)                │
  │  Formats result into a human-friendly response  │
  └─────────────────────────────────────────────────┘
                        │
                        ▼
  YOU get: "Added ₹500 lunch expense for today ✅
            Your total food spend this month: ₹2,340"

MCP工具注册模式

# How tools are exposed to Claude — clean decorator pattern
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Expense Tracker")

@mcp.tool()
def add_expense(amount: float, category: str, date: str, notes: str = "") -> str:
    """Add a new expense entry to the database."""
    # → inserts into SQLite → returns confirmation string

@mcp.tool()
def get_expenses(category: str = None, date_range: str = None) -> list[dict]:
    """Retrieve expenses with optional filters."""
    # → queries SQLite → returns list of expense dicts

@mcp.tool()
def summarize_expenses() -> dict:
    """Get total spending grouped by category."""
    # → GROUP BY query → returns category totals

🖥️ 演示

将其替换为真实的屏幕录制。 以下是如何记录它:

📹  Best demo flow (2 min recording):

  1. Start the MCP server  →  python main.py
  2. Open Claude.ai        →  Settings → MCP Servers → Add yours
  3. In Claude chat, type:
       "Add ₹800 dinner expense for yesterday"
       "Add ₹1200 groceries today"
       "What's my total spend this week?"
       "Break it down by category"
  4. Screenshot Claude's response showing the expense summary

  Tools:  scrcpy (Android screen mirror) + OBS for recording
          OR just screenshot Claude's response panel

预期克劳德响应预览:

┌──────────────────────────────────────────────────────┐
│  You: "Show me my spending breakdown this month"     │
│                                                      │
│  Claude:  Here's your expense breakdown for April:   │
│                                                      │
│  📊 Category Summary                                 │
│  ─────────────────────────────                       │
│  🍔 Food & Dining      ₹3,240   (34%)               │
│  🛒 Groceries          ₹2,800   (29%)               │
│  🚕 Transport          ₹1,450   (15%)               │
│  💊 Health             ₹900     (9%)                │
│  📦 Other              ₹1,210   (13%)               │
│  ─────────────────────────────                       │
│  💰 Total              ₹9,600                       │
│                                                      │
│  Your biggest category is Food & Dining. Want me     │
│  to set a budget limit for next month?               │
└──────────────────────────────────────────────────────┘

🛠️ 技术栈

技术 角色
Python 3.12+ 核心服务器语言
MCP(模型上下文协议) Anthropic的人工智能开放标准↔ 工具通信
FastMCP 高级MCP服务器框架(基于装饰器的工具注册)
SQLite (expenses.db) 轻量级、零配置的持久存储
紫外线 超快速Python包管理器(取代pip+venv)
克劳德 发现并调用MCP工具的AI客户端

⚡ 如何跑步

先决条件

  • Python 3.12+
  • uv 已安装→ pip install uv 或 curl -LsSf https://astral.sh/uv/install.sh | sh
  • Claude.ai Pro/Team帐户(用于远程MCP支持) 或 克劳德桌面(用于本地MCP)

1.克隆和安装

git clone https://github.com/Rohan171819/Expense-Tracker-Remote-MCP-Server.git
cd Expense-Tracker-Remote-MCP-Server

# Install dependencies with uv (fast)
uv sync

# OR with pip
pip install -r requirements.txt

2.运行MCP服务器

# With uv
uv run main.py

# OR directly
python main.py

服务器启动于 http://localhost:8000 (或配置的端口)。

3.连接到克劳德桌面(本地)

将此添加到您的Claude Desktop配置文件中:

雨衣: ~/Library/Application Support/Claude/claude_desktop_config.json
窗户: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "expense-tracker": {
      "command": "uv",
      "args": ["run", "main.py"],
      "cwd": "/absolute/path/to/Expense-Tracker-Remote-MCP-Server"
    }
  }
}

重新启动克劳德桌面→ 你会看到一个🔧 聊天中的工具图标。

4.连接到Claude.ai(远程-Web)

如果远程部署:

  1. 首选 claude.ai → 设置→ 集成
  2. 添加MCP服务器URL: https://your-deployed-url/mcp
  3. Claude将自动发现所有已注册的工具

5.测试它

连接后,打开Claude并尝试:

"Add ₹500 expense for lunch today"
"Show all my expenses this week"
"What's my total spending by category?"
"Delete expense number 3"

📂 项目结构

Expense-Tracker-Remote-MCP-Server/
│
├── main.py           # MCP server — all tools defined here
├── expenses.db       # SQLite database (auto-created on first run)
├── pyproject.toml    # Project metadata + dependencies (uv)
├── uv.lock           # Locked dependency versions
├── .python-version   # Python version pin (3.12)
├── .gitignore
└── README.md

🔧 可用的MCP工具

工具 参数 返回
add_expense amount, category, date, notes? 确认字符串
get_expenses category?, date_range?, limit? 费用对象列表
delete_expense id 确认字符串
summarize_expenses -- 类别划分→ 合计
monthly_summary year? 月份骰子→ 合计

🗺️ 路线图

  • [x] 带FastMCP的远程MCP服务器
  • [x] SQLite持久性
  • [x] 添加/获取/删除/汇总工具
  • [x] 基于uv的依赖性管理
  • []预算警报(set_budget, check_budget)
  • []导出到CSV工具
  • []多币种支持
  • []部署到铁路/渲染(公共MCP端点)
  • []N8N webhook集成,用于自动记录

👤 作者

罗汉·夏尔马 --AI/ML工程师·LangGraph+MCP开发人员
MCA@GL巴贾杰技术与管理学院


⭐ 如果你想让人工智能来管理你的钱,而不是电子表格,就把这个标出来