Hashfile MCP

io.github.mrorigo由 GitHub 账号 mrorigo 发布v0.3.0更新于 Oct 24, 2026

Hash-anchored file editing with surgical precision over file editing and ironclad control of access

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

概览

AI 生成的概览

本地 MCP 服务器,提供基于哈希锚点的文件编辑和 AGENTS.md 访问控制,让助手精确、可校验地读写项目文件。

可以做什么
  • 读取带哈希标记行的文件,并按锚点执行替换、插入、删除操作,附带文件哈希校验
  • 写入整个文件并返回带哈希行的校验结果
  • 浏览目录、生成紧凑目录树、创建目录、移动文件以及批量读取多个文件
  • 执行 AGENTS.md frontmatter 中的 forbidden、read_only、ignore 规则,并遵循 .gitignore 模式
适用场景
适合助手在文件可能被他人改动的项目中编辑代码、按行号编辑经常出错时使用;也适合希望用声明式规则阻止智能体接触密钥、锁文件和构建产物的场景。
运行要求
以本地 stdio 进程运行;README 说明可用 Cargo(Rust)从源码构建,或安装适用于 macOS、Linux、Windows 的预编译发布包。需在 MCP 客户端中配置该二进制文件路径。未声明任何账号、API 密钥或环境变量。
安装前请注意
它可以在被指定的目录中写入、移动和创建文件,访问限制取决于 AGENTS.md 规则是否正确。若未配置规则,无法阻止对敏感文件的修改。在指向含密钥的仓库前请先检查配置。

安装

在 SourceWeft 中

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

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Hashfile MCP Server

Fine-Grained Control for AI File Operations — A Model Context Protocol (MCP) server that gives you surgical precision over file editing and ironclad control over file access.

Why Hashfile MCP?

🎯 Surgical File Editing

Unlike traditional line-number-based editing that breaks when files change, Hashfile uses content-anchored operations:

  • Hash-Anchored Lines: Every line tagged with a content hash — edits target the right content, not just the right line number
  • Fuzzy Matching: Automatically finds moved lines even after insertions/deletions
  • Collision Detection: File-level verification prevents editing stale content
  • Multi-Operation Edits: Apply multiple precise changes in a single atomic operation

🔒 Ironclad Access Control

Take complete control over what AI agents can touch with AGENTS.md frontmatter:

  • forbidden: Block access to secrets, credentials, sensitive data
  • read_only: Allow reading schemas, configs, lock files — prevent modifications
  • ignore: Hide generated code, dependencies, build artifacts from AI context
  • Hierarchical Discovery: Place AGENTS.md anywhere in your tree — nearest file wins
  • Glob Patterns: Fine-tune access with wildcards (secrets/**, **/*.env)

📖 Full AGENTS.md Documentation | 📋 Proposal Spec

🛠️ Drop-In Filesystem Compatibility

All standard MCP filesystem tools included:

  • list_directory — Browse with [FILE]/[DIR] prefixes
  • directory_tree — Compact tree view (10x more token-efficient than JSON)
  • create_directory — Recursive directory creation
  • move_file — Rename/move files and directories
  • write_file — Raw UTF-8 writes (non-hashline)
  • read_multiple_files — Batch reads in one operation

Features at a Glance

FeatureBenefit
Hash-Anchored EditingEdits survive file changes — no more "line 42 doesn't match" errors
Content Verification6-character file hashing prevents race conditions
AGENTS.md SupportDeclarative access control — protect secrets, lock schemas, hide noise
Fuzzy Line MatchingFinds the right line even after insertions/deletions
9 MCP Tools3 hashline tools + 6 standard filesystem tools
Zero DependenciesPure Rust, compiles to a single binary

Installation

bash
cargo build --release

The binary will be at target/release/hashfile-mcp.

Quick Start

1. Configure Your MCP Client

Add to Claude Desktop or your MCP client config:

json
{  "mcpServers": {    "hashfile": {      "command": "/path/to/hashfile-mcp/target/release/hashfile-mcp"    }  }}

2. (Optional) Add Access Control

Create AGENTS.md in your project root:

markdown
---forbidden:  - "secrets/**"  - "**/*.env"  - ".git/**"
read_only:  - "package-lock.json"  - "Cargo.lock"  - "schema.sql"
ignore:  - "node_modules/**"  - "target/**"  - "**/*.generated.ts"---
# Project Instructions
Your custom instructions for AI agents here...

3. Start Editing

The AI can now:

  • ✅ Read and edit source files with hash-anchored precision
  • ✅ Browse directories and create new files
  • ❌ Cannot touch your secrets or .env files
  • ❌ Cannot modify lock files or schemas
  • 🙈 Won't see node_modules or build artifacts

How Hashline Works

The Problem

Traditional line-number editing fails when files change:

