Skip to main content
Glama

Edit file

edit_file
Destructive

Replace an exact text string in a file to fix content issues. Requires precise match; use context or replaceAll for duplicates, and read the file first.

Instructions

Replace an exact string in an existing text file. The oldString must match the file content exactly, including whitespace and indentation. If oldString appears more than once, either add more surrounding context to make it unique or set replaceAll=true. Read the file first with read_file. The change is written to disk immediately and is not reversible. For several files or several changes at once, prefer patch so all edits succeed or none are applied.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesWorkspace-relative path of the file to edit. Absolute paths inside the workspace are also accepted.
newStringYesReplacement text. Use an empty string to delete the matched text.
oldStringYesExact text to replace. Must not be empty.
workspaceNoWorkspace name (see workspace_list). Defaults to the primary workspace.
replaceAllNoReplace every occurrence instead of requiring a unique match. Defaults to false.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.5.0

TDQS

A4.7/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true, but the description adds meaningful context: 'The change is written to disk immediately and is not reversible.' This goes beyond the structured hint by disclosing immediacy and irreversibility, which materially affect how an agent should invoke the tool.

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?

Four sentences, each earning its place: purpose, matching constraint, ambiguity handling, and atomicity guidance via patch. The core behavior is front-loaded and no words are wasted.

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 destructive mutation tool, the description covers the prerequisite (read_file first), the matching pitfalls, the multi-occurrence handling, and the reversible-vs-atomic tradeoff with an alternative tool. No output schema exists, but return values are secondary for a tool whose effects are the point; the description is complete enough to call it correctly.

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 the baseline is 3, but the description adds real value: it explains that oldString must match the file content exactly including whitespace and indentation, explains the ambiguity condition ('If oldString appears more than once'), and prescribes the remedy (more context or replaceAll=true). These semantics are not present in the schema.

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 states a specific verb and resource ('Replace an exact string in an existing text file'), and the exact-match semantics distinguish it from siblings like write_file and patch. An agent can immediately tell what this tool does and how it differs from nearby alternatives.

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?

It explicitly instructs the agent to read the file first with read_file and names patch as the preferred alternative when multiple changes must be atomic ('so all edits succeed or none are applied'). This gives clear when-to-use and when-not-to-use guidance without leaving it to inference.

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