Skip to main content
Glama
HenkDz

Self-Hosted Supabase MCP Server

list_storage_buckets

Retrieve and display all storage buckets within a self-hosted Supabase project. Enables developers to manage and inspect storage resources directly from their development environments.

Instructions

Lists all storage buckets in the project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The execute function that implements the core logic of listing storage buckets by executing a SQL query on the storage.buckets table using direct PostgreSQL connection, validating the response, and logging the results.
    execute: async ( input: Input, context: ToolContext ): Promise<ListStorageBucketsOutput> => { const client = context.selfhostedClient; // Use console.error for operational logging console.error('Listing storage buckets...'); // Check if direct DB connection is available, as it's likely needed for storage schema if (!client.isPgAvailable()) { // Log error for MCP client context.log('Direct database connection (DATABASE_URL) is required to list storage buckets.', 'error'); throw new Error('Direct database connection (DATABASE_URL) is required to list storage buckets.'); } const sql = ` SELECT id, name, owner, public, avif_autodetection, file_size_limit, allowed_mime_types, created_at::text, -- Cast to text updated_at::text -- Cast to text FROM storage.buckets; `; console.error('Attempting to list storage buckets using direct DB connection...'); const result = await client.executeSqlWithPg(sql); // Validate and return using handler const validatedBuckets = handleSqlResponse(result, ListStorageBucketsOutputSchema); console.error(`Found ${validatedBuckets.length} buckets.`); context.log(`Found ${validatedBuckets.length} buckets.`); // Also log for MCP return validatedBuckets; },
  • Zod schemas defining the structure of a StorageBucket and the array output for list_storage_buckets tool validation.
    const BucketSchema = z.object({ id: z.string(), name: z.string(), owner: z.string().nullable(), public: z.boolean(), avif_autodetection: z.boolean(), file_size_limit: z.number().nullable(), allowed_mime_types: z.array(z.string()).nullable(), // Keep timestamps as strings as returned by DB/pg created_at: z.string().nullable(), updated_at: z.string().nullable(), }); const ListStorageBucketsOutputSchema = z.array(BucketSchema); type ListStorageBucketsOutput = StorageBucket[];
  • src/index.ts:118-118 (registration)
    Registration of the listStorageBucketsTool in the availableTools object, which is used to build the MCP server's tool capabilities.
    [listStorageBucketsTool.name]: listStorageBucketsTool as AppTool,
  • Helper utility function that processes SQL execution results, checks for errors, validates against Zod schema, and returns typed data or throws detailed errors.
    export function handleSqlResponse<T>(result: SqlExecutionResult, schema: z.ZodSchema<T>): T { // Check if the result contains an error if ('error' in result) { throw new Error(`SQL Error (${result.error.code}): ${result.error.message}`); } // Validate the result against the schema try { return schema.parse(result); } catch (validationError) { if (validationError instanceof z.ZodError) { throw new Error(`Schema validation failed: ${validationError.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`); } throw new Error(`Unexpected validation error: ${validationError}`); } }
  • TypeScript interface defining the StorageBucket type used in the tool's output type definition.
    export interface StorageBucket { id: string; name: string; owner: string | null; public: boolean; avif_autodetection: boolean; file_size_limit: number | null; allowed_mime_types: string[] | null; created_at: string | null; // Timestamps returned as text from DB updated_at: string | null; }

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/HenkDz/selfhosted-supabase-mcp'

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