@@ -2,13 +2,13 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22import { McpAgent } from 'agents/mcp'
33import { z } from 'zod'
44
5+ import { Env , Props } from '.'
56import { OPEN_CONTAINER_PORT } from '../shared/consts'
6- import { ExecParams , FileList , FilesWrite } from '../shared/schema'
7+ import { ExecParams , FileList , FilePathParam , FilesWrite } from '../shared/schema'
78import { MAX_CONTAINERS , proxyFetch , startAndWaitForPort } from './containerHelpers'
89import { getContainerManager } from './containerManager'
910import { BASE_INSTRUCTIONS } from './prompts'
1011import { fileToBase64 } from './utils'
11- import { Env , Props } from '.'
1212
1313export class ContainerMcpAgent extends McpAgent < Env , Props > {
1414 server = new McpServer (
@@ -70,7 +70,21 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
7070 }
7171 }
7272 )
73+ //COURT: At some point we should split the tools into separate files
74+ this . server . tool (
75+ 'container_file_delete' ,
76+ 'Delete file and its contents' ,
77+ { args : FilePathParam } ,
78+ async ( { args } ) => {
79+ const deleted = await this . container_file_delete ( args )
80+ return {
81+ content : [ { type : 'text' , text : `File deleted: ${ deleted } .` } ]
82+ }
83+ }
84+
85+ )
7386 this . server . tool (
87+ //TODO: make this file to be consistent with others
7488 'container_files_write' ,
7589 'Write file contents' ,
7690 { args : FilesWrite } ,
@@ -229,11 +243,21 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
229243 return json
230244 }
231245
246+ //TODO: Abstract these
247+ async container_file_delete ( filePath : string ) : Promise < boolean > {
248+ const res = await proxyFetch (
249+ this . env . ENVIRONMENT ,
250+ this . ctx . container ,
251+ new Request ( `http://host:${ OPEN_CONTAINER_PORT } /files/contents/${ filePath } ` , {
252+ method : 'DELETE'
253+ } ) ,
254+ OPEN_CONTAINER_PORT
255+ )
256+ return res . ok
257+ }
232258 async container_files_read (
233259 filePath : string
234260 ) : Promise < { blob : Blob ; mimeType : string | undefined } > {
235- console . log ( 'reading' )
236- console . log ( filePath )
237261 const res = await proxyFetch (
238262 this . env . ENVIRONMENT ,
239263 this . ctx . container ,
@@ -269,7 +293,6 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
269293 if ( ! res || ! res . ok ) {
270294 throw new Error ( `Request to container failed: ${ await res . text ( ) } ` )
271295 }
272- const txt = await res . text ( )
273296 return `Wrote file: ${ file . path } `
274297 }
275298}
0 commit comments