@@ -119,6 +119,11 @@ const EditFileArgsSchema = z.object({
119119 dryRun : z . boolean ( ) . default ( false ) . describe ( 'Preview changes using git-style diff format' )
120120} ) ;
121121
122+ const AppendFileArgsSchema = z . object ( {
123+ path : z . string ( ) ,
124+ content : z . string ( ) ,
125+ } ) ;
126+
122127const CreateDirectoryArgsSchema = z . object ( {
123128 path : z . string ( ) ,
124129} ) ;
@@ -369,6 +374,13 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
369374 "Only works within allowed directories." ,
370375 inputSchema : zodToJsonSchema ( EditFileArgsSchema ) as ToolInput ,
371376 } ,
377+ {
378+ name : "append_file" ,
379+ description :
380+ "Appends content to a file. If the file does not exist, it will be created. " +
381+ "Only works within allowed directories." ,
382+ inputSchema : zodToJsonSchema ( AppendFileArgsSchema ) as ToolInput ,
383+ } ,
372384 {
373385 name : "create_directory" ,
374386 description :
@@ -503,6 +515,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
503515 } ;
504516 }
505517
518+ case "append_file" : {
519+ const parsed = AppendFileArgsSchema . safeParse ( args ) ;
520+ if ( ! parsed . success ) {
521+ throw new Error ( `Invalid arguments for append_file: ${ parsed . error } ` ) ;
522+ }
523+
524+ const validPath = await validatePath ( parsed . data . path ) ;
525+ await fs . appendFile ( validPath , parsed . data . content , "utf-8" ) ;
526+ return {
527+ content : [ { type : "text" , text : `Successfully appended to ${ parsed . data . path } ` } ] ,
528+ } ;
529+ }
530+
506531 case "create_directory" : {
507532 const parsed = CreateDirectoryArgsSchema . safeParse ( args ) ;
508533 if ( ! parsed . success ) {
0 commit comments