Skip to main content
Glama

Edit file

edit_file
Destructive

Edit files using exact text replacement or line-range edits. Ensures atomic updates with revision validation and dry-run previews.

Instructions

Edit a file. Two mutually exclusive edit shapes: {oldText,newText} literal replacement, or line edits (1-based). {startLine,endLine,newText} replaces the inclusive range; newText "" deletes, no trailing newline. Omitting endLine INSERTS before startLine instead of replacing, and startLine = lines+1 appends at EOF. Line edits require rev and are applied bottom-up in one atomic pass, so numbers from a single grep/read stay valid; a stale rev is rejected, never applied. Returns the new rev. dryRun shows the diff. In a zone with policy overwrite="rev" every edit needs rev, including {oldText}; in overwrite="never" zones editing is refused outright. To replace a whole file use write_file. Document formats are read-only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
revNoFrom grep_files, read_text_file offset, or get_file_info
pathYes
editsYes
dryRunNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already flag destructive/non-idempotent, and the description adds substantial context beyond them: atomic bottom-up application so grep/read line numbers stay valid, stale rev rejection (never partially applied), the return value (new rev), dryRun diff preview, and per-zone policy behavior. This is exactly the operational detail a mutating tool needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and the two shapes, and nearly every sentence carries operational meaning. The density is high and the zone-policy clause packs several rules into one sentence, but nothing is padding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no output schema, the description covers input shapes, preconditions (rev), atomicity, failure behavior, the return value (new rev), dry-run, and the sibling alternative. An agent has everything required to call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is only 25% (rev is the sole documented param), so the description carries the burden and delivers: oldText/newText literal replacement, startLine/endLine inclusive range replacement, newText "" meaning delete with no trailing newline, and the insert/append edge cases. It fully compensates for the schema gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ("Edit a file") and immediately enumerates the two mutually exclusive edit shapes. It distinguishes itself from the sibling write_file explicitly ("To replace a whole file use write_file") and notes document formats are read-only, so an agent can place it against write_file without opening either schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete when-to-use rules for each shape, the exact conditions that select insert-vs-replace (omitting endLine inserts; startLine = lines+1 appends), the rev requirement for line edits, and the zone-policy exceptions (overwrite="rev" always needs rev; overwrite="never" refuses edits). It also routes whole-file replacement to write_file.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.