Skip to content

Commit 9512dc6

Browse files
committed
feat(filesystem): add append_file
1 parent eff333a commit 9512dc6

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/filesystem/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ const EditFileArgsSchema = z.object({
147147
dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format')
148148
});
149149

150+
const AppendFileArgsSchema = z.object({
151+
path: z.string(),
152+
content: z.string(),
153+
});
154+
150155
const CreateDirectoryArgsSchema = z.object({
151156
path: z.string(),
152157
});
@@ -548,6 +553,13 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
548553
"Only works within allowed directories.",
549554
inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput,
550555
},
556+
{
557+
name: "append_file",
558+
description:
559+
"Appends content to a file. If the file does not exist, it will be created. " +
560+
"Only works within allowed directories.",
561+
inputSchema: zodToJsonSchema(AppendFileArgsSchema) as ToolInput,
562+
},
551563
{
552564
name: "create_directory",
553565
description:
@@ -769,6 +781,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
769781
};
770782
}
771783

784+
case "append_file": {
785+
const parsed = AppendFileArgsSchema.safeParse(args);
786+
if (!parsed.success) {
787+
throw new Error(`Invalid arguments for append_file: ${parsed.error}`);
788+
}
789+
790+
const validPath = await validatePath(parsed.data.path);
791+
await fs.appendFile(validPath, parsed.data.content, "utf-8");
792+
return {
793+
content: [{ type: "text", text: `Successfully appended to ${parsed.data.path}` }],
794+
};
795+
}
796+
772797
case "create_directory": {
773798
const parsed = CreateDirectoryArgsSchema.safeParse(args);
774799
if (!parsed.success) {

0 commit comments

Comments
 (0)