Skip to main content
Glama

Edit File

edit_file

Replace exact text blocks in a file and return a unified diff, avoiding full-file rewrites. Use for precise, low-cost edits with optional dry-run preview.

Instructions

Surgical edit: replace exact text blocks and return a unified diff. Much cheaper than rewriting a whole file.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>",
      "edits": "<edits>"
    },
    "name": "edit_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesFile to edit.
editsYesOne or more find/replace edits, applied in order.
dry_runNoOnly show the diff, don't save.

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.9/5.0
Behavior3/5

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

Annotations already declare non-read-only, non-destructive, non-idempotent behavior, and the description usefully adds that it returns a unified diff and performs exact-text surgical replacement. However, it omits critical behavior for exact-match editing: what happens when old_text is missing, non-unique, or when a later edit in the ordered list fails. Those failure semantics matter more here than for most mutation tools.

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?

Two tight sentences with the core capability and its cost advantage front-loaded, and no wasted wording. Brevity is appropriate, though the space saved could have carried one sentence on failure behavior without hurting readability.

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

Completeness4/5

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

An output schema exists, so the description needn't explain the diff return value, and the input schema is fully documented. What remains thin is error/ambiguity handling around exact matching, which the description leaves entirely to the schema's parenthetical about uniqueness.

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

Parameters3/5

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

Schema coverage is 100%, so path, old_text, new_text, replace_all, and dry_run are all documented in the schema, establishing the baseline of 3. The description only reinforces the 'exact text' nature of old_text and adds no syntax, formatting, or ordering detail beyond what the schema already provides.

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 ('replace') and resource ('exact text blocks'), plus the return value ('unified diff'). The phrase 'Much cheaper than rewriting a whole file' implicitly contrasts it with a whole-file write tool like write_file, so an agent can tell the two apart without opening schemas.

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

Usage Guidelines4/5

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

The comparison 'much cheaper than rewriting a whole file' gives clear selection guidance: prefer this over full-file rewrites for targeted changes. It stops short of naming write_file explicitly or stating when not to use it (e.g., large-scale restructures where a full rewrite is safer).

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