Skip to main content
Glama
HenkDz

Self-Hosted Supabase MCP Server

list_tables

Retrieve all accessible tables from your self-hosted Supabase database, organized by schema, for efficient database introspection and management.

Instructions

Lists all accessible tables in the connected database, grouped by schema.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The execute handler function for the 'list_tables' tool. It constructs a SQL query to fetch accessible tables (excluding system and Supabase schemas), executes it using a fallback helper, and processes the response with output schema validation.
    execute: async (input: ListTablesInput, context: ToolContext) => { const client = context.selfhostedClient; // SQL query to get tables from pg_catalog and information_schema // Excludes system schemas like pg_catalog, information_schema, and Supabase internal schemas const listTablesSql = ` SELECT n.nspname as schema, c.relname as name, pgd.description as comment FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_catalog.pg_description pgd ON pgd.objoid = c.oid AND pgd.objsubid = 0 WHERE c.relkind = 'r' -- r = ordinary table AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND n.nspname NOT LIKE 'pg_temp_%' AND n.nspname NOT LIKE 'pg_toast_temp_%' -- Exclude Supabase internal schemas AND n.nspname NOT IN ('auth', 'storage', 'extensions', 'graphql', 'graphql_public', 'pgbouncer', 'realtime', 'supabase_functions', 'supabase_migrations', '_realtime') AND has_schema_privilege(n.oid, 'USAGE') AND has_table_privilege(c.oid, 'SELECT') ORDER BY n.nspname, c.relname `; const result = await executeSqlWithFallback(client, listTablesSql, true); return handleSqlResponse(result, ListTablesOutputSchema); // Use a helper to handle response/errors },
  • Zod schemas defining the input (empty object) and output (array of table objects with schema, name, and optional comment) for the list_tables tool.
    const ListTablesOutputSchema = z.array(z.object({ schema: z.string(), name: z.string(), comment: z.string().nullable().optional(), // Add comment if available })); // Define input type from schema const ListTablesInputSchema = z.object({ // No specific input needed for listing tables // Optional: add schema filter later if needed // schema: z.string().optional().describe('Filter tables by schema name.'), }); type ListTablesInput = z.infer<typeof ListTablesInputSchema>;
  • src/index.ts:100-100 (registration)
    The list_tables tool is registered in the availableTools map, which is used to configure the MCP server's tool capabilities.
    [listTablesTool.name]: listTablesTool as AppTool,
  • Static JSON Schema for MCP protocol input capabilities (empty object since no input params).
    const mcpInputSchema = { type: 'object', properties: {}, required: [], };

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