Skip to main content
Glama

Edit File

edit_file
Destructive

Replace an exact string in a text file with minimal risk by matching exact text; use dry run to preview changes before applying.

Instructions

Replace an exact string in a text file. Much safer than rewriting the whole file with write_file — the rest of the file is untouched. The old_string must match exactly (including whitespace) and, unless replace_all is true, must appear exactly once; include surrounding lines to make it unique. If you cannot reproduce the text exactly, use edit_lines instead.

Args:

  • path (string): File to edit.

  • old_string (string): Exact text to find.

  • new_string (string): Replacement text.

  • replace_all (boolean): Replace every occurrence (default false).

  • dry_run (boolean): Preview the change without writing (default false).

Returns a confirmation plus the edited region with line numbers, so you can verify without re-reading the file.

Example: { "path": "~/app/config.py", "old_string": "DEBUG = True", "new_string": "DEBUG = False" }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile to edit
old_stringYesExact text to replace
new_stringYesReplacement text
replace_allNoReplace all occurrences
dry_runNoPreview without writing
Behavior4/5

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

Annotations already mark destructiveHint=true. The description adds valuable context: it's safer than write_file, the rest of the file is untouched, and it returns confirmation with line numbers. No contradiction with annotations.

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?

The description is concise and front-loaded with purpose and safety comparison. The example is helpful. The list of Args is somewhat redundant with the schema but does not detract significantly.

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?

Given the 5 parameters and no output schema, the description explains the return value (confirmation + edited region), gives an example, contrasts with siblings, and covers constraints. It is complete enough for effective use.

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 baseline is 3. The description adds minimal extra meaning (e.g., hint about surrounding lines for uniqueness) but mostly restates schema info in a different format.

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 uses a specific verb (replace) and resource (exact string in a text file), clearly distinguishing it from siblings like write_file and edit_lines. It states the core operation immediately.

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?

Explicitly tells when to use (exact match known) and when not to (use edit_lines if text cannot be reproduced exactly). Also warns about uniqueness requirement and the alternative when replace_all is false.

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/highercomve/mcptools'

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