fast_write_file
Write or modify files with automatic directory creation, append mode, and emoji handling options for reliable file system operations.
Instructions
Writes or modifies a file (provides emoji guidelines)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path | |
| content | Yes | File content | |
| encoding | No | Text encoding | utf-8 |
| create_dirs | No | Automatically create directories | |
| append | No | Append mode | |
| force_remove_emojis | No | Force remove emojis (default: false) |
Implementation Reference
- api/server.ts:482-520 (handler)Implements the core logic for the fast_write_file tool: resolves and validates the path, optionally creates parent directories, writes or appends the content to the file, and returns success information with file stats.async function handleWriteFile(args: any) { const { path: filePath, content, encoding = 'utf-8', create_dirs = true, append = false } = args; let targetPath: string; if (path.isAbsolute(filePath)) { targetPath = filePath; } else { targetPath = path.join(process.cwd(), filePath); } if (!isPathAllowed(targetPath)) { throw new Error(`Access denied to path: ${targetPath}`); } const resolvedPath = path.resolve(targetPath); if (create_dirs) { const dir = path.dirname(resolvedPath); await fs.mkdir(dir, { recursive: true }); } if (append) { await fs.appendFile(resolvedPath, content, encoding as BufferEncoding); } else { await fs.writeFile(resolvedPath, content, encoding as BufferEncoding); } const stats = await fs.stat(resolvedPath); return { message: `File ${append ? 'appended' : 'written'} successfully`, path: resolvedPath, size: stats.size, size_readable: formatSize(stats.size), encoding: encoding, mode: append ? 'append' : 'write', timestamp: new Date().toISOString() }; }
- api/server.ts:123-137 (schema)Defines the input schema for the fast_write_file tool, specifying parameters like path, content, encoding, create_dirs, and append with their types and descriptions.{ name: 'fast_write_file', description: '파일을 쓰거나 수정합니다', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '파일 경로' }, content: { type: 'string', description: '파일 내용' }, encoding: { type: 'string', description: '텍스트 인코딩', default: 'utf-8' }, create_dirs: { type: 'boolean', description: '디렉토리 자동 생성', default: true }, append: { type: 'boolean', description: '추가 모드', default: false } }, required: ['path', 'content'] } },
- api/server.ts:326-328 (registration)Registers the fast_write_file tool handler in the main tools/call switch statement, dispatching calls to the handleWriteFile function.case 'fast_write_file': result = await handleWriteFile(args); break;