Skip to main content
Glama
Amana03

Universal MCP Server

by Amana03

delete_file

Remove files from storage systems by specifying the file key or name to permanently delete them.

Instructions

Delete a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesThe file key/name to delete

Implementation Reference

  • MCP tool handler for 'delete_file': extracts the file key from arguments, logs the operation, delegates deletion to FileStorage.delete(), and returns a JSON response indicating success or if the file was not found.
    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)
        }]
      };
    }
  • Input schema definition for the 'delete_file' tool, specifying a required 'key' string parameter, provided in the ListTools response.
    {
      name: 'delete_file',
      description: 'Delete a file',
      inputSchema: {
        type: 'object',
        properties: {
          key: {
            type: 'string',
            description: 'The file key/name to delete',
          },
        },
        required: ['key'],
      },
    },
  • Core implementation of file deletion in FileStorage class: acquires a lock for concurrency safety, computes safe file path, uses fs.unlink to delete the file, handles not-found gracefully by returning false, with comprehensive logging.
    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.ts:116-167 (registration)
    Registration of all tools including 'delete_file' via the ListToolsRequestSchema handler, which returns the tool list with schemas.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'write_file',
            description: 'Write content to a file',
            inputSchema: {
              type: 'object',
              properties: {
                key: {
                  type: 'string',
                  description: 'The file key/name',
                },
                content: {
                  type: 'string',
                  description: 'The content to write',
                },
              },
              required: ['key', 'content'],
            },
          },
          {
            name: 'delete_file',
            description: 'Delete a file',
            inputSchema: {
              type: 'object',
              properties: {
                key: {
                  type: 'string',
                  description: 'The file key/name to delete',
                },
              },
              required: ['key'],
            },
          },
          {
            name: 'search_files',
            description: 'Search for files containing specific text',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'The text to search for',
                },
              },
              required: ['query'],
            },
          },
        ],
      };
    });
  • Identical MCP tool handler for 'delete_file' in the multi-mode server variant.
    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)
        }]
      };
    }
Install Server

Other Tools

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/Amana03/universal-mcp-server'

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