Skip to main content
Glama

Edit a file

edit_file
Destructive

Replace exact text in a file without rewriting it, keeping permissions and uniqueness checks; reports where the closest match differs instead of applying a near match.

Instructions

Change part of a text file: replace old_string (exact, whitespace included, unique unless replace_all) with new_string; atomic, keeps permissions. Refuses what write_file refuses. If old_string is not there, it says where the closest text is and how it differs; it never applies a near match. Prefer this to rewriting a file with write_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>",
      "old_string": "<old_string>",
      "new_string": "<new_string>"
    },
    "name": "edit_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
whyNoone line in plain words: what this does and why (logged). With outside_sandbox: what the user asked for that the sandbox blocked
pathYesthe file: absolute, ~/..., or relative to the home folder
new_stringYesthe text to put in its place
old_stringYesthe exact text to replace, whitespace and line breaks included
replace_allNoreplace every occurrence (default false: old_string must occur exactly once)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.7.3
    • addedInput schema / properties / new_string / description
      Added value: +"the text to put in its place"
    • addedInput schema / properties / old_string / description
      Added value: +"the exact text to replace, whitespace and line breaks included"
    • addedInput schema / properties / path / description
      Added value: +"the file: absolute, ~/..., or relative to the home folder"
    • addedInput schema / properties / replace_all / description
      Added value: +"replace every occurrence (default false: old_string must occur exactly once)"
  2. First observedv0.7.1

TDQS

A4.5/5.0
Behavior5/5

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

Annotations only declare destructiveHint=true and openWorldHint=false; the description goes well beyond that by disclosing atomicity, permission preservation, shared refusal policy with write_file, and the exact failure behavior when old_string is absent (reports the closest text and how it differs, never applies a near match). That failure-mode disclosure is precisely what prevents an agent from assuming a fuzzy edit succeeded.

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?

Front-loaded with the core action, then constraints, then failure semantics, then the sibling comparison, all in four tightly packed sentences. Every clause carries information an agent needs; 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?

With no output schema and five fully documented parameters, the description supplies the remaining needed context: atomicity, permission retention, uniqueness rules, and what happens on a failed match. An agent can call this correctly and interpret a rejection without further documentation.

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% and already states that old_string is exact with whitespace, that replace_all defaults to false, and that old_string must then occur exactly once. The description's parameter statements largely restate the schema; its genuinely new content (near-match refusal) is behavioral rather than semantic, so baseline 3 applies.

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?

Names a specific verb and resource ("Change part of a text file") and immediately pins down the operation as replacing old_string with new_string. It also distinguishes itself from write_file, so an agent can separate the two tools 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 Guidelines4/5

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

Explicit routing guidance: "Prefer this to rewriting a file with write_file," plus "Refuses what write_file refuses," which tells the agent the two tools share a safety envelope. It stops short of stating when-not-to-use conditions (e.g. creating new content or whole-file rewrites) beyond the write_file comparison.

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