Agent: "Replace line 42"Reality: Someone inserted 3 lines at the topResult: Wrong line replaced! 💥

The Solution

Content-anchored editing with hash verification:

  1. Read: Each line gets a hash tag → 42:a3|const x = 1;
  2. Edit: Operations reference content, not just position → "anchor": "42:a3"
  3. Apply: Server finds the line by hash, even if it moved to line 45
  4. Verify: File hash must match — detects if content changed since read

Reliability Features

  • File-Level Verification: 6-character hash prevents editing stale content
  • Line-Level Anchoring: 2-character hash identifies specific lines
  • Fuzzy Matching: Searches for unique hash match if line number changed
  • Conflict Detection: Clear errors if content diverged

Core Tools

Hashline Tools (Precision Editing)

read_text_file

Returns content with hash-tagged lines for reliable editing:

1:a3|import { useState } from 'react';2:7f|3:2c|export function Counter() {---hashline_version: 1total_lines: 3file_hash: 8f3a9b
edit_text_file

Apply hash-anchored operations:

json
{  "path": "/path/to/file.ts",  "file_hash": "8f3a9b",  "operations": [    {      "op_type": "replace",      "anchor": "3:2c",      "content": "export function Counter({ initial = 0 }) {"    }  ]}

Operation types: replace, insert_after, insert_before, delete

write_text_file

Write content and get back hashline-tagged verification

Filesystem Tools (Standard Operations)

list_directory
[DIR] src[DIR] tests[FILE] README.md[FILE] Cargo.toml
directory_tree
src/├── agents.rs├── config.rs├── filesystem.rs├── hashline.rs├── main.rs└── tools.rs

Supports exclude_patterns for filtering (e.g., ["**/node_modules/**", "**/.git/**"])

create_directory, move_file, write_file, read_multiple_files

Standard filesystem operations with AGENTS.md enforcement

AGENTS.md Access Control

Constraint Types

ConstraintEffectUse Case
forbiddenBlock all accessSecrets, credentials, private keys
read_onlyAllow reads, block writesSchemas, lock files, generated configs
ignoreHide from AI contextDependencies, build artifacts, noise

Automatic .gitignore Support

Hashfile MCP automatically respects .gitignore files in your project:

  • Hierarchical: Walks up from target file to find all .gitignore files
  • Standard syntax: Supports standard .gitignore patterns (basename, directory, path)
  • Combined with AGENTS.md: Patterns from both sources are merged
  • Zero config: Works out of the box with existing projects

Pattern conversion:

# .gitignore*.log              → **/*.lognode_modules/      → node_modules/**build/output       → build/output

Precedence: AGENTS.md ignore patterns take precedence over .gitignore.

Example: Protect a Monorepo

yaml
---forbidden:  - "**/secrets/**"  - "**/*.key"  - "**/*.pem"  - ".env*"
read_only:  - "**/package-lock.json"  - "**/Cargo.lock"  - "db/schema.sql"
ignore:  - "**/node_modules/**"  - "**/target/**"  - "**/.next/**"  - "**/*.generated.*"---

Hierarchical Control

Place AGENTS.md files at any level:

/project/AGENTS.md          ← Global rules/project/backend/AGENTS.md  ← Backend-specific rules (overrides global)/project/frontend/AGENTS.md ← Frontend-specific rules

The nearest AGENTS.md in the directory hierarchy applies.

Development

Run Tests

bash
cargo test

Project Structure

src/├── main.rs        # MCP server setup├── tools.rs       # Tool definitions (9 tools)├── hashline.rs    # Hash-anchored editing logic├── filesystem.rs  # Standard filesystem operations├── agents.rs      # AGENTS.md frontmatter parsing├── config.rs      # Configuration (future: tool enablement)└── roots.rs       # Root path management (future)

Technical Details

  • Language: Rust (edition 2021)
  • MCP SDK: rmcp 0.15.0
  • Line Hashing: FNV-1a (2 hex chars, 256 buckets)
  • File Hashing: FNV-1a (6 hex chars, 16M buckets)
  • Transport: stdio
  • Dependencies: rmcp, serde, serde_json, serde_yaml, globset, anyhow, fnv

Roadmap

  • Environment variable-based tool enablement (ENABLE_FILESYSTEM_TOOLS=true)
  • Granular tool control (ENABLE_LIST_DIRECTORY=true, etc.)
  • Additional tools: get_file_info, search_files, list_directory_with_sizes
  • Command-line argument support for configuration

License

See LICENSE file for details.

See Also

  • The Harness Problem - I Improved 15 LLMs at Coding in One Afternoon. Only the Harness Changed. - Can Bölük Feb 2026
  • AGENTS.md Proposal - Frontmatter specification for agent access control

来源:README.md,提交 7fb6099

工具

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

版本历史

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

评分

已满足适用检查项的 40%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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

    请在仓库或注册中心条目中声明许可证。