Skip to main content
Glama

write_file

DestructiveIdempotent

Writes files with encoding conversion from UTF-8, preserving original encoding, BOM, and line endings. Use after reading a non-UTF-8 file to save changes safely.

Instructions

Write file with encoding conversion from UTF-8. PREFER THIS over built-in Write for non-UTF-8 files. Use after read_text_file to keep the original encoding. Parameters: path, content, encoding (default: the existing file's detected encoding, else utf-8), bom, lineEndings, expectedHash (the contentHash of the read this rewrite is based on — the write fails and changes nothing if the file has since changed). bom: "auto" (default) writes a BOM for utf-16-/utf-32- targets, else keeps one only if the file already had a BOM of the same encoding; "preserve" keeps it even when the encoding changed; "never" strips it; "always" fails on encodings with no BOM (e.g. cp1251). lineEndings: "preserve" (default) converts content to the file's existing style, so sending LF into a CRLF file will NOT leave it mixed; also "crlf", "lf", "asis" (byte for byte). Example — strip a UTF-8 BOM that breaks PHP: {"path": "D:\www\index.php", "content": "<?php ...", "bom": "never"}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bomNo
pathYes
contentYes
encodingNo
lineEndingsNo
expectedHashNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hasBomYes
bomTypeNo
messageYes
contentHashNo
lineEndingsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv4.5.0
    • addedInput schema / properties / expectedHash
      Added value: +{
      +  "type": "string"
      +}
    • addedOutput schema / properties / contentHash
      Added value: +{
      +  "type": "string"
      +}
  2. Changed2 schema fields changedv3.3.0
    • addedInput schema / properties / lineEndings
      Added value: +{
      +  "type": "string"
      +}
    • addedOutput schema / properties / lineEndings
      Added value: +{
      +  "type": "string"
      +}
  3. Addedv0.1.1

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already declare destructive/idempotent/non-readOnly, and the description adds substantial beyond that: expectedHash concurrency guard that aborts the write if the file changed, BOM-mode behavior including failure on BOM-less encodings, and line-ending conversion semantics. This is rich behavioral disclosure of exactly the traits that matter for a destructive write.

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?

Dense but front-loaded with purpose and preference first, then parameters, then a concrete example. Every sentence earns its place, though the parameter block is long and could be marginally tightened; sizing is justified by six undocumented parameters.

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?

Output schema exists so return values need not be described, and annotations cover the safety profile. Given the six-parameter destructive write, the description supplies encoding defaults, BOM/line-ending edge cases, and the optimistic-concurrency guard — nothing essential for correct invocation is missing.

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%, so the description carries the full burden and does: it documents path, content, encoding (with default resolution logic), bom (all four modes and their effects), lineEndings (all four values with the LF-into-CRLF example), and expectedHash (tied to the read's contentHash). Nearly every parameter gets meaning beyond a bare type.

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+resource (write file) with its defining scope (encoding conversion from UTF-8), and explicitly contrasts with the built-in Write sibling. An agent can tell what this does and how it differs from generic write/edit tools without opening a schema.

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?

Explicitly says to PREFER this over built-in Write for non-UTF-8 files and to use it after read_text_file to preserve original encoding. Names both the when (non-UTF-8 rewrites) and the workflow alternative, leaving little to inference.

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