write_file
Create or update files by writing content to specified paths in the filesystem.
Instructions
Create new file or overwrite existing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file to write | |
| content | Yes | Content to write to the file |
Implementation Reference
- src/index.ts:280-299 (handler)Handler for the 'write_file' tool. Extracts path and content from arguments, validates the path, ensures the parent directory exists, writes the file using fs.writeFile, and returns a success message.case 'write_file': { const { path: filePath, content } = request.params.arguments as { path: string; content: string }; validatePath(filePath); // Ensure parent directory exists await fs.ensureDir(path.dirname(filePath)); await fs.writeFile(filePath, content, 'utf8'); return { content: [ { type: 'text', text: `File written successfully: ${filePath}`, }, ], }; }
- src/index.ts:127-143 (registration)Registers the 'write_file' tool in the ListTools response, including name, description, and input schema definition.name: 'write_file', description: 'Create new file or overwrite existing', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file to write', }, content: { type: 'string', description: 'Content to write to the file', }, }, required: ['path', 'content'], }, },