Skip to main content
Glama

edit_file

Destructive

Replace exact text in files with transactional edits, validating all changes in memory and writing atomically to prevent partial file states. Supports dry-run and SHA-256 verification.

Instructions

Replace exact text in an existing UTF-8 file. Supply either old_text/new_text or an edits array. Array edits are validated in memory then written atomically, so a failed edit never leaves a partial file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath relative to the workspace root, or an allowed absolute path.
editsNoTransactional sequence of edits; all succeed or none are written.
dry_runNoReport what would change without writing the file.
new_textNoReplacement text.
old_textNoExact text to find, copied verbatim from read_file output.
replace_allNoReplace every occurrence; defaults to false.
expected_sha256NoOptional SHA-256 returned by a previous read or write. The call fails if the file changed since then.
expected_replacementsNoRequire exactly this many occurrences.
Behavior4/5

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

Beyond the destructiveHint annotation, the description adds valuable behavior: array edits are validated in memory and written atomically, so a failed edit never leaves a partial file. It also clarifies that the file must already exist and be UTF-8 encoded. There is no contradiction with the annotations.

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?

Two tight sentences with no filler. The purpose is front-loaded, and the important atomicity caveat is placed immediately after the mode description.

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?

For an 8-parameter mutation tool, the description is complete enough: it identifies the file scope, conditions, modes, and the key safety behavior. Parameter details are fully covered by the schema, and there is no output schema requiring return-value documentation. A brief comparison with sibling tools would make it fully complete.

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%, providing a strong baseline. The description adds meaning by making the either/or relationship between old_text/new_text and the edits array explicit, and by characterizing the array as transactional, which is not readily apparent from individual schema fields.

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

Purpose4/5

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

The description states a clear verb and resource: 'Replace exact text in an existing UTF-8 file.' It also conveys the two invocation modes, which helps separate it from broader file tools, though it does not explicitly name sibling alternatives.

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

Usage Guidelines3/5

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

The description implies when to use the tool ('Replace exact text in an existing UTF-8 file') and explains the two input modes. It does not provide explicit when-not-to-use guidance or compare with overlapping siblings such as update_file or apply_patch.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JonusNattapong/ChatGPTMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server