Skip to main content
Glama

edit_file

Replace a specific, unique string in a file to modify its content while maintaining file structure and updating its cached summary.

Instructions

Edit a file by replacing a specific string. The file becomes (or remains) the active file.

The old_string must:

  • Match exactly, including whitespace and indentation

  • Appear exactly once in the file (for safety)

After editing, the file's cached summary is updated.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to edit
old_stringYesThe exact string to replace (must be unique in the file)
new_stringYesThe string to replace it with
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing: 1) mutation behavior (editing changes file content), 2) safety constraints (exact match, uniqueness requirement), 3) side effects (file becomes/remains active, cached summary updated). It doesn't mention error handling or permissions, keeping it from a perfect score.

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?

Four concise sentences with zero waste. First sentence states core purpose, second explains file state change, next two detail old_string constraints, final sentence describes caching update. Every sentence earns its place with essential information.

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 a mutation tool with no annotations and no output schema, the description does well by explaining the edit operation, safety constraints, and side effects. It could be more complete by mentioning what happens on failure (e.g., if old_string isn't found) or the format of any return value, but covers the essential behavioral context.

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 description coverage is 100%, so the baseline is 3. The description adds some semantic context about old_string requirements (exact match including whitespace, must be unique), but doesn't provide additional meaning for path or new_string beyond what the schema already documents.

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 clearly states the specific action ('Edit a file by replacing a specific string') and distinguishes it from siblings like write_file (which likely creates/writes entire files) and read_file/peek_file (which are read-only). It also mentions the file becomes/remains active, adding operational context.

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?

The description implies usage for targeted string replacement rather than full-file writes (contrasting with write_file), but doesn't explicitly state when NOT to use it or name alternatives. The safety constraints (exact match, unique occurrence) provide some contextual guidance for when this tool is appropriate.

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/UBTCodeNinja/mcp-file-compaction'

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