delete_file
Remove files from storage systems using file keys or names to manage disk space and organize data.
Instructions
Delete a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The file key/name to delete |
Implementation Reference
- src/index.ts:200-222 (handler)MCP tool handler for 'delete_file': extracts key argument, logs the operation, calls storage.delete(key), and returns a JSON response with success status and message.case 'delete_file': { const { key } = args as { key: string }; logger.info('Tool request received', { operation: 'tool:delete', toolName: 'delete_file', key, requestId }); const deleted = await storage.delete(key, requestId); return { content: [{ type: 'text', text: JSON.stringify({ success: deleted, message: deleted ? `File '${key}' deleted successfully` : `File '${key}' not found`, key }, null, 2) }] }; }
- src/index.ts:140-149 (schema)Input schema definition for the 'delete_file' tool, specifying a required 'key' string parameter.inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'The file key/name to delete', }, }, required: ['key'], },
- src/index.ts:138-150 (registration)Registration of the 'delete_file' tool in the ListToolsRequestSchema response, including name, description, and input schema.name: 'delete_file', description: 'Delete a file', inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'The file key/name to delete', }, }, required: ['key'], }, },
- src/storage.ts:130-151 (helper)FileStorage.delete method: implements file deletion using fs.unlink with path sanitization, locking for concurrency, and proper error handling (returns false if not found).async delete(key: string, requestId: string): Promise<boolean> { const releaseLock = await this.acquireLock(key); const filePath = this.getFilePath(key); try { logger.debug('Deleting file', { operation: 'delete', key, filePath, requestId }); await fs.unlink(filePath); logger.info('File deleted successfully', { operation: 'delete', key, requestId }); return true; } catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') { logger.warn('File not found for deletion', { operation: 'delete', key, requestId }); return false; } logger.error('Failed to delete file', error as Error, { operation: 'delete', key, requestId }); throw error; } finally { releaseLock(); } }
- src/index-multimode.ts:209-231 (handler)Identical MCP tool handler for 'delete_file' in the multimode variant (supports HTTP), delegating to storage.delete.case 'delete_file': { const { key } = args as { key: string }; logger.info('Tool request received', { operation: 'tool:delete', toolName: 'delete_file', key, requestId }); const deleted = await storage.delete(key, requestId); return { content: [{ type: 'text', text: JSON.stringify({ success: deleted, message: deleted ? `File '${key}' deleted successfully` : `File '${key}' not found`, key }, null, 2) }] }; }