Skip to main content
Glama

edit_file

Destructive

Edit files with precise text replacements or unified diffs, preserving encoding and line endings. Supports dry-run for safe preview and similarity matching for whitespace drift.

Instructions

Edit one file with replacements or a unified diff. Returns a unified diff and keeps the file's encoding and line endings. PREFER THIS over read+write to modify a file. In 'ask before edits' mode call dryRun=true first, show the diff, then dryRun=false once the user confirms; with auto-edit permissions go straight to dryRun=false. On no match, prefer fixing oldText from the closest-content hint. Alternatively retry that edit with similarity (0.0-1.0) for whitespace/comment drift, not different code. Do NOT re-read the file afterwards to verify: a success with a diff means the edit is on disk, a failed edit changes nothing. Parameters: path; exactly one of edits [{oldText, newText, similarity?, replaceAll?}] or patch (---/+++/@@ unified diff for one file); dryRun (default false); encoding (auto). oldText must match ONE place: several matches fail with their line numbers and change nothing — add surrounding lines to pick one, or set replaceAll: true to change them all and report the count to the user. Edits apply in order. Matching ignores per-line leading/trailing whitespace and CRLF/LF, but interior spacing must match; newText is re-indented. Example: {"path": "D:\src\unit1.pas", "edits": [{"oldText": "i: Integer;", "newText": "i: NativeInt;"}, {"oldText": "for i := 0 to 10 do", "newText": "for i := 0 to 20 do"}], "dryRun": true}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
editsNo
patchNo
dryRunNo
encodingNo
forceWritableNo
Behavior5/5

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

Beyond the destructiveHint annotation, it reveals critical behavioral traits: returns a diff, preserves encoding and line endings, matching ignores whitespace/CRLF but requires interior spacing, and that a success with diff means the edit is on disk while failure changes nothing. It also details multi-match failure behavior and replaceAll semantics.

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?

Although long, every sentence provides necessary operational detail. It is front-loaded with purpose and usage priority, then flows logically through procedures, matching rules, and example. No filler or repetition that does not add value.

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?

With no output schema, the description clearly states the return is a unified diff. It covers expected behaviors for success, failure, dryRun, encoding, line endings, and edge cases like multiple matches. For a complex editing tool with 6 parameters, this description is exceptionally complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, and the description fully compensates. It explains each parameter: path, exactly one of edits or patch, dryRun default false, encoding auto, oldText matching constraints, replaceAll, similarity range, and provides a complete example. This is far beyond what the bare schema provides.

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 starts with a specific verb+resource: 'Edit one file with replacements or a unified diff.' It also distinguishes from siblings by explicitly stating 'PREFER THIS over read+write to modify a file,' making its purpose and differentiation crystal clear.

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 description gives explicit when-to-use and when-not-to-use guidance. It says to prefer this over read+write, details the dryRun workflow for 'ask before edits' mode, and explains when to use similarity vs fixing oldText. It also warns against re-reading the file after successful edits.

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/dimitar-grigorov/mcp-file-tools'

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