Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down