Skip to main content
Glama
boundary-edit

boundary-edit

by hypnotox

boundary-edit

Two file tools for coding agents, boundary_edit and boundary_read, that address a region of a file by literal text at its two ends instead of by line numbers or by reproducing the old content. One plugin provides them to Claude Code, Antigravity, Codex, omp, and OpenCode through a single bundled MCP server.

Use boundary_edit to replace or delete a substantial region when naming its boundaries is simpler than repeating what is there. Use the harness's ordinary edit tool for small, exact substitutions. Use boundary_read when known start and end content identifies what you want to inspect, or to check uncertain boundaries before a large edit. Reading first is optional.

Requirements

Node.js 20 or newer on PATH. Every harness starts the server as node. Nothing else is installed or built: the server is one committed JavaScript file with no dependencies.

Related MCP server: codeloupe-mcp

How addressing works

Both tools take one existing UTF-8 file and an array of ranges. Each end of a range is { "text": "...", "side": "before" | "after" }. The anchor text must occur exactly once in the entire file, counting overlapping matches. Matching is literal and case-sensitive, including whitespace and line endings. before is the position immediately before the whole matched text and after is immediately after it. Positions do not snap to lines. Anchors may be inline or span lines, may overlap each other, and may be context outside the selected content.

Editing

{
  "path": "/work/project/notes.md",
  "edits": [
    {
      "start": { "text": "The result is ", "side": "after" },
      "end": { "text": ", provided", "side": "before" },
      "replacement": "reliable"
    }
  ]
}

For The result is acceptable, provided retries are enabled., this replaces only acceptable. The region is the half-open interval from start to end, and it is replaced with exactly replacement. An empty replacement deletes it. No spaces or line terminators are inferred, appended, or kept inside the selected span. Everything outside it stays byte-for-byte unchanged. To replace a function without taking the next one, use the next function's signature with side: "before" as the end.

A side is a character position, never snapped to a line boundary. To replace the whole lines between two marker lines, include the start marker's line break in its text, and end the replacement with a line break:

{ "start": { "text": "BEGIN\n", "side": "after" }, "end": { "text": "END", "side": "before" }, "replacement": "replaced\n" }

With "BEGIN" instead of "BEGIN\n", the span would start with BEGIN's own line break, and the replacement would join the marker lines.

Every entry resolves against the same original file, not the result of earlier entries, and the whole batch is validated before anything is written. Missing or ambiguous anchors, reversed positions, unpaired surrogates, or overlapping regions leave the file unchanged. Shared or overlapping context anchors are fine when the regions themselves are disjoint. Adjacent regions are allowed. Equal start and end positions select an empty region, which inserts; two insertions at the same position, or an insertion strictly inside another replacement, are rejected.

The result gives an overall summary, a replaced, deleted, or unchanged outcome and the original span for each entry, selected and replacement sizes in lines and UTF-8 bytes, and a line-numbered diff. A byte-identical result is not written. Feedback is capped at 200 lines / 8 KiB.

Reading

{
  "path": "/work/project/README.md",
  "ranges": [
    {
      "start": { "text": "## Installation", "side": "before" },
      "end": { "text": "## Configuration", "side": "before" }
    }
  ],
  "maxLines": 40
}

In a document where both headings are unique, this reads the installation section without the configuration heading. ranges may hold several independent or overlapping regions. Each one reports its exact half-open [line:column, line:column) span, its size, and whether its content is complete. Positions are one-based and columns count Unicode code points. Content is returned as it is in the file, without line numbers.

maxLines

Content returned per range

Omitted

Up to 40 content lines

Positive integer N

A total budget of N content lines

"all"

All selected content, subject to the ceiling

maxLines limits output only and never changes the selected span. A large range shows its beginning and end with an explicit omission marker. The whole response is capped at 8 KiB, and when space is tight it is shared so a large first range does not hide later ones. Each range is resolved independently: a call with any invalid range is reported as an error and still carries the content of the valid ones.

Paths

Prefer an absolute path. ~/ and a leading @ are accepted. A relative path resolves against the session's workspace root as the harness reports it, and the result then shows the resolved absolute path. That root does not follow an agent into a subdirectory or another worktree. When the harness reports several roots or none, a relative path is an error that asks for an absolute one.

Failures

A failure names the entry, the selector, and the cause, suggests a correction, and shows nearby candidate locations when there are any. A search for an ambiguous anchor stops after six matches and says so. Nothing is ever guessed or matched loosely. Once writing has begun, an I/O failure warns that the file may be partially modified.

Limitations

  • Plain text only. Results are text in every harness; there is no native diff view.

  • Reading is not protection against stale content. Editing resolves anchors against the file as it is at that moment and overwrites whatever is between them. There are no snapshots, selection IDs, or reservations.

  • No coordination with other tools. Calls for the same file, including through symlinks, run one at a time and in arrival order within one server process. The harness's own edit tools, other processes, and editors are not covered. A harness that tracks which files it has read may ask for a re-read after boundary_edit changed one.

  • One UTF-8 file per call. An initial byte order mark is preserved and excluded from content and counts. Malformed UTF-8 is rejected. Line endings, indentation, and Unicode are never normalized. There are no cross-file transactions.

  • Literal anchors only. No line numbers, occurrence counts, regular expressions, fuzzy matching, or syntax awareness.

  • A started call runs to completion. Cancellation requests are ignored, so a write is never abandoned midway.

