Skip to main content
Glama

Write file

write_file
Destructive

Write a file into the sandbox (creates missing parent directories, overwrites an existing file); returns the path and the number of bytes written. Use it to put source code, configuration or data in place before running it; set base64=true for binary content. For a one-off script you only want to execute, running the code directly is shorter; files and directories are removed with the delete tool.

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

Input Schema

NameRequiredDescriptionDefault
pathYesAbsolute path, e.g. /home/user/app/main.py
base64NoContent is base64 (for binary files)
contentYesFile content (text, or base64 when base64=true)
sandbox_idNoSandbox ID (sb_…). If omitted, the current sandbox of this session is used. A sandbox_id you pass becomes the current sandbox for later calls without sandbox_id.

Output Schema

NameRequiredDescriptionDefault
pathYesPath of the written file.
bytesYesNumber of bytes written.
sandbox_idYesSandbox ID.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / sandbox_id / description
      Previous value: -"Sandbox ID (sb_…). If omitted, the current sandbox of this session is used."New value: +"Sandbox ID (sb_…). If omitted, the current sandbox of this session is used. A sandbox_id you pass becomes the current sandbox for later calls without sandbox_id."
  2. First observed

TDQS

A4.3/5.0
Behavior4/5

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

Goes beyond the annotations (destructiveHint=true, readOnlyHint=false) by disclosing exactly what is destructive: existing files are overwritten and missing parent directories are created. It also states the base64 flag for binary payloads. It stops short of disclosure about size limits, error behavior, or permission requirements, which would matter for a write tool.

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?

Two dense sentences, front-loaded with the core action and its return values, then usage routing. The parenthetical packing of parent-directory creation and overwrite into the first sentence is efficient but slightly compressed; no sentence is wasted.

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?

With annotations, a complete 4-parameter schema, and an output schema covering return values, the description supplies what structured fields cannot: overwrite semantics, directory creation, and alternatives. Minor gaps (failure modes, whether paths outside the sandbox are rejected) remain but are acceptable given the schema richness.

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?

Schema description coverage is 100%, including the non-obvious sandbox_id side effect (a passed sandbox_id becomes the current sandbox), so the schema is already doing the heavy lifting. The description only reinforces base64=true for binary content and adds no syntax or format detail beyond the schema. Baseline 3 applies.

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 concrete verb and resource ("Write a file into the sandbox") plus its side effects (creates missing parent directories, overwrites existing file) and return values. This clearly distinguishes it from run_code (execute without persisting) and delete_path's inverse operation.

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?

Gives explicit when-to-use guidance (put source code, configuration or data in place before running it) and explicit when-not-to-use guidance: for a one-off script you only want to execute, running the code directly is shorter. It also routes cleanup to the delete tool, so the agent knows this tool is not the removal path.

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.

Resources