Skip to main content
Glama

file_write

DestructiveIdempotent

Create, overwrite or copy files and scaffold whole folders with automatic parent creation. Write batches, duplicate or migrate code safely, then verify with a build.

Instructions

Create or overwrite one or more files. Each entry has its own mode:

  • create: fails if the file already exists (safe default for new files)

  • overwrite: fails if the file does NOT exist (explicit replacement)

  • upsert: create or overwrite unconditionally Parent folders are created automatically. An existing file keeps its encoding and line endings; new files are UTF-8. BATCH: pass several entries to scaffold a feature in one call. COPY, DO NOT RETYPE: an entry may carry "from" instead of content. The server copies a whole file or a line range of a file (any enabled workspace), so you write none of it. "from": { "workspace": "Legacy" (default: this workspace), "file": "Services/A.cs" (required), "startLine": 40, "endLine": 80 (leave both out for the whole file), "expectFirstLine" / "expectLastLine": (trimmed; the copy is refused if the lines moved), "replace": [{"find": "Invoice", "with": "Order", "count": 12}] (literal text, the match count must equal count), "csharp": {"namespaces": {"Old.Ns": "New.Ns"}, "identifiers": {"OldName": "NewName"}} (C# files only, by syntax; strings and comments are never touched; use replace for other languages), "indent": -4 (shift every line) }

A copied new file keeps the encoding and line endings of its source. Use it to duplicate, migrate or split files; use mode create so nothing is overwritten by accident. Copied text that holds a secret is refused. Run the build after a copy: the build is the proof. BULK (migrations): an entry {"fromFolder": {"workspace": "Legacy", "folder": "src/Billing", "toFolder": "src/Orders", "glob": "**/*.cs" (below folder, optional), "pathRename": [{"find": "Invoice", "with": "Order"}] (literal, on the path below folder), "replace" / "csharp" / "indent": as above, applied to every file, "mode": "create" (default), "confirmCount": 37}} copies every file of a folder tree (at most 500 per call). Blocked folders, links and refused files are left out. Always run it with dryRun=true first: it lists every file and the count; then repeat without dryRun and pass that count as confirmCount (a changed tree is refused). A file that fails (binary, a secret, an existing target) fails alone; the rest are copied. Keep the result as the migration record. dryRun=true runs every check and copy and reports what would happen without writing. WHEN TO USE: new files, full rewrites, copies and folder migrations. For targeted edits use file_edit_lines; for the same change across many files file_replace; to move or rename file_move. RETURNS: per-file success or error, line count, size in bytes, last-modified time and, for copies, where the text came from.

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>",
      "filesJson": "<filesJson>"
    },
    "name": "file_write"
  }
}

Input Schema

NameRequiredDescriptionDefault
guideNotrue: put the files guide first in the result. Use on your first files call, or when told it changed.
dryRunNotrue: check and report only, write nothing (default false)
filesJsonYesJSON array of entries, at most 50 (a fromFolder entry counts as one). Three shapes: write: { "relativeFilePath": "Services/OrderService.cs", "content": "<full file content>", "mode": "create|overwrite|upsert" } copy: { "relativeFilePath": "Services/OrderService.cs", "from": { "file": "Services/InvoiceService.cs", ... }, "mode": "create" } bulk: { "fromFolder": { "folder": "src/Billing", "toFolder": "src/Orders", "confirmCount": 37, ... } } The keys of from and fromFolder are listed in the tool description. mode defaults to upsert for write and copy, and to create for bulk.
workspaceYesWorkspace name as shown in Waymark (a single workspace; '*' is not accepted)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.2.2
    • changedInput schema / properties / filesJson / description
      Previous value: -"JSON array of files to write. Each entry:\n  { \"relativeFilePath\": \"Services/OrderService.cs\",\n    \"content\": \"<full file content>\",\n    \"mode\": \"create|overwrite|upsert\" }\nor, to copy instead of typing, replace content by \"from\": { ... } (see the tool description).\nmode defaults to upsert when omitted."New value: +"JSON array of entries, at most 50 (a fromFolder entry counts as one). Three shapes:\n  write: { \"relativeFilePath\": \"Services/OrderService.cs\", \"content\": \"<full file content>\", \"mode\": \"create|overwrite|upsert\" }\n  copy:  { \"relativeFilePath\": \"Services/OrderService.cs\", \"from\": { \"file\": \"Services/InvoiceService.cs\", ... }, \"mode\": \"create\" }\n  bulk:  { \"fromFolder\": { \"folder\": \"src/Billing\", \"toFolder\": \"src/Orders\", \"confirmCount\": 37, ... } }\nThe keys of from and fromFolder are listed in the tool description. mode defaults to upsert for write and copy, and to create for bulk."
  2. Addedv0.2.1

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already flag destructiveHint=true and idempotentHint=true, but the description adds substantial non-redundant behavior: parent folders are auto-created, existing files keep encoding/line endings while new files are UTF-8, secrets are refused, per-file failures are isolated, batch limits (50 entries, 500 files per call), and the dryRun/confirmCount guard against a changed tree. It explicitly states what is written versus merely reported, which is exactly what an agent needs before a destructive call.

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?

The purpose and modes are front-loaded and every section (BATCH, COPY, BULK, dryRun, WHEN TO USE, RETURNS) carries distinct information, so it earns its length for an inherently multi-modal tool. The nested-indentation formatting for the 'from' and 'fromFolder' objects is visually awkward and slows scanning, which keeps it from a perfect score.

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?

Covers everything an agent needs for a destructive, multi-mode write tool: mode semantics, encoding behavior, safety guards, limits, failure isolation, and a RETURNS block describing per-file results despite no output schema existing. Nothing required to invoke it correctly 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 100%, so the baseline would be 3, but the description goes well beyond it by documenting the nested keys of 'from' and 'fromFolder' (startLine/endLine, expectFirstLine/expectLastLine, replace, csharp namespaces/identifiers, indent, pathRename, glob, confirmCount) that the schema itself defers to the description. It also clarifies the default mode differs between write/copy and bulk, a semantic the schema states only tersely.

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?

Opens with a specific verb and resource: 'Create or overwrite one or more files.' It immediately breaks the operation into three explicit modes (create/overwrite/upsert) with their exact failure conditions, so the agent knows precisely what the tool does and how its modes differ. The sibling comparison section further isolates it from file_edit_lines, file_replace and file_move.

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 exact conditions (new files, full rewrites, copies, folder migrations) and routes the agent to the right alternative for each other case: file_edit_lines for targeted edits, file_replace for repeated changes, file_move for moves/renames. It also prescribes modality guidance, e.g. 'Use mode create so nothing is overwritten by accident' and the mandatory dryRun-then-confirmCount workflow for bulk.

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