Skip to main content
Glama

Enhanced Directory Context MCP Server

by PWalaGov

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

NameRequiredDescriptionDefault
backupNoCreate backup before deleting (.deleted extension)
pathYesFile 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

  • 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'], }, },
  • 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);
  • Usage of handleDeleteFile within batch_file_operations for delete operations (with backup disabled).
    result = await this.handleDeleteFile({ ...params, backup: false });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PWalaGov/File-Control-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server