
ofdkit
io.github.Edgar-311由 GitHub 帳號 Edgar-311 發布v0.4.0更新於 Oct 29, 2026
Read OFD files and Chinese e-invoices (数电票): text, invoice fields, folder totals. Read-only.
概覽
唯讀的 MCP 伺服器,讓助理擷取 OFD 文件的文字與中國電子發票欄位,並彙總資料夾中的發票。
- 可以做什麼
- 依閱讀順序擷取 OFD 檔案文字,可選 Markdown 輸出與頁碼範圍
- 讀取發票欄位,例如號碼、日期、買方、賣方、金額與明細
- 回傳頁數、頁面尺寸與文件中繼資料
- 彙總資料夾中的發票並提供合計,可選擇檢查買方名稱或統一編號
- 適用情境
- 適合需要讓助理讀取中國 OFD 版式文件(GB/T 33190)的情境,尤其是電子發票與公文,例如報帳核對、整理發票清單或擷取文字,不必手動逐一開啟檔案。
- 執行需求
- 透過 uvx 以 stdio 在本機執行,需先安裝 uv;安裝的是帶 mcp 附加元件的 ofdkit 套件。未宣告任何帳號、API 金鑰或環境變數。可用選用的 --root 資料夾限制可讀取的範圍。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 ofdkit,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
ofdkit
轻量的 Python 工具,用来读取 OFD 文件,提取里面的文字和发票字段,并能接入 AI 工具。OFD 是中国的国家标准版式文档格式(GB/T 33190),常见于电子发票和公文。
A lightweight Python toolkit for reading OFD documents (GB/T 33190, the Chinese fixed-layout format used for e-invoices and official documents): extract text and invoice fields, and use them from AI tools.
状态:0.4 版,接口以后可能还会调整。更新记录见 CHANGELOG。 Status: 0.4, the API may still change. See the CHANGELOG.
能做什么 / What it does
- 看发票:一条命令显示发票号码、日期、购买方、销售方、金额和明细。 Show an invoice: number, date, buyer, seller, amounts and line items, with one command.
- 把一个文件夹里的发票汇总到 Excel,也能直接读税务平台批量下载的 .zip 压缩包。发票号码保持原样(不会变成 2.4E+19),金额可以直接求和,重复的发票会标出来。 Summarise a folder of invoices, or a .zip archive downloaded from the tax service, into an Excel workbook: invoice numbers stay intact, amounts are numbers, duplicates are flagged.
- 报销帮手:检查发票抬头(购买方名称、税号)对不对;按发票内容给文件改名,可以预览、可以改回去。 For reimbursement: check that invoices are made out to the right buyer, and rename invoice files after their contents, with a preview and an undo.
- 按阅读顺序提取文字,包括模板和复合对象里的文字。 Text in reading order, including text in templates and composite objects.
- 给程序和 AI 用:发票字段输出 JSON,提供 MCP 服务器、Agent Skill 和 MarkItDown 插件。 For programs and AI: invoice fields as JSON, an MCP server, an Agent Skill and a MarkItDown plugin.
- 只用 Python 标准库,没有任何第三方依赖;能读很多不规范的文件(路径写法不对、编码不对、XML 前缀错误等)。 Standard library only, no dependencies; reads many non-conforming files (bad paths, encodings, XML prefixes).
快速上手 / Quick start
-
安装 Python 3.10 或更新版本。Windows 上安装时请勾选 "Add python.exe to PATH"。 Install Python 3.10 or newer.
-
打开命令行(Windows 在开始菜单搜索"终端"或"cmd",Mac 打开"终端"),安装 ofdkit: Open a terminal and install ofdkit:
-
看一张发票(把文件拖进命令行窗口就能填上路径): Show an invoice (drag the file into the terminal window to type its path):
(数据是虚构的 / fictional data)
-
看一个文件夹或 .zip 压缩包里的所有发票和合计,然后导出到 Excel: List every invoice in a folder or .zip archive with totals, then export to Excel:
Excel 文件有两张表:"发票"每张发票一行,最后是合计;"明细"每个商品或服务一行。重复的发票标黄,读不出来的文件标红,有其他提醒的发票(抬头不对、金额缺少或不是数字)标橙,都在"提醒"一栏写明原因。合计用的是 SUBTOTAL,筛选以后只算看得见的行;不是数字的金额保留原样、不算进合计,合计下面会注明有几张。 The workbook has two sheets: 发票 (one row per invoice, with totals; duplicates in yellow, unreadable files in red, other reminders such as another buyer or an amount that is missing or not a number in orange, each explained) and 明细 (one row per line item). Totals use SUBTOTAL, so they follow filters.
-
检查发票抬头:加上
--buyer,购买方名称或税号不是你公司的发票会标出来(Excel 里标橙色)。名称和税号都要查,就写两次: Check who the invoices are made out to: with--buyer, invoices for another buyer name or tax ID are flagged (orange in Excel). Repeat it to check both: -
按发票内容给文件改名,例如
dzfp_2411…_20240528.ofd改成2024-05-28_某某公司_4449.00_2411….ofd。不加--apply只是预览;同名的 PDF、XML 会一起改(其中一个改不了,这张发票的文件都保持原名);改名前会先写好改名记录,写不了就一个文件也不改;用--undo可以按记录改回去,运行几次都没关系: Rename invoice files after their contents. Without--applyit only previews; PDF and XML copies with the same name are renamed too (if one cannot be, that invoice's files all keep their names); the log is written before anything is renamed, and nothing is renamed if it cannot be;--undorestores the old names from the log and is safe to run again:名字的格式可以改,例如
--pattern "{开票日期}_{购买方}_{商品}"。可以用的字段:开票日期、发票号码、发票代码、发票种类、销售方、销售方税号、购买方、购买方税号、金额、税额、价税合计、商品、原文件名。 The name format can be changed with--pattern; fields are listed byofdkit rename --help(English names such as{date},{seller}and{total}work too).
命令行 / Command line
show、batch 和 rename 加 -r 会连子文件夹一起找。ofdkit 文件.ofd 是 ofdkit show 文件.ofd 的简写。
Add -r to show, batch and rename to include subfolders. ofdkit PATH is short for ofdkit show PATH.
ofdkit invoice 的输出示例(数据是虚构的)/ Example output (fictional data):
金额是字符串,不会丢失精度。如果"合计金额 + 合计税额"不等于"价税合计",或者某个金额不是数字(比如"无法识别",这时保留原样),warnings 里会提示。汇总时只加真正的数字:0 就是 0,缺少的和不是数字的不算进合计,并单独计数(not_summed)。
Amounts are decimal strings, so no precision is lost. warnings notes totals that do not add up and amounts that are not numbers (kept as found). Summaries add only real numbers: 0 counts as 0, while missing amounts and amounts that are not numbers are left out and counted in not_summed.
在 AI 工具里使用 / Use from AI tools
MCP 服务器 / MCP server
让 Claude、Codex、Cursor 等 AI 工具直接读取 OFD 文件。需要先安装 uv。所有工具都是只读的。 Lets Claude, Codex, Cursor and other AI tools read OFD files. Requires uv. All tools are read-only.
已在官方 MCP Registry 上架,名字是 io.github.Edgar-311/ofdkit;支持这个目录的工具可以直接搜索安装。
Listed in the official MCP Registry as io.github.Edgar-311/ofdkit; tools that read the registry can install it from there.
Claude Code:
Claude Desktop、Cursor 等使用 JSON 配置的工具 / tools with a JSON config:
Codex(~/.codex/config.toml):
加上 --root 文件夹 可以只允许读取这个文件夹里的文件。判断的是文件的真实位置:文件夹里指向外面的快捷方式式链接(符号链接、Windows 的目录联接)不会被读取,汇总文件夹时会跳过并计数(skipped_outside_root)。
Add --root FOLDER to allow only files inside that folder. The check uses each file's real location, so symbolic links and Windows directory junctions that lead outside are not read; folder listings skip and count them (skipped_outside_root).
Agent Skill
skills/ofd-reader 告诉 AI 什么时候、怎么用 ofdkit 命令行,适用于支持 Agent Skills 的工具。把这个文件夹复制到:
skills/ofd-reader tells an AI agent when and how to use the ofdkit command line. Copy the folder to:
- Claude Code:
~/.claude/skills/ofd-reader/ - Codex:
~/.codex/skills/ofd-reader/
MarkItDown 插件 / MarkItDown plugin
MarkItDown 是把各种文件转成 Markdown 给 AI 读的工具。安装插件后它就能读 OFD: MarkItDown converts files to Markdown for AI. With this plugin it reads OFD too:
Python
遇到读不出的文件 / Reporting a problem
请不要把真实发票发到网上。用这个命令导出文件结构,然后附在 GitHub issue 里。文字、文件名和较长的号码会打码(汉字变成"字",数字变成"0",字母变成 x),只保留结构、坐标和 OFD 格式自己的名字(如 Doc_0、Content.xml)。打码是尽力而为,发出去之前请自己再看一遍:
Please do not post real invoices. Export the structure and attach it to a GitHub issue. Text, file names and long numbers are masked; the structure, coordinates and the OFD format's own names (Doc_0, Content.xml) are kept. Masking is a best effort, so look through the file before posting it:
注意 / Notes
- ofdkit 只读取文件里写了什么,不验证发票真伪。查验真伪请使用国家税务总局的发票查验平台。 ofdkit reports what a file contains. It does not verify that an invoice is genuine.
- 文字如果是画成图形或图片的,就读不出来(需要 OCR,不在本项目范围内)。 Text drawn as shapes or images cannot be extracted (that needs OCR, which is out of scope).
- 阅读顺序是根据位置推测的。两栏的正文会按栏读,表格按行读;版面特别复杂的页面(比如多栏加图片的杂志页)可能不完全准确。 Reading order is inferred from positions. Prose columns are read column by column and tables row by row; very complex pages (magazine layouts with pictures) may not come out perfectly.
原则 / Principles
- 只读取 OFD,不生成、不修改发票。 Reads OFD only. It never creates or modifies invoices.
- 本项目大部分代码由 AI(Claude)编写,维护者负责决定方向和批准发布。 Most code is written with AI assistance (Claude). The maintainer sets the direction and approves releases.
许可证 / License
來源:README.md,提交 2e21cce
工具
0版本歷史
1- v0.4.0最新Oct 29, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分