Skip to main content
Glama

write_file

Write or update files for revenue tracking and business management, automatically creating backups for complex edits or new files in allowed directories.

Instructions

Write or update entire file. Creates backup automatically. Use for complex multi-location edits or new files. Only works in allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFull file path
contentYesFile content to write

Implementation Reference

  • Handler for the 'write_file' tool. Validates the path is in allowed directories, creates a timestamped backup if the file exists, writes the new content using fs.writeFileSync, and returns a success response with file details.
    case "write_file": {
      const { path, content } = args;
      
      if (!isPathAllowed(path)) {
        throw new Error(`Access denied: Path not in allowed directories`);
      }
    
      // Create backup if file exists
      if (fs.existsSync(path)) {
        const backupPath = `${path}.backup-${Date.now()}`;
        fs.copyFileSync(path, backupPath);
        debugLog(`Created backup: ${backupPath}`);
      }
    
      fs.writeFileSync(path, content, 'utf8');
      result = {
        success: true,
        path: path,
        bytesWritten: content.length,
        message: "File written successfully"
      };
      break;
  • index.js:577-594 (registration)
    Registration of the 'write_file' tool in the ListTools response, including name, description, and input schema requiring 'path' and 'content'.
    {
      name: "write_file",
      description: "Write or update entire file. Creates backup automatically. Use for complex multi-location edits or new files. Only works in allowed directories.",
      inputSchema: {
        type: "object",
        properties: {
          path: { 
            type: "string", 
            description: "Full file path" 
          },
          content: {
            type: "string",
            description: "File content to write"
          }
        },
        required: ["path", "content"]
      }
    },
  • Helper function used by write_file (and other FS tools) to validate if the file path is within the allowed directories defined in ALLOWED_PATHS.
    function isPathAllowed(filePath) {
      const normalized = filePath.replace(/\//g, '\\');
      return ALLOWED_PATHS.some(allowedPath => 
        normalized.startsWith(allowedPath)
      );
    }
  • Configuration array defining the allowed directories for file operations, used by isPathAllowed helper.
    const ALLOWED_PATHS = [
      'C:\\Users\\Node1\\revenue-engine-mcp',
      'C:\\Users\\Node1\\Documents\\revenue-engine\\mcp-server',
      'C:\\Users\\Node1\\Documents\\revenue-engine\\apps-script',
    ];
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: it writes or updates entire files, creates backups automatically, and has directory restrictions. However, it lacks details on error handling, permissions needed, or what happens if the file already exists, leaving some gaps for a mutation tool.

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 front-loaded with the core action ('write or update entire file') and uses three concise sentences that each add value: backup creation, usage context, and directory restrictions. There is no wasted text, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description covers basic behavior and constraints but lacks details on return values, error cases, or side effects. It is adequate given the simple schema but could be more complete for safe agent use.

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%, so the schema already documents both parameters ('path' and 'content'). The description adds no additional meaning about parameters beyond what the schema provides, such as format examples or constraints, meeting the baseline for high coverage.

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 verb 'write or update' and the resource 'entire file', distinguishing it from sibling tools like 'edit_file' (which might imply partial edits) and 'read_file'. It specifies the scope as 'entire file' and mentions automatic backup creation, making the purpose specific and differentiated.

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?

The description provides clear context for when to use this tool: 'for complex multi-location edits or new files' and 'only works in allowed directories'. However, it does not explicitly state when not to use it or name alternatives (e.g., 'edit_file' for partial edits), which prevents a perfect score.

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/PromptishOperations/mcpSpec'

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