
hledit MCP
io.github.dabito由 GitHub 帳號 dabito 發布v0.1.4更新於 Oct 24, 2026
Hash-anchored file edits for MCP clients. Rejects stale writes before they happen.
概覽
一個 MCP 伺服器,為程式設計助理提供以雜湊錨點為基礎的檔案讀取與編輯,並在寫入磁碟前拒絕錨點已失效的修改。
- 可以做什麼
- 依行號與雜湊錨點讀取檔案,可依子字串篩選並顯示上下文行,支援位移與行數上限。執行單次錨點修改:取代、插入、刪除或取代兩個錨點之間的範圍。在一次批次呼叫中套用多處錨點編輯,支援結構化陣列或舊版 JSON 字串。回傳精簡的修改摘要,啟用後可附上受行數限制的差異區塊。
- 適用情境
- 適用於程式設計助理編輯本機工作區檔案的情境,希望在上下文過期時明確報錯,而不是盲目取代文字,例如多個編輯或多個代理可能同時改動同一檔案時。
- 執行需求
- 透過 npx 以 stdio 在本機執行。需要 Node.js 18+,以及用 Go 1.21+ 安裝的 hledit 命令列工具或位於 PATH 上的預先編譯二進位檔。選用環境變數:HLEDIT_BIN 指定二進位檔路徑,HLEDIT_CWD 限定可編輯工作區,HLEDIT_MCP_DIFF 及其行數、上下文與儲存格上限用於啟用差異輸出。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 hledit MCP,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
hledit-mcp
[npm version] [License: MIT] [MCP Registry] [Glama]
hledit-mcp is an MCP server exposing hledit's hash-anchored file edits to standard MCP clients such as Claude Code, Claude Desktop, and Cursor.
Same idea as pi-hledit (the Pi-native integration), but over MCP instead of Pi's extension API, so the same edit primitive can be used from MCP-compatible clients.
Official MCP Registry: io.github.dabito/hledit-mcp.
Instead of asking an agent to reproduce old text exactly, hledit read annotates each line with a stable anchor:
Write commands reference anchors such as 6#M9A. Before changing the file, hledit recomputes the hash at that line. If the file changed since it was read, the anchor is rejected and no write happens — the agent gets a stale error and a remap hint instead of silently corrupting the wrong line.
Demo
See docs/demo/transcript.md for a deterministic MCP stdio transcript showing stale-write rejection over the actual hledit-mcp tool surface.
The transcript is generated by docs/demo/hledit-mcp-demo.mjs, which drives dist/index.js through @modelcontextprotocol/sdk's stdio client. It does not call hledit directly.
MCP server for stale-write-safe file editing
hledit-mcp gives MCP-compatible coding agents one file-editing tool that reads line anchors, validates those anchors against current file contents, and rejects stale writes before touching disk. It is for local workspace edits where you want explicit stale-context failure instead of blind text replacement.
Why MCP, separately from pi-hledit
pi-hledit and hledit-mcp share the same tool contract (core.ts in this repo — arg-building, batch translation, result formatting) and the same underlying hledit CLI. Only the registration/execution glue differs: pi-hledit wires that contract into Pi's registerTool, this wires it into @modelcontextprotocol/sdk's McpServer. MCP has no equivalent of Pi's renderCall/renderResult terminal rendering, so this package doesn't have one either — that layer is genuinely Pi-specific chrome, not part of the portable tool contract.
Use hledit-mcp when you want stale-write rejection over an MCP tool boundary instead of relying on a host's native text replacement behavior.
Requirements
- Go 1.21+ to install the
hleditCLI (or a prebuilt binary onPATH) - Node.js 18+
- An MCP-compatible client
Install
Install the hledit CLI first:
Then configure your MCP client to run hledit-mcp. For Claude Code, verify the current CLI syntax with claude mcp add --help; recent versions use:
Claude Desktop and other MCP clients can use the same stdio server shape:
Set HLEDIT_CWD to the workspace the MCP client should allow hledit to edit.
Configuration
Tool
hledit
One tool, three operations, matching pi-hledit's contract exactly:
Workflow: read to get anchors → edit (single change) or batch (multiple). If an edit returns stale, re-read to get fresh anchors before retrying — the anchor's line moved or changed since it was read.
Successful edit and batch calls return concise summaries, including Lines: +N -M when the installed hledit CLI provides line delta metadata (hledit >= 1.2.4). Older hledit versions still work; they just omit the line delta summary.
Contextual grep uses a small default window (context:2) when grep is set; pass context:0 for match-only output.
Set HLEDIT_MCP_DIFF=1 to append a capped fenced diff block for successful edits. Leave it off for the most token-economical MCP responses.
Preferred batch shape uses structured edits so the MCP/RPC layer handles escaping:
Contextual grep example:
Match-only grep example:
Legacy JSON-string edits remains supported during the transition.
Default read calls are bounded: when offset/limit are omitted, the server uses offset=1 and limit=2000.
Development
Unit tests in core.test.ts cover the same contract as pi-hledit's test suite, minus the Pi-specific rendering assertions (there's no render layer here). e2e.test.ts drives the built dist/index.js over a real MCP stdio handshake with @modelcontextprotocol/sdk's own Client/StdioClientTransport — the same artifact npx hledit-mcp runs, not just the TypeScript source.
The published bin/main point at dist/index.js, built with esbuild (build.mjs) and run via plain node — this keeps the >=18 Node requirement honest. Running index.ts directly with node (no tsx) only works on Node ≥22.6, which has built-in TypeScript type-stripping; older LTS versions have no such support at all.
Credits and prior art
The hashline-edit idea comes from Can Bölük / @can1357's coding-agent harness work, especially “I Improved 15 LLMs at Coding in One Afternoon. Only the Harness Changed.” and oh-my-pi. See hledit's credits for more prior art.
Related packages
來源:README.md,提交 3814b39
工具
0版本歷史
1- v0.1.4最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分