Skip to main content
Glama
martinbowling

Clipboard to Supabase MCP Helper

cleanup_old_files

Remove outdated files from Supabase Storage to free up space and maintain organized storage for clipboard-uploaded images.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the cleanup_old_files tool. It deletes files older than the specified number of retention days from the 'clips' folder in the Supabase storage bucket. Processes files in batches of 100 and returns counts of successful deletions and errors.
    export const cleanupOldFiles = asyncHandler(async (retentionDays: number = 30): Promise<{
      success: number;
      errors: number;
    }> => {
      if (retentionDays <= 0) {
        logger.info('Cleanup skipped - retention policy disabled (RETENTION_DAYS=0)');
        return { success: 0, errors: 0 };
      }
    
      logger.info(`Starting cleanup of files older than ${retentionDays} days in ${BUCKET}/clips`);
    
      // Calculate the cutoff date
      const cutoffDate = new Date();
      cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
      
      try {
        // List all objects in the clips folder
        const { data: files, error } = await supabase.storage
          .from(BUCKET)
          .list('clips');
        
        if (error) {
          throw new AppError(`Failed to list files in ${BUCKET}/clips: ${error.message}`, 'LIST_FILES_ERROR');
        }
        
        if (!files || !files.length) {
          logger.info(`No files found in ${BUCKET}/clips`);
          return { success: 0, errors: 0 };
        }
        
        logger.info(`Found ${files.length} files in ${BUCKET}/clips`);
        
        // Filter files older than the retention period
        const oldFiles = files.filter(file => {
          const fileDate = new Date(file.created_at);
          return fileDate < cutoffDate;
        });
        
        if (!oldFiles.length) {
          logger.info(`No files older than ${retentionDays} days found`);
          return { success: 0, errors: 0 };
        }
        
        logger.info(`Found ${oldFiles.length} files older than ${retentionDays} days to delete`);
        
        // Delete old files
        let successCount = 0;
        let errorCount = 0;
        
        // Process deletions in batches of 100 files
        const batchSize = 100;
        for (let i = 0; i < oldFiles.length; i += batchSize) {
          const batch = oldFiles.slice(i, i + batchSize);
          const filePaths = batch.map(file => `clips/${file.name}`);
          
          const { data, error } = await supabase.storage
            .from(BUCKET)
            .remove(filePaths);
          
          if (error) {
            logger.error(`Batch deletion error: ${error.message}`);
            errorCount += batch.length;
          } else {
            successCount += filePaths.length;
            logger.debug(`Deleted batch of ${filePaths.length} files`);
          }
        }
        
        logger.info(`Cleanup complete. Successfully deleted ${successCount} files. Failed to delete ${errorCount} files.`);
        return { success: successCount, errors: errorCount };
      } catch (error) {
        if (error instanceof AppError) {
          throw error;
        }
        
        throw new AppError(
          `Error during cleanup: ${error instanceof Error ? error.message : 'Unknown error'}`,
          'CLEANUP_ERROR'
        );
      }
    });
  • src/server.ts:55-93 (registration)
    Registers the 'cleanup_old_files' tool on the MCP stdio server, including input schema for 'days' parameter and wrapper handler that calls the core cleanupOldFiles function.
    server.tool(
      "cleanup_old_files",
      {
        type: "object",
        properties: {
          days: {
            type: "integer",
            description: "Number of days to keep files"
          }
        }
      },
      async ({ days }) => {
        try {
          // Use the configured retention period if no days parameter provided
          const retentionDays = days || parseInt(process.env.RETENTION_DAYS || '30', 10);
    
          logger.info(`MCP tool called: cleanup_old_files with retention period of ${retentionDays} days`);
    
          const result = await cleanupOldFiles(retentionDays);
    
          return {
            content: [
              {
                type: "text",
                text: `Cleanup completed: Deleted ${result.success} files older than ${retentionDays} days. Failed: ${result.errors}.`
              }
            ]
          };
        } catch (error) {
          const errorMessage = `Error cleaning up old files: ${error instanceof Error ? error.message : 'Unknown error'}`;
          logger.error(errorMessage);
          return {
            content: [
              { type: "text", text: `Error: Failed to cleanup old files` }
            ]
          };
        }
      }
    );
  • Registers the 'cleanup_old_files' tool on the MCP HTTP server, including input schema for 'days' parameter and wrapper handler that calls the core cleanupOldFiles function.
    server.tool(
      "cleanup_old_files",
      {
        type: "object",
        properties: {
          days: {
            type: "integer",
            description: "Number of days to keep files"
          }
        }
      },
      async ({ days }) => {
        try {
          // Use the configured retention period if no days parameter provided
          const retentionDays = days || parseInt(process.env.RETENTION_DAYS || '30', 10);
    
          logger.info(`MCP tool called: cleanup_old_files with retention period of ${retentionDays} days`);
    
          const result = await cleanupOldFiles(retentionDays);
    
          return {
            content: [
              {
                type: "text",
                text: `Cleanup completed: Deleted ${result.success} files older than ${retentionDays} days. Failed: ${result.errors}.`
              }
            ]
          };
        } catch (error) {
          const errorMessage = `Error cleaning up old files: ${error instanceof Error ? error.message : 'Unknown error'}`;
          logger.error(errorMessage);
          return {
            content: [
              { type: "text", text: `Error: Failed to cleanup old files` }
            ]
          };
        }
      }
    );
  • Input schema definition for the cleanup_old_files tool, specifying an optional 'days' integer parameter.
      type: "object",
      properties: {
        days: {
          type: "integer",
          description: "Number of days to keep files"
        }
      }
    },
    async ({ days }) => {
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/martinbowling/clipboard-to-supabase-mcp-helper'

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