午餐钱红宝石
MCP服务器和CLI 午餐费 个人理财API。
- 命令行界面 --用于管理交易、类别、帐户等的人性化Thor命令
- MCP服务器 --展示与相同的操作 模型上下文协议 与AI助手一起使用的工具
两个接口共享一个共同的后端,因此每个操作都可以在两种模式下使用。
需求
- 红宝石>=3.4
- A. 午餐钱API代币
安装
git clone https://github.com/ajaya/lunchmoney-ruby.git
cd lunchmoney-ruby安装Ruby
安装Ruby 3.4.8 房车:
brew install rv
rv install 3.4.8
ruby -v # verify
bundle install配置
cp .env .env.local
# Edit .env.local and set LUNCHMONEY_API_TOKEN或者通过CLI进行身份验证:
bundle exec ruby bin/lunchmoney login 环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
LUNCHMONEY_API_TOKEN | - | API访问令牌(必需) |
LUNCHMONEY_CACHE_DB_PATH | ~/.config/lunchmoney/cache.sqlite3 | SQLite缓存位置 |
LUNCHMONEY_LOG_LEVEL 关 debug, info, warn, error, fatal | ||
LUNCHMONEY_LOG_OUTPUT | stderr | stderr, stdout,或绝对文件路径 |
CLI使用情况
为方便起见设置别名:
alias lunchmoney='rv run --ruby 3.4.8 ruby /path/to/lunchmoney-ruby/bin/lunchmoney'# Help
lunchmoney help # list all commands
lunchmoney tree # show full command tree
lunchmoney transactions help list # show all parameters for a subcommand
# Examples
lunchmoney transactions list # last 30 days of transactions
lunchmoney transactions show 123 # single transaction
lunchmoney categories list
lunchmoney plaid_accounts list
lunchmoney user me
# JSON output (useful for scripting / AI agents)
lunchmoney transactions list --json
# Resolve foreign key IDs to full objects (requires --json)
lunchmoney transactions list --json --resolve没有 --resolve,事务包含裸ID,如 "category_id": 42.与 --resolve,这些扩展为完整对象("category": { "id": 42, "name": "Groceries", ... }).
命令
| 命令 | 描述 |
|---|---|
help [COMMAND] | 描述可用命令 |
tree | 打印所有可用命令的树 |
login TOKEN | 节省您的午餐钱API代币 |
logout | 删除已保存的API令牌 |
| 交易 | |
transactions list | 列出交易记录 |
transactions show ID | 显示单个交易 |
transactions create | 从JSON创建事务(stdin或 --data) |
transactions update ID | 更新交易 |
transactions update_bulk | 从JSON批量更新事务(stdin或 --data) |
transactions delete ID | 删除交易 |
transactions delete_bulk ID1 ID2 ... | 删除多个交易记录 |
transactions split ID | 拆分交易(stdin或 --data) |
transactions unsplit ID | 取消交易拆分 |
transactions group | 组交易(stdin或 --data) |
transactions ungroup ID | 取消交易组分组 |
| 分类 | |
categories list | 列出类别 |
categories show ID | 显示单个类别 |
categories create --name=NAME | 创建类别 |
categories update ID | 更新类别 |
categories delete ID | 删除类别 |
| 格子帐 | |
plaid_accounts list | 列出所有与Plaid关联的帐户 |
plaid_accounts show ID | 显示单个Plaid帐户 |
plaid_accounts fetch | 触发Plaid数据同步 |
| 手工账目 | |
manual_accounts list | 列出所有手动管理的帐户 |
manual_accounts show ID | 显示单个手动帐户 |
manual_accounts create | 创建新的手动帐户 |
manual_accounts update ID | 更新手动帐户 |
manual_accounts delete ID | 删除手动帐户 |
| 循环项 | |
recurring_items list | 列出所有重复项目 |
recurring_items show ID | 显示单个重复项目 |
| 标签 | |
tags list | 列出所有标签 |
tags show ID | 显示单个标签 |
tags create --name=NAME | 创建新标签 |
tags update ID | 更新标签 |
tags delete ID | 删除标签 |
| 总结 | |
summary budget | 获取日期范围的预算摘要 |
| 用户 | |
user me | 显示当前经过身份验证的用户 |
| 服务器 | |
server start | 启动MCP服务器(通过stdio的JSON-RPC) |
server config | 打印Claude的MCP配置片段 |
MCP服务器
通过stdio启动服务器:
bundle exec ruby bin/lunchmoney server
# Or with rv:
rv run --ruby 3.4.8 ruby bin/lunchmoney server克劳德代码/克劳德桌面
生成一个带有解析路径和当前令牌的可粘贴配置片段:
bundle exec ruby bin/lunchmoney server config --claude
# Or with rv:
rv run --ruby 3.4.8 ruby bin/lunchmoney server config --claude这将输出Claude Code、Claude Desktop和Docker的JSON块。将相关片段复制到:
- 克劳德代码 —
.mcp.json在项目根目录中,或~/.claude/settings.json全球访问 - 克劳德桌面 —
claude_desktop_config.json
如果您更喜欢手动配置,这里有一个最小的示例:
{
"mcpServers": {
"lunchmoney": {
"command": "/opt/homebrew/bin/rv",
"args": [
"run",
"--ruby",
"3.4.8",
"ruby",
"/path/to/lunchmoney-ruby/bin/lunchmoney",
"server"
],
"cwd": "/path/to/lunchmoney-ruby",
"env": {
"LUNCHMONEY_API_TOKEN": "your_token_here"
}
}
}
}调整 command 和 args 对于你的Ruby版本管理器。这 server config --claude 命令检测您的本地设置并生成正确的路径。
发展
bundle exec rake test # Run all tests
bundle exec ruby -Ilib -Itest test/tools/transactions_test.rb # Single test file建筑
CLI (Thor) ─┐
├──▶ Api::* (shared backend) ──▶ lunchmoney-sdk-ruby ──▶ Lunch Money API
MCP server ─┘中的共享后端 lib/lunchmoney_app/api/ 包含所有业务逻辑。MCP工具处理程序(lib/lunchmoney_app/tools/)和CLI命令(lib/lunchmoney_app/cli/)是委托给他人的薄包装 Api::* 班级。
许可证
麻省理工学院
