Skip to main content
Glama

write_file

Write full file content atomically with crash-durable writes, automatic parent directory creation, and optimistic concurrency checks 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 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).
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).
Behavior5/5

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

No annotations are present, so the description carries full burden. It thoroughly discloses atomic temp+fsync+rename durability, automatic parent directory creation, LSP notification, optimistic concurrency guards, and error semantics (either fully written or untouched). This goes well beyond a simple 'writes a file' statement.

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 description is fairly long but front-loaded with the core purpose. It contains some redundancy (e.g., 'never partially written' appears twice, and the clobbering warning is repeated), but overall each sentence adds significant value for a complex tool with 8 parameters.

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?

Given the tool's complexity and absence of annotations/output schema, the description covers atomicity, crash durability, parent directory creation, LSP integration, concurrency guards, error handling, and the alternative edit_file. It omits the return value, but for a write operation this is minor compared to the behavioral detail provided.

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?

The input schema provides 100% coverage with detailed descriptions for every parameter. The description adds some context linking expected_mtime/expected_sha to read_file headers and explaining the concurrency rationale, but most parameter meaning is already in the schema, so baseline 3 is appropriate.

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?

Clearly states 'Create or overwrite a file with the given content' — a specific verb, resource, and scope. Differentiates from sibling edit_file by explicitly directing targeted edits to edit_file, and distinguishing from other file operations like delete/rename.

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 'Use edit_file for targeted edits to an existing file,' providing an alternative. Also explains when to use expected_mtime/expected_sha (from a read_file header) to avoid clobbering concurrent changes, and mentions dirty_ok/overwrite_changed for override scenarios.

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

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