ledger-mcp

ledger-mcp

Enables AI agents to create accounts, record balanced double-entry transactions, query balances, and reconcile accounts against a SQLite-backed ledger through four MCP tools.

Category
访问服务器

README

ledger-mcp

I built this over two days to figure out where an MCP server's correctness actually lives — in the tool implementation, or in the schemas the model sees.

The domain is a double-entry ledger, because it has a hard definition of "wrong": debits have to equal credits, or the books don't reconcile. So there's no room to hand-wave that the agent did "something reasonable." Either the reconcile call comes back balanced or it doesn't.

What's in the repo

ledger.py is a small SQLite-backed double-entry ledger. Amounts are integer cents so nothing rounds. test_ledger.py covers it with 7 pytest cases.

server.py wraps the ledger as an MCP server with four tools: create_account, record_transaction, get_balance, reconcile.

Day 1 ended there — server running, the four tools discoverable from Claude Desktop, the sample scenario (record a $250 sale, an $80 supplies purchase on account, pay it off) ran end-to-end.

Day 2 is the eval work.

  • evals/cases.py — 10 test cases split across three buckets: five that should just work, three that probe specific design leaks I noticed in Day 1 (dollar-vs-cent ambiguity, no discovery tool for existing accounts, silent account creation on ambiguous prompts), and two restraint cases where the agent shouldn't touch the ledger at all (accounting theory question, advice question).
  • evals/harness.py — runs each case through Claude via the Anthropic Messages API with the real MCP server spawned as a subprocess. Each case gets its own SQLite file (server.py reads LEDGER_DB_PATH from the env), so cases are fully isolated. Every tool call is captured, transcripts land in evals/transcripts/.
  • evals/inspect_request.py — dry-runs a case and prints the exact request body the harness would POST. No API key, no cost. This turned out to be the most useful thing in the repo.

What the schema audit found

Before running anything against the API I used inspect_request to look at the tool payload the model would actually receive. The docstrings and the JSON schema were telling different stories.

record_transaction.entries at baseline-v1:

"entries": {
  "items": { "additionalProperties": true, "type": "object" },
  "type": "array"
}

The docstring said each entry needs account, amount_cents, and side. The schema said "array of arbitrary objects." Same pattern on side (no debit/credit enum), on account_type (no enum for the five valid values), and on amount_cents — no type constraint anywhere inside entries.items, so nothing prevents the model from passing 42.50 and getting silently truncated to 42 at the SQLite integer column.

Everything I cared about lived in prose.

Full baseline payload: evals/baseline_schemas/tools_payload_baseline.txt.

What I changed

Four edits to server.py, in expected-impact order:

  1. Introduced a LedgerEntry pydantic model with account: str, amount_cents: int (gt=0), side: Literal["debit","credit"]. entries.items now $refs a proper nested type in the schema.
  2. Literal["asset","liability","equity","revenue","expense"] on account_type. Now visible in the schema as an enum.
  3. Rewrote get_balance's docstring to explain the sign convention — positive means "normal balance" for assets and expenses, the reverse for liabilities/equity/revenue. Signal change, not a schema change, but it's semantic detail types can't carry.
  4. Added a concrete example call inside record_transaction's docstring.

Fixed payload: evals/baseline_schemas/tools_payload_fixed.txt. The two files are meant to be diffed.

7/7 unit tests still pass.

What I did not do

The harness is real. Running it against claude-sonnet-4-5-20250929 takes ~3 minutes and would cost a few cents. I did not run it against both tags for one honest reason: I hit my Anthropic API credit limit before I could. So this README doesn't quote a pass/fail delta — the schema diff is the evidence here. Anyone with a key can reproduce the behavioral run in one command.

Two things I deliberately left out of the M10 fix pass, even though NOTES.md argues for them:

  • A list_accounts discovery tool. Right now the model has no way to check what accounts exist before referencing them.
  • Structured error objects instead of raw ValueError strings.

Both are real design improvements, not schema tightening. I kept the fix pass to one thing so the before/after diff would be readable.

Running it

uv sync
uv run pytest -q                                       # unit tests
uv run python -m evals._smoketest                      # verify MCP plumbing, no API
uv run python -m evals.inspect_request simple_sale     # inspect the wire payload

Full agent eval:

export ANTHROPIC_API_KEY="sk-ant-..."
export EVAL_MODEL="claude-sonnet-4-5-20250929"
uv run python -m evals.harness

Per-case transcripts go to evals/transcripts/, and _summary.json collects the pass/fail table.

Tags

  • baseline-v1 — Day 1 tools as originally shipped, schemas untouched.
  • fixes-v1 — after the M10 schema tightening.

git diff baseline-v1 fixes-v1 -- server.py is the source-level change. The two files in evals/baseline_schemas/ are the wire-level change.

NOTES.md

The raw build log lives in NOTES.md. It reads rough on purpose — it's the actual notes I wrote while building, not a cleaned-up narrative. If anything in this README seems too tidy, that file has the friction.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选