fs_append_file
Add content to the end of a file or create a new file if it doesn't exist, supporting various encoding formats for development workflows.
Instructions
Append content to an existing file. Creates the file if it doesn't exist.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute or relative path to the file | |
| content | Yes | Content to append to the file | |
| encoding | No | File encoding | utf8 |
Implementation Reference
- src/tools/filesystem.ts:142-172 (handler)Core handler function that appends content to a file using Node.js fs.appendFile, handles errors, and returns JSON response.export async function appendFile(args: z.infer<typeof appendFileSchema>): Promise<ToolResponse> { try { await fs.appendFile(args.path, args.content, args.encoding as BufferEncoding); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, path: args.path, bytesAppended: args.content.length }, null, 2) } ] }; } catch (error) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2) } ], isError: true }; } }
- src/tools/filesystem.ts:25-29 (schema)Zod input schema for validating tool arguments: path, content, encoding.export const appendFileSchema = z.object({ path: z.string().describe('Absolute or relative path to the file'), content: z.string().describe('Content to append to the file'), encoding: z.enum(['utf8', 'binary', 'base64']).default('utf8').describe('File encoding') });
- src/tools/filesystem.ts:504-527 (registration)MCP tool registration in filesystemTools array, defining name, description, and inputSchema for the MCP protocol.{ name: 'fs_append_file', description: 'Append content to an existing file. Creates the file if it doesn\'t exist.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Absolute or relative path to the file' }, content: { type: 'string', description: 'Content to append to the file' }, encoding: { type: 'string', enum: ['utf8', 'binary', 'base64'], default: 'utf8', description: 'File encoding' } }, required: ['path', 'content'] } },
- src/index.ts:313-315 (registration)Dispatch logic in main server CallToolRequestHandler that parses arguments and invokes the appendFile handler.if (name === 'fs_append_file') { const validated = appendFileSchema.parse(args); return await appendFile(validated);