Skip to main content
Glama

write_file

Create or overwrite files with specified content to manage project files directly from Claude Desktop, enabling file operations within your local development environment.

Instructions

Create or overwrite a file with new content. Use this to create new files or completely replace existing ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file (relative to projects directory or absolute)
contentYesContent to write to the file

Implementation Reference

  • The main handler function for the 'write_file' tool. It resolves the file path, ensures the directory exists, writes the content using fs.writeFile, and returns a success message.
    async writeFile(filePath, content) { const resolvedPath = this.resolvePath(filePath); const dir = path.dirname(resolvedPath); await fs.mkdir(dir, { recursive: true }); await fs.writeFile(resolvedPath, content, 'utf-8'); return { content: [ { type: 'text', text: `File written successfully: ${resolvedPath}`, }, ], }; }
  • The input schema definition for the 'write_file' tool, registered in the ListTools response.
    name: 'write_file', description: 'Create or overwrite a file with new content. Use this to create new files or completely replace existing ones.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file (relative to projects directory or absolute)', }, content: { type: 'string', description: 'Content to write to the file', }, }, required: ['path', 'content'], }, },
  • index.js:166-167 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes 'write_file' calls to the writeFile method.
    case 'write_file': return await this.writeFile(args.path, args.content);
  • Helper method to resolve relative file paths to absolute paths based on the PROJECTS_DIR.
    resolvePath(inputPath) { if (!inputPath || inputPath === '.') { return PROJECTS_DIR; } if (path.isAbsolute(inputPath)) { return inputPath; } return path.join(PROJECTS_DIR, inputPath); }

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/talentedmrweb/local-dev-bridge-mcp'

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