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
7 changes: 7 additions & 0 deletions src/filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
- `path` (string): File location
- `content` (string): File content

- **append_file**
- Append content to an existing file without overwriting previous content
- Inputs:
- `path` (string): File location
- `content` (string): Content to append
- Useful for adding content to log files or continuing content from previous operations

- **edit_file**
- Make selective edits using advanced pattern matching and formatting
- Features:
Expand Down
28 changes: 28 additions & 0 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const WriteFileArgsSchema = z.object({
content: z.string(),
});

const AppendFileArgsSchema = z.object({
path: z.string(),
content: z.string(),
});

const EditOperation = z.object({
oldText: z.string().describe('Text to search for - must match exactly'),
newText: z.string().describe('Text to replace with')
Expand Down Expand Up @@ -343,6 +348,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
"the contents of a single file. Only works within allowed directories.",
inputSchema: zodToJsonSchema(ReadFileArgsSchema) as ToolInput,
},
{
name: "append_file",
description:
"Append content to an existing file or create a new file if it doesn't exist. " +
"This is safer than overwriting when you need to add content incrementally. " +
"Preserves existing content and adds new content at the end of the file. " +
"Handles text content with proper encoding. Only works within allowed directories.",
inputSchema: zodToJsonSchema(AppendFileArgsSchema) as ToolInput,
},
{
name: "read_multiple_files",
description:
Expand All @@ -366,6 +380,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
description:
"Make line-based edits to a text file. Each edit replaces exact line sequences " +
"with new content. Returns a git-style diff showing the changes made. " +
"When modifying existing files, prefer using this tool for partial changes (adding/modifying/removing specific parts) " +
"rather than rewriting the entire or substantial portions of the file. " +
"Only works within allowed directories.",
inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput,
},
Expand Down Expand Up @@ -491,6 +507,18 @@ 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 "edit_file": {
const parsed = EditFileArgsSchema.safeParse(args);
if (!parsed.success) {
Expand Down