Skip to main content
Glama

Edit

edit

Replace file content by exact text matching, with scoped line ranges, replace-all, and dry-run preview to avoid unintended changes.

Instructions

Edit one file by exact text replacement.

Three modes:

  • find/replace: old_string + new_string (the default).

  • scoped: add start_line/end_line to confine the search to a range.

  • line-range: omit old_string and give both lines to replace them wholesale.

old_string must match exactly — whitespace and indentation included — and, unless replace_all=true, must be unique, or the edit fails. Use edit_preview first if you're unsure an anchor is unique. Returns the replacement count and the affected line numbers, and refreshes the cache. The diff itself is omitted unless you ask for it with show_diff; diff_state always tells you which you got. A dry_run writes nothing and says so: the status is would_edit and dry_run: true comes back with it. For several edits to one file use batch_edit; for a full rewrite use write.

Pass known_hash and the response carries a claimable content_hash, so no read is needed afterwards. Without it, or with auto_format, you get file_hash instead — editing a file is not the same as having read it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile path to modify (absolute, or relative to root).
dry_runNoPreview without writing.
end_lineNo1-based inclusive end line for a scoped or line-range edit.
show_diffNoReturn the diff even on a deterministic edit.
known_hashNoThe `content_hash` from your last read of this file. Proves you hold the text being edited, so the result can be handed back as a claimable `content_hash`.
new_stringNoReplacement text (an empty string deletes the match).
old_stringNoExact text to find. Omit only for a line-range replacement.
start_lineNo1-based inclusive start line for a scoped or line-range edit.
auto_formatNoRun the formatter after editing.
replace_allNoReplace every occurrence instead of requiring a unique match.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.6.0
    • addedInput schema / properties / known_hash
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "The `content_hash` from your last read of this file. Proves\nyou hold the text being edited, so the result can be handed back as\na claimable `content_hash`."
      +}
    • changedOutput schema / (root)
      Previous value: -{
      -  "properties": {
      -    "content_hash": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Content Hash"
      -    },
      -    "diff": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Diff"
      -    },
      -    "diff_omitted": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Diff Omitted"
      -    },
      -    "diff_state": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Diff State"
      -    },
      -    "diff_stats": {
      -      "anyOf": [
      -        {
      -          "additionalProperties": true,
      -          "type": "object"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Diff Stats"
      -    },
      -    "from_cache": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "From Cache"
      -    },
      -    "line_numbers": {
      -      "anyOf": [
      -        {
      -          "items": {
      -            "type": "integer"
      -          },
      -          "type": "array"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Line Numbers"
      -    },
      -    "params": {
      -      "anyOf": [
      -        {
      -          "properties": {
      -            "auto_format": {
      -              "anyOf": [
      -                {
      -                  "type": "boolean"
      -                },
      -                {
      -                  "type": "null"
      -                }
      -              ],
      -              "default": null,
      -              "title": "Auto Format"
      -            },
      -            "dry_run": {
      -              "anyOf": [
      -                {
      -                  "type": "boolean"
      -                },
      -                {
      -                  "type": "null"
      -                }
      -              ],
      -              "default": null,
      -              "title": "Dry Run"
      -            },
      -            "replace_all": {
      -              "anyOf": [
      -                {
      -                  "type": "boolean"
      -                },
      -                {
      -                  "type": "null"
      -                }
      -              ],
      -              "default": null,
      -              "title": "Replace All"
      -            },
      -            "show_diff": {
      -              "anyOf": [
      -                {
      -                  "type": "boolean"
      -                },
      -                {
      -                  "type": "null"
      -                }
      -              ],
      -              "default": null,
      -              "title": "Show Diff"
      -            },
      -            "truncated": {
      -              "anyOf": [
      -                {
      -                  "type": "boolean"
      -                },
      -                {
      -                  "type": "null"
      -                }
      -              ],
      -              "default": null,
      -              "title": "Truncated"
      -            }
      -          },
      -          "title": "EditParams",
      -          "type": "object"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null
      -    },
      -    "path": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Path"
      -    },
      -    "replaced": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Replaced"
      -    },
      -    "status": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Status"
      -    },
      -    "tokens_saved": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Tokens Saved"
      -    },
      -    "truncated": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Truncated"
      -    }
      -  },
      -  "title": "EditResponse",
      -  "type": "object"
      -}New value: +null
  2. Changed9 schema fields changedv0.5.1
    • addedInput schema / properties / auto_format / description
      Added value: +"Run the formatter after editing."
    • addedInput schema / properties / dry_run / description
      Added value: +"Preview without writing."
    • addedInput schema / properties / end_line / description
      Added value: +"1-based inclusive end line for a scoped or line-range edit."
    • addedInput schema / properties / new_string / description
      Added value: +"Replacement text (an empty string deletes the match)."
    • addedInput schema / properties / old_string / description
      Added value: +"Exact text to find. Omit only for a line-range replacement."
    • addedInput schema / properties / path / description
      Added value: +"File path to modify (absolute, or relative to root)."
    • addedInput schema / properties / replace_all / description
      Added value: +"Replace every occurrence instead of requiring a unique match."
    • addedInput schema / properties / show_diff / description
      Added value: +"Return the diff even on a deterministic edit."
    • addedInput schema / properties / start_line / description
      Added value: +"1-based inclusive start line for a scoped or line-range edit."
  3. Addedv0.4.5

TDQS

A4.9/5.0
Behavior5/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure, and it does so thoroughly. It states exact-match requirements, uniqueness rules, return values (replacement count and line numbers), cache refresh behavior, diff omission unless show_diff is set, dry_run semantics, and hash implications. This covers both success paths and caveats.

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

Conciseness5/5

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

The description is long but front-loaded with the core purpose and mode summary. It is organized in scannable chunks, and every sentence contributes functional value: constraints, return behavior, hash semantics, and tool routing. Given the complexity of a 10-parameter editing tool, this length is earned rather than bloated.

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 complex file-editing tool with no annotations and no output schema, this description is remarkably complete. It explains all three invocation modes, uniqueness constraints, preview fallback, dry-run behavior, return values, diff control, and hash semantics. An agent has enough context to invoke the tool correctly without additional probing.

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

Parameters4/5

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

Schema coverage is 100%, so a baseline of 3 applies. The description adds meaningful semantic context beyond the schema by explaining how old_string, new_string, start_line, end_line, replace_all, dry_run, known_hash, and auto_format interact across the three modes. It does not merely repeat schema descriptions but frames them behaviorally.

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?

The description opens with a crisp statement: 'Edit one file by exact text replacement.' It immediately names the resource ('one file'), the action ('exact text replacement'), and goes on to distinguish itself from sibling tools like batch_edit and write. An agent can tell exactly what this tool does and what it does not do.

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?

The description provides explicit usage guidance: three modes are spelled out, when uniqueness is required, when to use edit_preview, and when to prefer batch_edit or write. It also explains when known_hash is beneficial and what happens without it. This is exemplary 'when to use vs. alternatives' content.

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