Skip to main content
Glama

write_file

Create or update files for revenue tracking and business management. Automatically creates backups and supports complex multi-location edits within 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
contentYesFile content to write
pathYesFull file path

Implementation Reference

  • index.js:577-594 (registration)
    Registration of the write_file tool in the ListTools response, including name, description, and input schema definition.
    { 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"] } },
  • Handler implementation for write_file tool. Validates path access, creates timestamped backup if file exists, writes new content using fs.writeFileSync, and returns success 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; }
  • Helper function used by write_file (and other FS tools) to validate if the target path is within allowed directories for security.
    function isPathAllowed(filePath) { const normalized = filePath.replace(/\//g, '\\'); return ALLOWED_PATHS.some(allowedPath => normalized.startsWith(allowedPath) ); }

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