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.

已验证STDIO仅桌面文件与存储开发者工具

概览

AI 生成的概览

一个 MCP 服务器,为编程助手提供基于哈希锚点的文件读取与编辑,在写入磁盘前拒绝锚点已失效的修改。

可以做什么
按行号与哈希锚点读取文件,可按子串过滤并显示上下文行,支持偏移与行数上限。执行单次锚点修改:替换、插入、删除或替换两个锚点之间的范围。在一次批量调用中应用多处锚点编辑,支持结构化数组或旧版 JSON 字符串。返回简洁的修改摘要,启用后可附带受行数限制的差异块。
适用场景
适用于编程助手编辑本地工作区文件的场景,希望上下文过期时明确报错而不是盲目替换文本,例如多个编辑或多个代理可能同时改动同一文件时。
运行要求
通过 npx 以 stdio 在本地运行。需要 Node.js 18+,以及用 Go 1.21+ 安装的 hledit 命令行工具或位于 PATH 上的预编译二进制。可选环境变量:HLEDIT_BIN 指定二进制路径,HLEDIT_CWD 限定可编辑工作区,HLEDIT_MCP_DIFF 及其行数、上下文和单元格上限用于启用差异输出。
安装前请注意
服务器会写入其所指向工作区中的文件,应将 HLEDIT_CWD 限定在期望客户端编辑的目录内。锚点过期时修改会被拒绝,助手需重新读取后再重试。差异输出默认关闭以保持响应紧凑。

安装

在 SourceWeft 中

  1. 打开 控制台中的 hledit MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

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:

text
5#K7Q:func main() {6#M9A:    fmt.Println("hello")7#R2C:}

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 hledit CLI (or a prebuilt binary on PATH)
  • Node.js 18+
  • An MCP-compatible client

Install

Install the hledit CLI first:

bash
go install github.com/dabito/hledit@latest

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:

bash
claude mcp add hledit -- npx -y hledit-mcp

Claude Desktop and other MCP clients can use the same stdio server shape:

json
{  "mcpServers": {    "hledit": {      "command": "npx",      "args": ["-y", "hledit-mcp"],      "env": {        "HLEDIT_CWD": "/path/to/workspace"      }    }  }}

Set HLEDIT_CWD to the workspace the MCP client should allow hledit to edit.

Configuration

VariableDefaultDescription
HLEDIT_BINhledit (on PATH)Path to the hledit binary, if not on PATH.
HLEDIT_CWDserver's process.cwd()Working directory hledit resolves relative paths against. Keep this scoped to the workspace you expect the MCP client to edit.
HLEDIT_MCP_DIFF0Opt-in textual diff output for successful edit/batch calls. Off by default to keep MCP/model context compact. Set 1, true, or yes to enable.
HLEDIT_MCP_DIFF_MAX_LINES80Max diff lines when HLEDIT_MCP_DIFF is enabled, including the omission marker. Minimum accepted value: 3.
HLEDIT_MCP_DIFF_CONTEXT2Context lines around changed ranges when diff output is enabled. Minimum accepted value: 0.
HLEDIT_MCP_DIFF_MAX_CELLS40000Max LCS comparison cells before diff body is omitted. Minimum accepted value: 1.

Tool

hledit

One tool, three operations, matching pi-hledit's contract exactly:

opPurpose
readRead annotated lines with LN#HASH anchors
editApply a single replace/insert/delete/replace-range
batchApply multiple anchor-referenced edits in one call
NameTypeRequiredDescription
opstring✓"read", "edit", or "batch"
pathstring✓File path
offsetnumber1-indexed starting line (read)
limitnumberMax lines to return (read); defaults to 2000
contextnumberSurrounding lines around each grep match; defaults to 2 when grep is set, use 0 for match-only output
grepstringFilter lines by substring (read)
actionstringreplace, insert, delete, or replace-range (edit)
end_anchorstringEnd anchor for replace-range/range delete
contentstringReplacement/inserted content; empty = delete
afterbooleanFor action:"insert", insert after the anchor
editsarray or stringfor batchPreferred: structured array of batch edit ops (replace/delete/insert). Legacy JSON string still accepted.

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:

json
{  "op": "batch",  "path": "src/file.ts",  "edits": [    { "op": "replace", "anchor": "12#NKT", "lines": ["const ok = true;"] }  ]}

Contextual grep example:

json
{ "op": "read", "path": "src/file.ts", "grep": "validateToken" }

Match-only grep example:

json
{ "op": "read", "path": "src/file.ts", "grep": "validateToken", "context": 0 }

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

bash
npm installnpm test          # typecheck + build + unit/e2e tests + lintnpm run build      # compile index.ts+core.ts to dist/index.jsnpm start         # run the server directly from source via tsx (stdio transport)

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

  • hledit — the standalone CLI both integrations wrap.
  • pi-hledit — the Pi-native integration, same tool contract.

来源:README.md,提交 3814b39

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.4最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分