Skip to main content
Glama

Write app file

write_file
Destructive

Create or edit a file in a space. Only app/ files are writable (Genesis app source code). IMPORTANT: Always read the file with inspect_space before editing. Edits to a stale view may fail or corrupt content. Commands:

  • "create" — Create a new file. Provide fileText with the full content.

  • "str_replace" — Replace a substring. Provide oldStr (must match exactly once in the file) and newStr.

  • "insert" — Insert text at a line number. Provide insertLine and fileText.

  • "str_diff_patch" — Apply a unified diff patch. Provide diffPatch.

  • "delete" — Delete an app file. No other fields are needed. Refused while any app source still imports the file, so remove or repoint those imports first. A deleted file can be brought back from the app's Version History. A successful write is COMMITTED, not staged: it redeploys and, on apps using the default automatic publish strategy, typically republishes to the live app on its own. Do not tell the user to publish afterwards, and do not report the change as pending - it is already on its way out.

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": {
      "spaceId": "<spaceId>",
      "path": "<path>",
      "command": "<command>"
    },
    "name": "write_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesFile path to write. Example: "app/src/App.tsx"
appIdNoApp ID. When omitted, resolves the default (first-created) app in the space.
newStrNoThe replacement string. Required for "str_replace".
oldStrNoThe exact string to find and replace. Required for "str_replace". Must appear exactly once in the file.
commandYesWrite operation. One of: create, str_replace, insert, str_diff_patch, delete.
spaceIdYesSpace ID
fileTextNoFile content. Required for "create" and "insert".
diffPatchNoUnified diff patch to apply. Required for "str_diff_patch".
insertLineNoLine number to insert before. Required for "insert".

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already flag destructiveHint=true and idempotentHint=false, and the description goes well beyond them: writes are committed not staged, trigger a redeploy, and typically republish to the live app automatically. It also documents the delete guard (refused while imports remain) and recoverability via Version History.

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?

Front-loads scope and the read-before-edit warning, then uses a compact command list. Some field-level requirements duplicate the schema's descriptions, but each line is tied to a distinct command, so the length is largely earned.

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 output schema, the description covers scope, preconditions, per-command requirements, failure modes, and post-write side effects (redeploy/republish) — including the explicit instruction not to report the change as pending. Nothing an agent needs to call it correctly is missing.

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?

Schema coverage is 100%, so parameters are already documented, yet the description adds the conditional requirements the schema does not express — which fields each command needs (fileText for create/insert, oldStr/newStr for str_replace, insertLine for insert, diffPatch for str_diff_patch). It also adds a constraint the schema only hints at: oldStr must match exactly once.

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 and resource ("Create or edit a file in a space") plus a hard scope constraint ("Only app/ files are writable (Genesis app source code)"). The command list enumerates the exact operations, so an agent knows precisely what the tool does without opening the schema.

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

Usage Guidelines4/5

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

Gives an explicit prerequisite ("Always read the file with `inspect_space` before editing") and explains the consequence of skipping it (stale-view edits may fail or corrupt content). It also routes among the five commands. It does not name non-file alternatives, but the workflow guidance is concrete and actionable.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.