Skip to main content
Glama

write_file

Create or overwrite a file atomically and crash-durably, auto-creating parent directories and notifying the IDE. Use expected mtime/SHA guards to prevent overwriting concurrent changes.

Instructions

Create or overwrite a file with the given content. The write is atomic and crash-durable (temp file fsynced, renamed, parent directory fsynced before the call returns — never partially written); parent directories are created automatically and the LSP server is notified so diagnostics and symbols update immediately. Pass expected_mtime or expected_sha (from a read_file header) to reject the write if the file changed since you read it, so a full-content overwrite never silently clobbers a concurrent change. If the call fails with a transport/connection error, the atomic temp+rename guarantees the file is either fully written or untouched — never partially written; re-read to confirm which side of the rename it landed on. Use edit_file for targeted edits to an existing file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentNoFull content to write to the file.
dirty_okNoAllow writing a file that has uncommitted changes in its git repository. Default false — the write is refused if the target file is dirty. Pass true to overwrite anyway.
file_pathNoAbsolute path, file:// URI, or workspace-relative path of the file to write.
create_dirsNoCreate parent directories if they do not exist. Default true.
expected_shaNoOptional. Hex-encoded SHA-256 previously returned by read_file. If provided, the write is rejected if the file's current content hash differs — stronger than expected_mtime, survives mtime aliasing.
expected_mtimeNoOptional. RFC3339Nano mtime previously returned by read_file. If provided, the write is rejected if the file's current mtime differs — fast optimistic-concurrency check, so a full-content overwrite never silently clobbers a change made since you read it.
await_diagnosticsNoWhen true, block up to a few seconds for the language server to finish re-analysing this file, and append a machine-readable 'diagnostics delta' line (fresh, new_errors, resolved, pre_existing). The block is always labelled — authoritative, pre-write snapshot, unverified, or not-analysed — so a stale result is never dressed as fresh. Default false (fast adaptive window; the result may predate the write).
overwrite_changedNoAllow overwriting a file that changed on disk since this session read it (a peer agent or human edited it after your read). Default false — the write is refused so a stale full-content overwrite cannot silently discard that change. Re-read to merge, or pass true to overwrite anyway. Only consulted when neither expected_mtime nor expected_sha is given (those guards take precedence).
fail_on_new_errorsNoWhen true (implies await_diagnostics), roll this write back if the language server CONFIRMS it introduced new errors here, leaving the file byte-for-byte unchanged and returning the delta as the error. An unconfirmed check never rolls back; nor do warnings, pre-existing errors, or breakage elsewhere. Not over 1 MiB. Default false.

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. Changed2 schema fields changedv0.17.0
    • changedInput schema / properties / await_diagnostics / description
      Previous value: -"When true, block up to a few seconds for the language server to finish re-analysing this file and report an authoritative post-write result — a clean fresh pass is stated explicitly. Use it for a trustworthy \"did my change compile?\" answer instead of shelling out to a build. Default false (fast adaptive window; the result may predate the write)."New value: +"When true, block up to a few seconds for the language server to finish re-analysing this file, and append a machine-readable 'diagnostics delta' line (fresh, new_errors, resolved, pre_existing). The block is always labelled — authoritative, pre-write snapshot, unverified, or not-analysed — so a stale result is never dressed as fresh. Default false (fast adaptive window; the result may predate the write)."
    • addedInput schema / properties / fail_on_new_errors
      Added value: +{
      +  "description": "When true (implies await_diagnostics), roll this write back if the language server CONFIRMS it introduced new errors here, leaving the file byte-for-byte unchanged and returning the delta as the error. An unconfirmed check never rolls back; nor do warnings, pre-existing errors, or breakage elsewhere. Not over 1 MiB. Default false.",
      +  "type": "boolean"
      +}
  2. First observedv0.16.6

TDQS

A4.9/5.0
Behavior5/5

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

With no annotations provided, the description carries the full burden and does so thoroughly: it discloses atomic temp-file-plus-rename behavior, fsync guarantees, automatic parent-directory creation, LSP notification, and the no-partial-write outcome even on transport errors. It also explains the conditional rollback-ish protections against stale reads. This significantly exceeds what the raw name and schema alone would convey.

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?

The description is dense but organized: primary action first, then safety guarantees, concurrency controls, failure semantics, and an alternative-tool pointer. It front-loads the most important decision-relevant information and avoids irrelevant filler. Any redundancy in reinforcing 'never partially written' is purposeful in the context of failure handling.

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?

For a 9-parameter mutation tool with no annotations and no output schema, this description is unusually complete. It explains the critical runtime behaviors an agent must reason about: atomicity, durability, read-check guards, transport failure outcomes, and diagnostic update side effects. An agent can safely invoke this tool with appropriate expectations of behavior and consequences.

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?

The schema already covers 100% of parameters with descriptive text, so the baseline is 3. The description adds valuable meaning beyond the schema by explaining expected_mtime/expected_sha as concurrency guards tied to a prior read_file, and by framing atomicity, overwrite protection, and directory creation as behaviors. It does not walk through every parameter, but the schema does that job.

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 opens with a clear, specific verb and resource: 'Create or overwrite a file with the given content.' It distinguishes write_file from the sibling edit_file by explicitly directing targeted-edits use cases to edit_file, and it establishes full-content write as the core responsibility.

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 last sentence gives an explicit routing rule: use edit_file for targeted edits instead. It also describes exactly when to pass expected_mtime/expected_sha/overwrite_changed, showing when to refuse a write to avoid clobbering concurrent changes. This gives clear selection context among file-related siblings.

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

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/plumbkit/plumb'

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