monarch-mcp
monarch-mcp
MCP 服务器,将 Claude(桌面版、Code 或任何 MCP 客户端)连接到 Monarch Money,用于个人财务分析和轻量级编辑。
封装了非官方的 monarchmoney Python 客户端。
功能
组 | 工具 |
交易 |
|
标签 |
|
分类 |
|
账户 |
|
净资产 |
|
现金流 |
|
预算/目标 |
|
上游 API 缺失功能
由于上游库未实现,以下功能未公开:
标签:不支持重命名、删除。
分类:不支持重命名(支持删除)。
目标:只读(随
get_budgets一起返回);不支持创建/更新/删除。
Related MCP server: monarch-mcp2
安装
需要 Python 3.10+ 以及 keyring 包可以调用的操作系统密钥环(macOS Keychain、Windows 凭据管理器、Linux 上通过 D-Bus 的 GNOME Keyring / KWallet)。
推荐:pipx
pipx 将包安装到其自己的 venv 中,并将 monarch-mcp / monarch-mcp-setup 入口点放入您的 $PATH:
pipx install .替代方案:在 venv 中使用 pip
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install .如果采用此路径,Claude Desktop 将需要 venv 中 monarch-mcp 二进制文件的绝对路径(见下文)。
Linux 注意事项
在无头 Linux 机器(或没有桌面会话的 WSL2)上,keyring 默认找不到后端。请执行以下任一操作:
安装
gnome-keyring并运行dbus-launch以便可以访问守护进程,或者安装
keyrings.alt(pip install keyrings.alt) 并接受密钥以明文形式存储在~/.local/share/python_keyring/下 —— 这对于个人开发机器没问题,但不适用于共享机器。
配置凭据
运行一次以将您的 Monarch 电子邮件、密码和(可选但推荐)MFA TOTP 密钥存储在操作系统密钥环中。这三者都位于服务名称 monarch-mcp 下。
monarch-mcp-setup set # interactive prompts (password + MFA are hidden input)
monarch-mcp-setup show # report which fields are stored (values not echoed)
monarch-mcp-setup clear # wipe all three fields不带子命令的 monarch-mcp-setup 默认为 set。
关于 MFA 密钥
当您在 Monarch 中启用 MFA 时,设置屏幕会显示一个二维码和一个 base32 字符串(通常标记为“密钥”或“手动输入代码”)。该 base32 字符串正是 monarch-mcp-setup 所要求的 —— 而不是 6 位数的代码。
存储它允许服务器自行计算 TOTP 代码,并在会话 pickle 过期后在无人值守的情况下重新进行身份验证。如果没有它,每次会话过期都会迫使您通过清除凭据并使用新代码再次运行 set 来手动重新登录。
如果您在首次注册时没有保存该密钥,可以在 Monarch 的设置中重新注册您的身份验证器以再次查看它。
会话状态存储位置
在首次成功登录后,服务器会缓存一个会话 pickle,以便后续进程启动时跳过登录往返:
默认:
~/.config/monarch-mcp/session.pickle覆盖:将
MONARCH_MCP_SESSION_DIR环境变量设置为您选择的目录
如果 pickle 被损坏或被 Monarch 拒绝,服务器会静默回退到使用存储的凭据进行全新登录 —— 您无需手动清除它。
连接到 Claude Desktop
编辑 claude_desktop_config.json:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
在 mcpServers 下添加一个条目:
{
"mcpServers": {
"monarch": {
"command": "monarch-mcp"
}
}
}如果 monarch-mcp 不在 Claude Desktop 可见的 $PATH 中(在使用 venv 而非 pipx 时很常见),请提供绝对路径:
{
"mcpServers": {
"monarch": {
"command": "/Users/you/code/monarch-mcp/.venv/bin/monarch-mcp"
}
}
}要将会话 pickle 存放在非默认位置:
{
"mcpServers": {
"monarch": {
"command": "monarch-mcp",
"env": { "MONARCH_MCP_SESSION_DIR": "/Users/you/.local/share/monarch-mcp" }
}
}
}重启 Claude Desktop。工具应出现在 MCP 选择器中。
连接到 Claude Code
claude mcp add monarch monarch-mcp关于工具界面的说明
所有日期参数均为 ISO
YYYY-MM-DD字符串。ID(分类、标签、账户)是不透明字符串 —— 在调用过滤后的端点之前,请通过相应的
list_*工具发现它们。set_budget需要category_id或category_group_id中的恰好一个。list_transactions支持分页:传递limit和offset以遍历大于默认 100 条的结果。
开发与测试
测试套件是封闭的 —— 当未安装这些包时,它会存根 keyring、monarchmoney 和 mcp.server.fastmcp,因此您可以在没有网络访问或密钥环后端的情况下运行它。
设置
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'-e .[dev] 安装可编辑的包以及 pytest 和 pytest-asyncio。
运行
pytest # full suite (~80ms, 43 tests)
pytest tests/test_server.py # one module
pytest -k "set_budget" # one keyword
pytest -v # verbose, lists each testPytest 配置位于 pyproject.toml 的 [tool.pytest.ini_options] 下:
pythonpath = ["src"]—— 允许from monarch_mcp import ...在没有可编辑安装的情况下解析(在不运行pip install的 CI 容器中很方便)。asyncio_mode = "auto"—— 异步测试函数不需要@pytest.mark.asyncio装饰器。testpaths = ["tests"]—— 直接运行pytest即可找到套件。
布局
src/monarch_mcp/
auth.py — keychain wrapper (get/set/delete + require_login_credentials)
setup.py — monarch-mcp-setup CLI (set / show / clear)
server.py — FastMCP server, lazy-login client, all tool definitions
tests/
conftest.py — third-party stubs + clean_keyring / fake_mm_client / server_with_fake_client fixtures
test_auth.py
test_setup.py
test_server.py编写新工具
将一个带有
@mcp.tool()装饰的异步函数添加到 src/monarch_mcp/server.py。文档字符串将成为 Claude 看到的 MCP 工具描述,因此请为 Claude 编写它。如果它调用了新的
MonarchMoney方法,请将方法名称添加到 tests/conftest.py 中的_FAKE_METHODS,以便fake_mm_client对其进行模拟。使用
server_with_fake_clientfixture 在 tests/test_server.py 中添加测试 —— 断言client.<method>.await_args.kwargs以确认调用形式。
Fixture 的作用
clean_keyring—— 在每次测试前清除内存中的密钥环存根(安装真实密钥环时为空操作)。fake_mm_client——MagicMock,其 Monarch 方法是返回{"called": <method_name>}的AsyncMock。server_with_fake_client—— 将server._clientmonkeypatch 为 fake,因此工具调用完全绕过_get_client()和登录流程。执行登录的测试(test_get_client_*)会将_client重置为None并直接修补server.MonarchMoney。
Available Tools
18 toolscreate_categoryC
Create a new category under the given group.
Inputs: group_id (required), name (required), icon, rollover_enabled. Returns: object
create_tagA
Create a new tag. Color is a hex string like '#ff0000'.
Inputs: name (required), color (required). Returns: object
delete_categoryB
Delete a category by ID.
Inputs: category_id (required). Returns: object
get_account_historyB
Historical balance snapshots for a single account.
Inputs: account_id (required). Returns: object
get_budgetsC
Budget plan vs. actuals for the date range. Includes v2 goals when present.
Inputs: start_date, end_date. Returns: object
get_cash_flowB
Cash flow aggregated by category, group, and merchant for the date range.
Inputs: limit, start_date, end_date. Returns: object
get_cash_flow_summaryA
Top-line cash flow numbers only (income, expense, savings).
Inputs: start_date, end_date. Returns: object
get_net_worth_by_typeC
Net worth broken down by account type. Timeframe: 'month' or 'year'.
Inputs: start_date (required), timeframe. Returns: object
get_net_worth_historyA
Daily net-worth snapshots aggregated across all accounts.
Optional account_type filters to a single type (e.g. 'brokerage'). Dates are ISO YYYY-MM-DD.
Inputs: start_date, end_date, account_type. Returns: object
get_transactionA
Return full detail for a single transaction (includes splits, tags, attachments).
Inputs: transaction_id (required). Returns: object
get_transactions_summaryB
Aggregate stats (count, sum, average, max) across all transactions.
Inputs: no named parameters. Returns: object
list_accountsA
List all configured accounts with current balances and metadata.
Inputs: no named parameters. Returns: object
list_categoriesA
List all transaction categories.
Inputs: no named parameters. Returns: object
list_category_groupsA
List all category groups (the parent groupings for categories).
Inputs: no named parameters. Returns: object
list_tagsA
List all transaction tags.
Inputs: no named parameters. Returns: object
list_transactionsA
List transactions with optional filters. Dates are ISO YYYY-MM-DD.
Use list_categories / list_tags / list_accounts to discover the IDs needed for the *_ids filter arguments.
Inputs: limit, offset, start_date, end_date, +9 more. Returns: object
set_budgetA
Set a budget amount. Provide exactly one of category_id or category_group_id.
timeframe: 'month' or 'year'. apply_to_future propagates the change forward.
Inputs: amount (required), category_id, category_group_id, timeframe, +2 more. Returns: object
set_transaction_tagsB
Replace the set of tags on a transaction with the given tag IDs.
Inputs: transaction_id (required), tag_ids (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 18 tools
Each tool targets a distinct financial entity or operation (e.g., categories, tags, budgets, transactions, cash flow, net worth). No two tools have overlapping functionality; even related tools like get_cash_flow and get_cash_flow_summary are clearly differentiated by detail level.
All tool names follow a consistent verb_noun pattern using snake_case (e.g., create_category, get_budgets, list_transactions). Verbs are uniformly chosen (create, delete, get, list, set) and nouns are plural or singular as appropriate.
18 tools cover the major areas of personal finance management (accounts, transactions, categories, tags, budgets, cash flow, net worth) without being overwhelming. The count is within the optimal 3-15 range, though slightly above, but still well-scoped for the domain.
The tool surface has significant gaps: no update or delete for transactions, no delete for tags, no update for categories or tags. While core reads and some writes exist, essential lifecycle operations (especially delete and update for transactions) are missing, limiting agent workflows.
Maintenance
Related MCP Connectors
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Personal finance for AI agents — onboard, import statements, categorize & budget over MCP.
Read-only finance MCP server. Connects your banks, cards, payment apps, books and payroll into one ledger for your AI. Can't move money. Open source (AGPL-3.0), free during beta.
Query your real net worth, spending, transactions, budgets and portfolio from any MCP client.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that integrates with Monarch Money to provide financial data access and operations, including account management, transaction filtering, budget analysis, and goal tracking through natural language.-
- AlicenseCqualityCmaintenanceUnofficial MCP server for Monarch Money that exposes tools for managing accounts, transactions, budgets, and other financial data through natural language.1251MIT
- FlicenseBqualityDmaintenanceA personal MCP server that gives Claude native access to YNAB budget data.461-
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that enables AI assistants to interact with your Monarch Money personal finance data. Manage accounts, transactions, budgets, and analyze your finances programmatically.MIT