From 9512dc6bfeeb89f825f8c16358a2d932ecbffae1 Mon Sep 17 00:00:00 2001 From: Vinicius Altrao Date: Thu, 12 Jun 2025 18:08:14 +0200 Subject: [PATCH 1/2] feat(filesystem): add append_file --- src/filesystem/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 6723f43600..3cd764b1b4 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -147,6 +147,11 @@ const EditFileArgsSchema = z.object({ dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') }); +const AppendFileArgsSchema = z.object({ + path: z.string(), + content: z.string(), +}); + const CreateDirectoryArgsSchema = z.object({ path: z.string(), }); @@ -548,6 +553,13 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { "Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, }, + { + name: "append_file", + description: + "Appends content to a file. If the file does not exist, it will be created. " + + "Only works within allowed directories.", + inputSchema: zodToJsonSchema(AppendFileArgsSchema) as ToolInput, + }, { name: "create_directory", description: @@ -769,6 +781,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { }; } + case "append_file": { + const parsed = AppendFileArgsSchema.safeParse(args); + if (!parsed.success) { + throw new Error(`Invalid arguments for append_file: ${parsed.error}`); + } + + const validPath = await validatePath(parsed.data.path); + await fs.appendFile(validPath, parsed.data.content, "utf-8"); + return { + content: [{ type: "text", text: `Successfully appended to ${parsed.data.path}` }], + }; + } + case "create_directory": { const parsed = CreateDirectoryArgsSchema.safeParse(args); if (!parsed.success) { From 6c93529435a91708737804ee3d030257aa7a2f08 Mon Sep 17 00:00:00 2001 From: Vinicius Altrao Date: Thu, 12 Jun 2025 18:31:02 +0200 Subject: [PATCH 2/2] update README --- src/filesystem/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/filesystem/README.md b/src/filesystem/README.md index ac63f39a5f..838182ce8f 100644 --- a/src/filesystem/README.md +++ b/src/filesystem/README.md @@ -113,6 +113,15 @@ The server's directory access control follows this flow: - Returns detailed diff and match information for dry runs, otherwise applies changes - Best Practice: Always use dryRun first to preview changes before applying them +- **append_file** + - Append content to existing file or create new file if it doesn't exist + - Inputs: + - `path` (string): File location + - `content` (string): Content to append + - Features: + - Creates file if it doesn't exist + - Appends content to the end of the file + - **create_directory** - Create new directory or ensure it exists - Input: `path` (string)