Skip to main content
Glama

edit_file

Safely replace exact text in remote files with unique-match validation, conflict detection, and base64-preserving writeback; ambiguous or stale edits fail instead of writing blindly.

Instructions

受控编辑远端文件:精确替换(唯一命中校验,all=true 全替换)+ TOCTOU 乐观锁(他人先写则拒绝)+ base64 保真写回(零 Shell 转义——绝不 sed -i)。未命中/多处命中/冲突均报错不盲写。返回 write_mode:atomic-replace=原子替换;inplace-write=保留 inode(bind mount 挂载点 mv 不可用降级)——非原子写入,中断可暴露半截。

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": "<old>",
      "new": "<new>"
    },
    "name": "edit_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
allNo多处命中全替换(缺省报错)
newYes
oldYes待替换片段(含足够上下文唯一)
pathYes
layerNo目标层名(缺省=默认层)
write_modeNoinplace=已知 bind mount 挂载环境显式请求保留 inode 写(跳过 mv 失败尝试)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior5/5

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

With no annotations, the description carries the full burden and does so well: it discloses TOCTOU optimistic locking, that no-match/multi-match/conflict all fail loudly instead of blind-writing, that writes are base64-fidelity with zero shell escaping, and that inplace-write is non-atomic and can expose half-written state on interruption. These are exactly the behavioral traits annotations would otherwise provide.

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?

Purpose and guarantees are front-loaded in a single dense paragraph, followed by the write_mode return semantics. Every clause carries information, though the nested parentheticals make it slightly hard to scan on first read.

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 six-parameter mutation tool with no annotations and no output schema, the description compensates by explaining the write_mode return values and the failure modes. It stops short of stating permissions/auth needs or what happens on a nonexistent path, which are the remaining gaps.

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?

At 67% schema coverage, the description adds real meaning: `all=true` means replace all occurrences vs error on multi-match, `old` must carry enough context to be unique, and `write_mode`/inplace maps to the bind-mount inode-preservation fallback. Only `layer` and `new` are left to the schema, which is acceptable.

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 states a specific verb and resource — controlled editing of a remote file via exact-string replacement — and names the mechanism (unique-match validation, base64 write-back). It implicitly separates itself from run_command by declaring '绝不 sed -i', so an agent can tell this is the structured edit path rather than shell text munging.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied rather than stated: the 'never sed -i' line steers agents away from run_command for edits, and 'all=true 全替换' hints at bulk replacement. However, there is no explicit when-to-use vs put_file (full-content write) and no stated prerequisites, so the agent must infer the boundary.

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