delete_file
Remove a specified file with optional backup (.deleted extension) using the Enhanced Directory Context MCP Server for efficient file management and cleanup tasks.
Instructions
Delete a file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| backup | No | Create backup before deleting (.deleted extension) | |
| path | Yes | File path relative to working directory |
Input Schema (JSON Schema)
{
"properties": {
"backup": {
"default": true,
"description": "Create backup before deleting (.deleted extension)",
"type": "boolean"
},
"path": {
"description": "File path relative to working directory",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- server.js:638-666 (handler)Core handler function for the 'delete_file' tool. Resolves the file path relative to working directory, checks existence, optionally creates a .deleted backup, deletes the file with fs.unlink, and returns success message with backup info.async handleDeleteFile(args) { const { path: filePath, backup = true } = args; const fullPath = path.resolve(this.workingDirectory, filePath); try { // Check if file exists await fs.access(fullPath); // Create backup if requested if (backup) { const backupPath = `${fullPath}.deleted`; await fs.copyFile(fullPath, backupPath); } // Delete file await fs.unlink(fullPath); return { content: [ { type: 'text', text: `File deleted: ${filePath}${backup ? '\nBackup created: ' + filePath + '.deleted' : ''}`, }, ], }; } catch (error) { throw new McpError(ErrorCode.InternalError, `Failed to delete file: ${error.message}`); } }
- server.js:276-294 (registration)Tool registration in the ListToolsRequestSchema response, defining name, description, and input schema.{ name: 'delete_file', description: 'Delete a file', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path relative to working directory', }, backup: { type: 'boolean', description: 'Create backup before deleting (.deleted extension)', default: true, }, }, required: ['path'], }, },
- server.js:482-483 (handler)Dispatch in the main CallToolRequestSchema handler that routes 'delete_file' tool calls to the specific handleDeleteFile method.case 'delete_file': return await this.handleDeleteFile(args);
- server.js:755-755 (helper)Usage of handleDeleteFile within batch_file_operations for delete operations (with backup disabled).result = await this.handleDeleteFile({ ...params, backup: false });