Skill: GridTRX Accounting
Demo
Watch the demo: Full accounting cycle in 15 minutes
What it does
Use this skill when the user asks you to "do the books," "categorize expenses," "import bank transactions," "run a balance sheet," or any bookkeeping task. GridTRX is a full-cycle double-entry accounting engine. You prompt in plain English, and the agent completes the books correctly. Every transaction balances. Every amount is deterministic. All data is local — no cloud services, no external APIs.
GridTRX produces a full set of auditable books: balance sheet, income statement, general ledger, trial balance, adjusting journal entries, retained earnings rollforward. Reports are exportable to CSV and PDF for any time period.
Architecture
GridTRX has three interfaces to the same engine (models.py → books.db):
- 1. MCP Server (preferred for agents) — Structured JSON tools. 20 tools (12 read, 8 write) wrapping
models.py directly. No text parsing, typed parameters, deterministic output. - CLI (fallback for agents, power users) — One-shot shell commands via
python cli.py. Zero dependencies beyond Python 3.7+ standard library. Any terminal-based agent can drive it via subprocess. - Browser UI (for humans) — Flask web interface at
localhost:5000 via python run.py. Ledger browsing, report viewer with drill-down, comparative reports up to 13 columns, bank import with rule preview, reconciliation marking, dark mode.
All three hit the same models.py data layer. Nothing is out of sync. Use MCP when available. Fall back to CLI otherwise. The browser UI is for human review.
Prerequisites
Install dependencies before first use (one-time setup):
CODEBLOCK0
Or install individually: pip install mcp (MCP server), pip install flask (browser UI). The CLI has no dependencies beyond the Python 3.7+ standard library.
No packages are installed at runtime. All dependencies must be pre-installed.
MCP Setup
Add to the agent's MCP config with GRIDTRX_WORKSPACE set to the user's client folder:
CODEBLOCK1
INLINECODE10 is mandatory — the MCP server will refuse to start without it. Any db_path outside the workspace is rejected at runtime. Every MCP tool takes db_path as its first parameter, which must resolve to a books.db file inside the workspace.
CLI Usage
CODEBLOCK2
Runs one command, prints plain text to stdout, exits. When GRIDTRX_WORKSPACE is set, the CLI enforces the same workspace boundary as the MCP server — paths outside the workspace are rejected.
Inputs needed
- - The absolute path to the client's books (
books.db file or its parent folder). - The absolute path to the bank file (
.csv, .ofx, or .qbo). - The bank account name to post against (typically
BANK.CHQ for chequing).
Core concepts
- - Double-entry: Every transaction is a balanced zero-sum entry. Debits = Credits. Always.
- Sign convention: Positive = Debit. Parentheses
(1,500.00) = Credit. — = Zero. - Amounts: Stored as integer cents internally. Displayed as dollars with two decimals.
- Account names: Case-insensitive, UPPER by convention. Common prefixes:
BANK. EX. REV. AR. AP. GST. RE. SHL. — When importing a trial balance or creating accounts, ALWAYS use GridTRX naming. Never use numeric account codes. If the source data has numeric codes (1010, 5800, etc.), ignore the codes and map by description to the nearest GridTRX account name. If no match exists, create the account using the EX. or REV. prefix convention. Always call list_accounts first before creating anything. - EX.SUSP (Suspense): Where unrecognized transactions land. This is the triage queue. Tell the AI what the suspense items are and it will clear them. Or clear them yourself through the GUI.
- Import rules: Keyword → account mappings. Case-insensitive match, highest priority wins. Optional tax code splits the amount into net + tax automatically.
- Lock date: Prevents changes to closed periods. Check before importing historical data.
- Architecture: Each client is one SQLite file. Copy it, back it up, email it. One data layer (
models.py) — CLI, MCP server, and browser UI all call the same functions.
Workflow
Step 1: Initialize (if no books exist)
MCP: No direct tool — use exec to run CLI.
CLI: python cli.py then INLINECODE35
This creates books.db with a full chart of accounts (~60 posting accounts), five reports (BS, IS, AJE, TRX, RE.OFS), 60+ import rules, and four tax codes. Always use starter books as the base — they include the critical perpetual retained earnings chain (IS → NI → RE.CLOSE → RE on BS, plus RE.OFS/RE.OPEN for year-end). Never build reports from scratch without this chain. The fiscal year ceiling (fy_end_date) is automatically set to the current fiscal year end.
After setup, run validate to confirm the report chain is intact:
CLI: INLINECODE39
Step 2: Import bank data
MCP (preferred):
- - CSV: INLINECODE40
- OFX/QBO: INLINECODE41
CLI fallback:
- - CSV: INLINECODE42
- OFX: INLINECODE43
The import applies all rules automatically. Check the result summary: posted, skipped, to_suspense.
CaseWare AJE import:
- - MCP: INLINECODE47
- CLI: INLINECODE48
- Supports QuickBooks IIF and Venice/MYOB text formats. Maps CsW account descriptions to Grid account codes.
Step 3: Audit suspense
MCP: get_ledger(db_path, "EX.SUSP")
CLI: INLINECODE50
Every entry here is an unrecognized transaction. Note the description and transaction ID for each.
Step 4: Resolve suspense with the user
Present each suspense item to the user. Ask: "What category is this?"
Do NOT guess. If the description is ambiguous (e.g., "AMAZON", "BEST BUY", "TRANSFER"), ask the user for business context before categorizing.
Once the user answers, add a rule so future imports are automatic:
MCP: add_rule(db_path, "AMAZON", "EX.OFFICE", "G5", 0)
CLI: INLINECODE52
Tax code is optional. Common codes: G5 (GST 5%), H13 (HST 13%), H15 (HST 15%), E (exempt).
Step 5: Clear the bad suspense entries and re-import
Delete each suspense transaction, then re-import so the new rules apply:
MCP: delete_transaction(db_path, txn_id) for each, then import_csv(...) or import_ofx(...) again.
CLI: python cli.py /path/to/books.db delete <txn_id> for each, then re-run the import command.
Repeat Steps 3-5 until suspense is empty.
Step 6: Verify and report
MCP:
- -
trial_balance(db_path) — debits must equal credits - INLINECODE62 — Balance Sheet
- INLINECODE63 — Income Statement
CLI:
- - INLINECODE64
- INLINECODE65
- INLINECODE66
Step 7: Year-end rollforward
When the fiscal year is complete:
MCP: rollforward(db_path, "2025-12-31")
CLI: INLINECODE68
This reads RE.CLOSE from the IS, posts Dr RE.OFS / Cr RE.OPEN, sets the lock date, and advances the FY ceiling to the next year. Then repeat from Step 2 for the next fiscal year. Rows beyond the ceiling are automatically skipped during import.
Recovery: Undoing a bad import
If the user uploaded the wrong file or you imported against the wrong account:
- 1. Find the bad transactions:
search_transactions(db_path, "some description") or via CLI search <keyword>. - Delete them one by one:
delete_transaction(db_path, txn_id) or CLI delete <txn_id>. - Verify the trial balance still balances after cleanup.
- Re-import the correct file.
There is no bulk undo. Deletions are individual and respect the lock date — you cannot delete transactions in a locked period.
MCP tools reference (20 tools)
Read tools
| Tool | Purpose |
|---|
| INLINECODE73 | List/search chart of accounts |
| INLINECODE74 |
Single account balance |
|
get_ledger(db_path, account_name, date_from?, date_to?) | Account ledger with running balance |
|
trial_balance(db_path, as_of_date?) | Trial balance — all accounts, Dr/Cr columns |
|
generate_report(db_path, report_name, date_from?, date_to?) | Run a report (BS, IS, AJE, etc.) |
|
get_transaction(db_path, txn_id) | Single transaction with all journal lines |
|
search_transactions(db_path, query, limit?) | Search by description/reference |
|
list_reports(db_path) | List available reports |
|
list_rules(db_path) | List import rules |
|
get_info(db_path) | Company name, fiscal year, lock date |
Write tools
| Tool | Purpose |
|---|
| INLINECODE83 | Post a simple 2-line entry |
| INLINECODE84 |
Delete a transaction (respects lock date) |
|
add_account(db_path, name, normal_balance, description?) | Add a posting account |
|
add_rule(db_path, keyword, account_name, tax_code?, priority?) | Add an import rule |
|
delete_rule(db_path, rule_id) | Delete an import rule |
|
import_csv(db_path, csv_path, bank_account) | Import bank CSV |
|
import_ofx(db_path, ofx_path, bank_account) | Import bank OFX/QBO |
|
import_aje(db_path, file_path, ref_prefix) | Import CaseWare AJE export (IIF or Venice) |
|
rollforward(db_path, ye_date) | Year-end rollforward (posts RE closing, sets lock, advances ceiling) |
|
year_end(db_path, ye_date) | Alias for rollforward |
|
set_lock_date(db_path, lock_date?) | Show or set the lock date |
|
set_ceiling(db_path, date?) | Show or set the fiscal year ceiling |
|
bulk_report_layout(db_path, report_name, items, after_account?, mode?) | Batch-place items on a report (accounts, totals, labels, separators) |
Guardrails
- - NEVER GUESS CATEGORIES. If a transaction description is ambiguous, let it go to
EX.SUSP and ask the user. Do not assume "AMAZON" is office supplies — it could be inventory, personal, or cost of sales. - NEVER MODIFY books.db DIRECTLY. All writes go through
cli.py commands or MCP tools. Never use file tools to read or write the SQLite database. - STAY IN THE WORKSPACE. Only operate on
books.db files within the user's GridTRX workspace. Both the MCP server and CLI enforce this when GRIDTRX_WORKSPACE is set — the MCP server will not start without it, and both interfaces reject any path outside the workspace. - NO OUTBOUND NETWORK REQUESTS. GridTRX processes data locally. It does not phone home, call APIs, or transmit data. Do not attempt to "verify" transactions against external services.
- RESPECT THE POSTING WINDOW. Before importing, check the lock date and FY ceiling with
get_info(). You cannot post on or before the lock date, or after the FY ceiling. Run rollforward to advance to the next fiscal year. - PRESERVE RAW OUTPUT. When presenting financial data to the user, use the exact numbers from GridTRX. Do not round, reformat, or flip signs. Positive = Debit. Parentheses = Credit.
- TRIAL BALANCE MUST BALANCE. After any operation, if the trial balance shows unequal debits and credits, something is wrong. Stop and investigate before proceeding.
- LIMIT EXEC SCOPE. When using exec, only run
python cli.py commands against books within the workspace. Do not run arbitrary shell commands, install packages, start background processes, or execute scripts other than cli.py. The MCP server is the preferred interface — use CLI only when MCP is unavailable.
技能:GridTRX 会计
演示
观看演示:15分钟完成完整会计周期
功能说明
当用户要求你做账、分类费用、导入银行交易、生成资产负债表或任何簿记任务时,使用此技能。GridTRX是一个全周期复式记账引擎。你用简单的英语提示,智能体就能正确完成记账。每笔交易都平衡。每个金额都是确定的。所有数据都在本地——无需云服务,无需外部API。
GridTRX生成一套完整的可审计账簿:资产负债表、利润表、总分类账、试算平衡表、调整分录、留存收益滚动汇总。报表可导出为CSV和PDF格式,支持任意时间段。
架构
GridTRX为同一引擎(models.py → books.db)提供三个接口:
- 1. MCP服务器(智能体首选) — 结构化JSON工具。20个工具(12个读取,8个写入)直接封装models.py。无需文本解析,使用类型化参数,输出确定性。
- CLI(智能体备用方案,高级用户使用) — 通过python cli.py执行一次性Shell命令。除Python 3.7+标准库外无任何依赖。任何基于终端的智能体均可通过子进程驱动。
- 浏览器UI(供人类使用) — 通过python run.py在localhost:5000启动Flask Web界面。分类账浏览、带下钻功能的报表查看器、最多13列的对比报表、带规则预览的银行导入、对账标记、深色模式。
三者均使用同一models.py数据层。数据完全同步。优先使用MCP,否则回退到CLI。浏览器UI供人工审查使用。
前提条件
首次使用前安装依赖项(一次性设置):
bash
pip install -r requirements.txt
或单独安装:pip install mcp(MCP服务器),pip install flask(浏览器UI)。CLI除Python 3.7+标准库外无任何依赖。
运行时不会安装任何包。 所有依赖项必须预先安装。
MCP设置
在智能体的MCP配置中添加,并将GRIDTRX_WORKSPACE设置为用户的客户文件夹:
json
{
command: python,
args: [/path/to/mcp_server.py],
env: {GRIDTRX_WORKSPACE: /path/to/clients}
}
GRIDTRXWORKSPACE是必填项——MCP服务器在未设置时将拒绝启动。任何工作区之外的dbpath在运行时都会被拒绝。每个MCP工具都将db_path作为第一个参数,该参数必须解析为工作区内的books.db文件。
CLI使用
GRIDTRX_WORKSPACE=/path/to/clients python cli.py /path/to/clients/acme/books.db
执行一个命令,将纯文本输出到stdout,然后退出。当设置了GRIDTRX_WORKSPACE时,CLI强制执行与MCP服务器相同的工作区边界——工作区之外的路径将被拒绝。
所需输入
- - 客户账簿的绝对路径(books.db文件或其父文件夹)。
- 银行文件的绝对路径(.csv、.ofx或.qbo)。
- 要过账的银行账户名称(通常支票账户为BANK.CHQ)。
核心概念
- - 复式记账: 每笔交易都是一个平衡的零和分录。借方=贷方。始终如此。
- 符号约定: 正数=借方。括号(1,500.00)=贷方。—=零。
- 金额: 内部以整数分存储。显示为带两位小数的美元金额。
- 账户名称: 不区分大小写,按惯例使用大写。常见前缀:BANK. EX. REV. AR. AP. GST. RE. SHL. — 导入试算平衡表或创建账户时,始终使用GridTRX命名。切勿使用数字账户代码。如果源数据有数字代码(1010、5800等),忽略代码并根据描述映射到最接近的GridTRX账户名称。如果找不到匹配项,使用EX.或REV.前缀约定创建账户。在创建任何内容之前,始终先调用list_accounts。
- EX.SUSP(暂记账户): 未识别交易的存放位置。这是分类队列。告诉AI暂记项目是什么,它将清除这些项目。或者通过GUI自行清除。
- 导入规则: 关键字→账户映射。不区分大小写匹配,优先级最高者获胜。可选的税码自动将金额拆分为净额+税额。
- 锁定日期: 防止对已关闭期间进行更改。在导入历史数据前检查。
- 架构: 每个客户一个SQLite文件。复制、备份、通过电子邮件发送。一个数据层(models.py)——CLI、MCP服务器和浏览器UI都调用相同的函数。
工作流程
第1步:初始化(如果没有现有账簿)
MCP: 没有直接工具——使用exec运行CLI。
CLI: python cli.py 然后 new /path/to/folder Company Name
这将创建包含完整会计科目表(约60个过账账户)、五个报表(BS、IS、AJE、TRX、RE.OFS)、60多条导入规则和四个税码的books.db。始终使用启动账簿作为基础——它们包含关键的自续留存收益链(IS → NI → RE.CLOSE → BS上的RE,加上用于年末的RE.OFS/RE.OPEN)。没有此链切勿从头构建报表。财政年度上限(fyenddate)自动设置为当前财政年度末。
设置后,运行validate确认报表链完整:
CLI: python cli.py /path/to/books.db validate
第2步:导入银行数据
MCP(首选):
- - CSV:importcsv(dbpath, csvpath, BANK.CHQ)
- OFX/QBO:importofx(dbpath, ofxpath, BANK.CHQ)
CLI备用方案:
- - CSV:python cli.py /path/to/books.db importcsv /path/to/file.csv BANK.CHQ
- OFX:python cli.py /path/to/books.db importofx /path/to/file.qbo BANK.CHQ
导入会自动应用所有规则。检查结果摘要:posted(已过账)、skipped(已跳过)、to_suspense(进入暂记账户)。
CaseWare AJE导入:
- - MCP:importaje(dbpath, filepath, 25AJE)
- CLI:python cli.py /path/to/books.db importaje /path/to/ajeexport.iif 25AJE
- 支持QuickBooks IIF和Venice/MYOB文本格式。将CsW账户描述映射到Grid账户代码。
第3步:审计暂记账户
MCP: getledger(dbpath, EX.SUSP)
CLI: python cli.py /path/to/books.db ledger EX.SUSP
这里的每笔分录都是未识别的交易。记录每笔交易的描述和交易ID。
第4步:与用户一起解决暂记账户问题
向用户展示每个暂记项目。询问:这是什么类别?
不要猜测。如果描述不明确(例如AMAZON、BEST BUY、TRANSFER),在分类前向用户询问业务背景。
用户回答后,添加规则以便未来导入自动处理:
MCP: addrule(dbpath, AMAZON, EX.OFFICE, G5, 0)
CLI: python cli.py /path/to/books.db addrule AMAZON EX.OFFICE G5 0
税码可选。常见代码:G5(GST 5%)、H13(HST 13%)、H15(HST 15%)、E(免税)。
第5步:清除错误的暂记分录并重新导入
删除每个暂记交易,然后重新导入以便应用新规则:
MCP: 对每个交易执行deletetransaction(dbpath, txnid),然后再次执行importcsv(...)或import_ofx(...)。
CLI: 对每个交易执行python cli.py /path/to/books.db delete ,然后重新运行导入命令。
重复第3-5步,直到暂记账户为空。
第6步:验证和报告
MCP:
- - trialbalance(dbpath) — 借方必须等于贷方
- generatereport(dbpath, BS