Skip to main content
Glama
MrGNSS

Desktop Commander MCP

write_file

Replace entire file contents for significant edits or when incremental editing fails. Overwrites existing files within permitted directories.

Instructions

Completely replace file contents. Best for large changes (>20% of file) or when edit_block fails. Use with caution as it will overwrite existing files. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
contentYes

Implementation Reference

  • Core handler function that validates the file path security and writes the provided content to the file using Node.js fs.promises.writeFile.
    export async function writeFile(filePath: string, content: string): Promise<void> {
        const validPath = await validatePath(filePath);
        await fs.writeFile(validPath, content, "utf-8");
    }
  • Zod schema for validating the input arguments to the write_file tool: path (string) and content (string). Used in tool registration and dispatch.
    export const WriteFileArgsSchema = z.object({
      path: z.string(),
      content: z.string(),
    });
  • src/server.ts:142-148 (registration)
    Tool metadata registration in the ListTools response, including name, description, and input schema reference.
    {
      name: "write_file",
      description:
        "Completely replace file contents. Best for large changes (>20% of file) or when edit_block fails. " +
        "Use with caution as it will overwrite existing files. Only works within allowed directories.",
      inputSchema: zodToJsonSchema(WriteFileArgsSchema),
    },
  • Dispatch handler in the CallToolRequest that parses arguments with the schema and delegates to the core writeFile function.
    case "write_file": {
      const parsed = WriteFileArgsSchema.parse(args);
      await writeFile(parsed.path, parsed.content);
      return {
        content: [{ type: "text", text: `Successfully wrote to ${parsed.path}` }],
      };
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behavioral traits: it's destructive ('will overwrite existing files'), has constraints ('Only works within allowed directories'), and provides context on failure cases ('when edit_block fails'). However, it doesn't mention error handling, permissions, or rate limits, leaving some gaps.

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 appropriately sized and front-loaded, with every sentence earning its place. The first sentence states the core purpose, followed by usage guidelines, cautions, and constraints, all in a concise three-sentence structure with no wasted words.

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 (destructive file operation), lack of annotations, and no output schema, the description does a good job covering key aspects like purpose, usage, and constraints. However, it doesn't explain return values or error conditions, which would be helpful for a tool with no output schema.

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 has 0% description coverage, so the description must compensate. It implies the parameters (path and content) but doesn't explicitly explain their semantics beyond context. For example, it mentions 'allowed directories' which relates to path constraints, but doesn't detail format or validation. This adds some value but doesn't fully compensate for the schema gap.

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 clearly states the tool's purpose with specific verbs ('Completely replace file contents') and resource ('file'), distinguishing it from siblings like edit_block (for partial edits) and read_file (for reading). It explicitly mentions overwriting existing files, which clarifies its destructive nature.

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 description provides explicit guidance on when to use this tool ('Best for large changes (>20% of file) or when edit_block fails') and when not to use it (implied for small changes where edit_block is preferred). It also names an alternative (edit_block) and includes a cautionary note about overwriting files.

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/MrGNSS/ClaudeDesktopCommander'

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