Skip to main content
Glama

file_replace

Destructive

Preview and apply exact text or C# identifier replacements across workspace files, with line-level matches, exclusions, and preserved encoding and line endings.

Instructions

Find and replace text across the files of one workspace, in two calls.

  1. PREVIEW (no planId): reads and matches, writes nothing. Shows every match with its line, the count, and a planId (a preview without a planId shows only counts per file).

  2. APPLY: the SAME arguments plus planId and confirmCount (the count after exclusions). Writes exactly the previewed matches in every file, or nothing. Only the matched characters change: encoding, byte order mark and every line ending stay as they were.

mode 'literal' (default): find is plain text on one line; caseSensitive (default true), wholeWord (default false). mode 'csharp': find and with are C# identifiers; every identifier token with that name in .cs files is renamed by syntax (strings and comments never). Same-named members of other types change too: check the preview and drop wrong lines with excludeJson.

Scope: pathGlob ('/*.cs', 'src/Orders/', '**' for everything) or pathsJson (exact files, e.g. from code_grep), exactly one of them. The access rules apply; vendored, minified, binary and files over 1 MB are left out and counted. A plan lasts 10 minutes and is used once. A wrong confirmCount or different arguments are refused and the plan stays usable; a planned file that changed after the preview is refused too, and that plan is used up: preview again. A preview whose scan was partial (too many files, too slow, over the limits) gives no planId: narrow the scope. WHEN TO USE: the same text or identifier changes in many places or files. For edits at known lines of one file use file_edit_lines; to create or rewrite whole files use file_write. RETURNS: preview - matches per file with marked lines and the planId; apply - replacements per 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": {
      "workspace": "<workspace>",
      "find": "<find>",
      "with": "<with>"
    },
    "name": "file_replace"
  }
}

Input Schema

NameRequiredDescriptionDefault
findYesText to find: one line, at most 200 characters. In mode 'csharp', an identifier.
modeNo'literal' (default) or 'csharp'
withYesReplacement: one line, at most 1000 characters; an empty string deletes the matches. In mode 'csharp', an identifier.
guideNotrue: put the files guide first in the result. Use on your first files call, or when told it changed.
planIdNoLeave out to preview. To apply: the planId the preview returned.
pathGlobNoFiles to search, relative to the workspace: '**/*.cs', 'src/Orders/**', '*.json', '**' for all. Give this or pathsJson.
pathsJsonNoJSON array of exact workspace-relative file paths, at most 200: ["src/A.cs","docs/a.md"]. Give this or pathGlob.
wholeWordNoLiteral mode: a match must not touch a letter, digit or '_' (default false).
workspaceYesWorkspace name as shown in Waymark (a single workspace; '*' is not accepted)
excludeJsonNoApply only: JSON array of matches to leave alone: "path" (the whole file) or "path#L12" (every match on line 12).
confirmCountNoApply only, required: the number of replacements after exclusions, as the preview counted them.
caseSensitiveNoLiteral mode: match letter case exactly (default true).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.2.1

TDQS

A4.6/5.0
Behavior4/5

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

Annotations already flag destructive/non-idempotent, and the description goes well beyond them: plan lifetime of 10 minutes, single use, refusal semantics for wrong confirmCount (plan survives) vs. stale planned file (plan is consumed), partial scans yielding no planId, and exclusions for vendored/minified/binary/>1 MB files. It also explains that only matched bytes change, preserving encoding, BOM and line endings. Minor gap: no statement about permissions or concurrency beyond the stale-file case.

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 the two-call model, then mode semantics, then scope, then failure rules — a logical order for an agent reading top-down. It is long and the trailing RETURNS line largely restates what the preview/apply paragraph already said, which is the main slack.

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 12-parameter destructive tool with no output schema, the description covers the full lifecycle: scanning scope, preview contents, apply gating via planId/confirmCount, exclusion handling, and what happens on each refusal path. An agent has enough to call it correctly on the first attempt without experimenting.

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 bar is what the prose adds on top. It does add real meaning: mode 'csharp' renames every matching identifier token in .cs files by syntax, never touching strings or comments, and also affects same-named members of other types — behavior not conveyed by the schema's one-line enum hint. It also clarifies confirmCount is the count after exclusions and that pathGlob/pathsJson are mutually exclusive.

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 (find and replace text across a workspace's files) and immediately frames the two-call preview/apply model. It explicitly distinguishes itself from file_edit_lines and file_write, so an agent can route without inspecting schemas.

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?

The WHEN TO USE block names the condition (same text or identifier changed in many places/files) and names both alternatives with their own conditions. The numbered PREVIEW/APPLY walkthrough gives explicit when-to-use for planId and confirmCount, and the 'exactly one of' scope rule is stated in prose as well as schema.

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