Installation

Each harness reads committed files from this repository; there is no build or npm install step.

Claude Code

claude plugin marketplace add hypnotox/boundary-edit
claude plugin install boundary-edit@boundary-edit

# Local checkout, for one session
claude --plugin-dir /absolute/path/to/boundary-edit

The tools appear as mcp__plugin_boundary-edit_boundary-edit__boundary_edit and …__boundary_read.

Antigravity

agy plugin install /absolute/path/to/boundary-edit

# Or clone into the global plugin directory
git clone https://github.com/hypnotox/boundary-edit.git ~/.gemini/config/plugins/boundary-edit

Headless runs (agy -p) cannot ask for permission and deny MCP tools by default. To allow these two, add "permissions": { "allow": ["mcp(boundary-edit_boundary-edit/*)"] } to ~/.gemini/antigravity-cli/settings.json.

Codex

codex plugin marketplace add hypnotox/boundary-edit
codex plugin add boundary-edit@boundary-edit

Codex runs boundary_read without asking and asks for approval before each boundary_edit. Non-interactive runs (codex exec) cannot approve, so boundary_edit fails there. To pre-approve it, define the server yourself instead of installing the plugin:

# ~/.codex/config.toml
[mcp_servers.boundary-edit]
command = "node"
args = ["/absolute/path/to/boundary-edit/server/boundary-edit.mjs"]
default_tools_approval_mode = "approve"

Codex does not sandbox MCP servers. boundary_edit therefore honors the session's permission profile itself: in a read-only session, or for a path the profile does not make writable, it refuses and leaves the file unchanged, even after you approve the call. This follows your chosen mode; it is not a security boundary, and it understands plain path entries and the root and temporary-directory entries only.

omp (Oh My Pi)

omp plugin marketplace add hypnotox/boundary-edit
omp plugin install boundary-edit@boundary-edit

# Local checkout, for one session
omp --plugin-dir /absolute/path/to/boundary-edit

OpenCode

OpenCode has no plugin manifest for MCP servers, so the package ships a small module that registers the server.

opencode plugin add git+https://github.com/hypnotox/boundary-edit.git

This writes your global configuration and applies to every project. For one project only, add a file .opencode/plugins/boundary-edit.js that re-exports the module from a checkout:

export { default } from "/absolute/path/to/boundary-edit/opencode/server.js";

An MCP server you have configured yourself under the name boundary-edit takes precedence over the plugin's.

Verification status

Model-driven calls of both tools have been observed in all five harnesses; in Codex, boundary_edit only with the server pre-approved. The Codex and OpenCode install commands above have been run against this repository. docs/topics/harness-loading.md keeps the current per-harness record.

Development

Sources are TypeScript under src/. server/boundary-edit.mjs is generated from them by scripts/bundle.ts and committed, because harnesses run it directly.

npm install
npm run bundle    # after changing src/
npm run check     # types, bundle freshness, tests, plugin validators
./awf check       # documentation bundle and generated workflow files
npm pack --dry-run

Development needs Node 22.18 or newer, because the bundle script is TypeScript run directly by Node, and npm run check needs the Claude Code and Antigravity CLIs for their plugin validators. No lockfile is committed. Contributor guidance is in AGENTS.md; how each harness loads the plugin is in docs/topics/harness-loading.md.

License and provenance

AGPL-3.0-only. The editing core was adapted from the boundary-edit extension of pi-tools. The bundle includes third-party code under the MIT and BSD-3-Clause licenses; see NOTICE.

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
      A
      quality
      B
      maintenance
      Enables reading, creating, and editing files on the local filesystem through operations like view, create, string replacement, and line insertion.
      4
      384 npm
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables coding agents to inspect files, search text, compare directories, read symbols, and apply structured edits against large codebases through bounded, local-first MCP tools.
      4
      Apache 2.0
    • A
      license
      B
      quality
      C
      maintenance
      Enables AI agents to read, replace, and write files through line-range-scoped, byte-literal edits that preserve CRLF/LF line endings and indentation, reject ambiguous matches, and perform atomic writes. It returns the actual current range content and a self-correction hint on mismatch, eliminating 'Could not find oldString' failures in MCP clients like opencode and Claude Desktop.
      3
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables agents to perform bounded binary-file inspection, hashing, search, and diffing within configured roots, and to preview and apply expected-byte-validated patches that produce new output copies while preserving originals. It also reads a user's existing GUI session—active buffer context, selections, and unsaved in-memory bytes—through trusted templates, with mutations to live buffers explicitly disabled.
      14
      2
      MIT