Skip to main content
Glama
Hashline Filesystem MCP

Hashline Filesystem MCP

by okdshin

hashline-filesystem-mcp

MCP server for hashline-based file editing. Each line is tagged with a short content hash, so LLMs can reference lines by anchor instead of reproducing exact text.

Inspired by The Harness Problem and the oh-my-pi coding agent.

Concept

Standard str_replace tools require the model to reproduce exact text — whitespace, indentation, and all. Hashline sidesteps this:

1:6add9f2e|function hello() {
2:0d79a1bc|  return "world";
3:cbb1f034|}

The model references 0d79a1bc as an anchor. The hash is an 8-char MD5 prefix of the line content, recomputed from the actual file on each edit — so if the file has changed since the model last read it, the hash won't match and the edit is rejected (optimistic locking).

Related MCP server: Files MCP Server

Setup

python -m venv venv
venv/bin/pip install mcp

Optionally install ripgrep for faster grep (rg on PATH). Falls back to Python re if unavailable.

Claude Code integration

Add to ~/.claude/claude.json (or project-level .claude/claude.json).

No manual installation needed — uvx fetches and runs the package automatically:

{
  "mcpServers": {
    "hashline-fs": {
      "command": "uvx",
      "args": ["hashline-filesystem-mcp"]
    }
  }
}

With restrictions:

{
  "mcpServers": {
    "hashline-fs": {
      "command": "uvx",
      "args": [
        "hashline-filesystem-mcp",
        "--allowed-dirs", "/home/user/projects",
        "--max-file-size", "1MiB"
      ]
    }
  }
}

Using a local virtualenv

{
  "mcpServers": {
    "hashline-fs": {
      "command": "/path/to/hashline_filesystem_mcp/venv/bin/python",
      "args": ["/path/to/hashline_filesystem_mcp/server.py"]
    }
  }
}

CLI options

--allowed-dirs DIR [DIR ...]   Restrict access to these directories (default: unrestricted)
--max-file-size SIZE           Reject reads/writes larger than SIZE (default: 0 = unlimited)
                               Accepts plain bytes or a unit suffix: 1MiB, 512KiB, 10MB, etc.
                               Units: B, KB, MB, GB, TB (powers of 1000), KiB, MiB, GiB, TiB (powers of 1024)

Tools

read_file

Read a file in hashline format.

path:   file path
offset: start line, 1-indexed (default 1)
limit:  max lines to return, 0 = all (default 0)

Output:

1:6add9f2e|function hello() {
2:0d79a1bc|  return "world";
3:cbb1f034|}

read_multiple_files

Read multiple files in a single call, each in hashline format. Files that cannot be read are reported inline without aborting the rest.

paths: list of file paths

grep

Search files and return results in hashline format. Match lines are prefixed with *, context lines with a space.

pattern:       regex (or literal string when fixed_strings=True)
path:          file or directory (default: current dir)
context:       lines of context around each match (default 2)
fixed_strings: treat pattern as literal string
file_glob:     file filter, e.g. "*.py"

Output:

# src/app.py
 1:eb18c3a1|import express
*3:a2f1d90e|const app = express()
 4:d41d8cd9|

Uses rg --json when ripgrep is available, pure Python otherwise.

edit_file

Edit a file using hash anchors. All operations are validated before writing — if any anchor is not found, the entire edit is rejected and the file is unchanged.

path:       file path
operations: list of operation objects (see below)

Returns the resulting file in hashline format.

Operations

replace — replace a range of lines (first..last inclusive):

{ "type": "replace", "first": "6add9f2e", "last": "cbb1f034", "content": "new content\nhere" }

insert_after — insert lines after an anchor:

{ "type": "insert_after", "anchor": "cbb1f034", "content": "// added\n" }

insert_before — insert lines before an anchor:

{ "type": "insert_before", "anchor": "6add9f2e", "content": "// preamble" }

delete — delete a range of lines:

{ "type": "delete", "first": "0d79a1bc", "last": "0d79a1bc" }

replace_text — fallback text replace (no hash needed, requires opt-in):

{ "type": "replace_text", "old_text": "world", "new_text": "universe", "all": false, "acknowledged": true }

acknowledged: true is required to confirm intentional use, since replace_text bypasses hash anchoring and line-boundary guarantees.

Anchor format

  • "a3b4c5d6" — hash only (8 hex chars). Fails if the same hash appears on multiple lines (e.g. duplicate blank lines).

  • "11:a3b4c5d6" — linenum:hash. Use this to disambiguate when the same hash appears more than once.

Optimistic locking

If a referenced hash is not present in the file at edit time, the operation returns an error and the file is not modified. This catches the case where the model's view of the file is stale.

write_file

Create or overwrite a file. Returns the written content in hashline format so hashes are immediately available for edits.

path:    file path (parent directories are created if needed)
content: file content

move_file

Move or rename a file or directory. Creates destination parent directories if needed.

source:          source path
destination:     destination path
allow_overwrite: overwrite destination if it exists (default: false)

list_directory

List files and directories.

path:       directory path (default: current directory)
recursive:  list recursively
show_sizes: include file sizes and directory entry counts (default: true)

Hidden entries (names starting with .) are always excluded.

get_file_info

Return metadata for a file or directory: size, line count, timestamps, and permissions.

path: file or directory path

list_allowed_directories

Show which directories this server is allowed to access. Returns the configured allowed directories, or indicates unrestricted access if none were specified at startup.

Typical workflow

read_file("src/app.py")
→ 1:eb18c3a1|import express
  2:d41d8cd9|
  3:a2f1d90e|const app = express()
  ...

edit_file("src/app.py", [
  { "type": "insert_after", "anchor": "eb18c3a1", "content": "import cors" },
  { "type": "replace", "first": "a2f1d90e", "last": "a2f1d90e", "content": "const app = express()\napp.use(cors())" }
])

grep("TODO", "src/", context=1, file_glob="*.ts")
→ # src/routes.ts
   4:c3aa71f2|// handler
  *5:f812e04b|// TODO: add auth
   6:d41d8cd9|

edit_file("src/routes.ts", [
  { "type": "replace", "first": "f812e04b", "last": "f812e04b", "content": "// auth handled by middleware" }
])

Running tests

venv/bin/pytest tests/ -v

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables Large Language Models to safely browse and interact with local file systems through secure directory listing, file reading, and content search capabilities. Built with comprehensive security controls and high-performance handling of large directories and files.
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to safely explore directories, read files, search content by pattern or filename, and edit files with checksum verification and dry-run preview within sandboxed filesystem access.
      76
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides hashline-based file editing using line-addressed edits and content hashes for integrity verification. It enables LLMs to perform precise file modifications while ensuring edits are rejected if the file content has changed since the last read.
      10
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables agents to read, write, edit, search, rename, move, and delete files, perform regex search-and-replace across trees, query and modify JSON documents, and inspect git status and diffs, all through structured tools instead of shell commands. Includes safeguards like dry-run previews, atomic multi-file edits, and protection for denied or sensitive paths.
      MIT