Skip to main content
Glama

write_file

Create or overwrite files with specified content for local development tasks, enabling direct file system access within configured project directories.

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 that executes the write_file tool: resolves the file path, creates the directory if necessary, writes the content to the file 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}`, }, ], }; }
  • index.js:61-78 (registration)
    Registration of the write_file tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.
    { 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)
    In the CallToolRequestSchema handler, the switch case that routes write_file calls to the writeFile method.
    case 'write_file': return await this.writeFile(args.path, args.content);
  • Input schema definition for the write_file tool, specifying path and content as required string properties.
    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'], },
  • Helper method used by writeFile to resolve relative file paths to absolute paths within the projects directory.
    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