Skip to main content
Glama

replace_text_in_file

Destructive

Replace an exact text occurrence in a workspace file, with optional replace-all and case matching. Use dry_run to preview changes before writing through the open editor or disk.

Instructions

Replace text in a workspace text file as the window shows it, saved or not. old_text must occur exactly once unless replace_all is true; none or several occurrences are an error naming the count and the 1-based lines, and nothing changes. case_sensitive defaults to true. Returns replacements, the 1-based lines of the replaced places and applied. dry_run defaults to true; dry_run=false needs the user-granted write right and writes through the open editor as one undo step, or to the disk when the file is not open.

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_text": "<old_text>",
      "new_text": "<new_text>"
    },
    "name": "replace_text_in_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesWorkspace-relative text file.
dry_runNoOnly report what would change (default true); false writes, which needs the `write` right.
new_textYesWhat it becomes.
old_textYesThe text to replace (not empty).
replace_allNoReplace every occurrence (default false: the text must occur exactly once).
case_sensitiveNoMatch case (default true).

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.5.1

TDQS

A4.6/5.0
Behavior5/5

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

Goes well beyond the destructiveHint/openWorldHint annotations by disclosing that dry_run is the default, that writing needs the `write` right, that changes land in the open editor as a single undo step or on disk if the file is closed, and that on a uniqueness mismatch nothing changes. It even names the error contents (occurrence count and 1-based lines), which is the kind of consequence detail an agent needs before mutating a file.

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?

Front-loaded with purpose and the matching contract, then the return shape, then the dry-run/write gate — a sensible ordering with no filler. It is dense and a couple of sentences run long, but each one carries distinct information.

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?

Despite no output schema, the description explains what is returned (`replacements`, 1-based `lines`, `applied`) and covers the error case, permissions, and undo behavior. For a destructive six-parameter tool this leaves nothing an agent would need 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 semantics the schema does not carry: the exactly-once requirement on `old_text` unless `replace_all` is set, and the failure mode naming counts and 1-based lines. Defaults for `case_sensitive` and `dry_run` are merely restated from the schema, keeping it below a 5.

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?

States a specific verb and resource — replacing text in a workspace text file — plus the crucial scope detail that it acts on the file as the editor window shows it, saved or not. That scope alone distinguishes it from read_file or search_in_files, so an agent can pick it without opening the 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?

Gives clear operating context: dry_run defaults to true and must be explicitly set false to write, which requires the user-granted `write` right. It does not explicitly say when to prefer this over inspecting files with search_in_files or read_file, but the write-safety gate makes the intended use unambiguous.

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