Skip to main content
Glama
Desmond-Labs

Supabase Storage MCP

by Desmond-Labs

download_file

Download files from Supabase Storage buckets with optional image transformations like resizing and quality adjustment.

Instructions

Download file content directly with optional image transformations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYesSource bucket
file_pathYesFull file path in storage
return_formatNoFormat to return file contentbase64
transform_optionsNoOptional image transformation settings

Implementation Reference

  • The main handler function `handleDownloadFile` that executes the core logic: validates inputs, applies optional image transformations, downloads the file from Supabase Storage using `supabase.storage.download`, converts to base64 or binary, and returns structured result with auditing.
    async function handleDownloadFile(args: any, requestId: string, startTime: number) {
      const { bucket_name, file_path, return_format = 'base64', transform_options } = args;
      
      const inputHash = generateSecureHash(JSON.stringify({ bucket_name, file_path, return_format, transform_options }));
      
      try {
        // Input validation
        if (!bucket_name || typeof bucket_name !== 'string') {
          throw new Error('Invalid bucket_name parameter');
        }
        
        if (!file_path || typeof file_path !== 'string') {
          throw new Error('Invalid file_path parameter');
        }
        
        if (!['base64', 'binary'].includes(return_format)) {
          throw new Error('return_format must be either "base64" or "binary"');
        }
        
        // Prepare download options
        const downloadOptions: any = {};
        
        // Add transformation options if provided
        if (transform_options && typeof transform_options === 'object') {
          const { width, height, quality } = transform_options;
          
          if (width || height || quality) {
            downloadOptions.transform = {};
            if (width && typeof width === 'number' && width > 0) {
              downloadOptions.transform.width = width;
            }
            if (height && typeof height === 'number' && height > 0) {
              downloadOptions.transform.height = height;
            }
            if (quality && typeof quality === 'number' && quality > 0 && quality <= 100) {
              downloadOptions.transform.quality = quality;
            }
          }
        }
        
        // Download the file
        const { data, error } = await supabase.storage
          .from(bucket_name)
          .download(file_path, downloadOptions);
        
        if (error) {
          throw new Error(`Failed to download file: ${error.message}`);
        }
        
        if (!data) {
          throw new Error('No data received from download');
        }
        
        // Convert to buffer and then to requested format
        const buffer = await data.arrayBuffer();
        const fileBuffer = Buffer.from(buffer);
        
        let content: string;
        if (return_format === 'base64') {
          content = fileBuffer.toString('base64');
        } else {
          content = fileBuffer.toString('binary');
        }
        
        // Get file metadata
        const fileName = file_path.split('/').pop() || 'unknown';
        const contentType = data.type || 'application/octet-stream';
        
        auditRequest('download_file', true, inputHash);
        
        const result: DownloadFileResult = {
          success: true,
          file_path,
          file_name: fileName,
          content,
          content_type: contentType,
          file_size: fileBuffer.length,
          format: return_format,
          transformed: !!(transform_options && Object.keys(transform_options).length > 0),
          transform_options: transform_options || undefined,
          metadata: {
            last_modified: new Date().toISOString(),
            cache_control: 'no-cache'
          }
        };
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                ...result,
                request_id: requestId,
                processing_time: Date.now() - startTime
              }, null, 2)
            }
          ]
        };
      } catch (error) {
        auditRequest('download_file', false, inputHash, getErrorMessage(error));
        throw error;
      }
    }
  • src/index.ts:278-328 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining name, description, and detailed inputSchema with validation for bucket_name, file_path, return_format, and transform_options.
    name: 'download_file',
    description: 'Download file content directly with optional image transformations',
    inputSchema: {
      type: 'object',
      properties: {
        bucket_name: {
          type: 'string',
          description: 'Source bucket',
          minLength: 3,
          maxLength: 63
        },
        file_path: {
          type: 'string',
          description: 'Full file path in storage',
          maxLength: 1024
        },
        return_format: {
          type: 'string',
          description: 'Format to return file content',
          enum: ['base64', 'binary'],
          default: 'base64'
        },
        transform_options: {
          type: 'object',
          description: 'Optional image transformation settings',
          properties: {
            width: {
              type: 'number',
              description: 'Resize width in pixels',
              minimum: 1,
              maximum: 5000
            },
            height: {
              type: 'number',
              description: 'Resize height in pixels',
              minimum: 1,
              maximum: 5000
            },
            quality: {
              type: 'number',
              description: 'Image quality (1-100)',
              minimum: 1,
              maximum: 100
            }
          },
          additionalProperties: false
        }
      },
      required: ['bucket_name', 'file_path'],
      additionalProperties: false
    }
  • Type definition for the output/result of the download_file tool, used in the handler to type the result object.
    export interface DownloadFileResult {
      success: boolean;
      file_path: string;
      file_name: string;
      content: string; // base64 or binary data
      content_type: string;
      file_size: number;
      format: 'base64' | 'binary';
      transformed: boolean;
      transform_options?: {
        width?: number;
        height?: number;
        quality?: number;
      };
      metadata?: {
        last_modified: string;
        etag?: string;
        cache_control?: string;
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions 'optional image transformations' but doesn't disclose what happens if transformations fail, whether the download is destructive to the source, authentication requirements, rate limits, or error handling. For a download tool with zero annotation coverage, this is inadequate.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose ('download file content') and mentions a key feature ('optional image transformations'). There is no wasted verbiage or redundancy.

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

Completeness2/5

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

For a tool with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain return values (e.g., what 'base64' or 'binary' format entails), error conditions, or how transformations interact with non-image files. The lack of behavioral context makes it incomplete for safe and effective use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds marginal value by hinting at 'optional image transformations' which aligns with the 'transform_options' parameter, but doesn't provide additional context beyond what the schema already specifies. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('download file content') and resource ('file'), and mentions optional image transformations. However, it doesn't explicitly differentiate from sibling tools like 'download_file_with_auto_trigger' or 'get_file_url', which likely have overlapping functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'batch_download', 'download_file_with_auto_trigger', or 'get_file_url'. It mentions optional transformations but doesn't specify when they apply or any prerequisites for usage.

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/Desmond-Labs/supabase-storage-mcp'

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