generate_types
Generate TypeScript types from your Supabase database schema to ensure type safety in your applications.
Instructions
Generate TypeScript types for your Supabase database schema
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Database schema (optional, defaults to public) |
Implementation Reference
- src/index.ts:291-333 (handler)Executes the generate_types tool: validates input, checks for Supabase CLI, constructs and runs the 'supabase gen types' command with appropriate flags, returns generated TypeScript types.case "generate_types": { if (!isValidTypeGenArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, "Invalid type generation arguments" ); } const hasSupabaseCLI = await this.checkSupabaseCLI(); if (!hasSupabaseCLI) { throw new McpError( ErrorCode.InternalError, 'Supabase CLI not found. Please install it with: npm install -g supabase' ); } const { schema = 'public' } = request.params.arguments; let command = 'npx supabase gen types typescript'; if (this.projectRef) { command += ` --project-id "${this.projectRef}"`; } else { command += ' --local'; } command += ` --schema ${schema}`; try { const { stdout, stderr } = await execAsync(command); return { content: [ { type: "text", text: stdout || stderr || 'No types generated', }, ], }; } catch (error: any) { throw new McpError( ErrorCode.InternalError, `Failed to generate types: ${error.message}` ); } }
- src/index.ts:231-243 (registration)Registers the generate_types tool in the list of available tools, including name, description, and input schema.{ name: "generate_types", description: "Generate TypeScript types for your Supabase database schema", inputSchema: { type: "object", properties: { schema: { type: "string", description: "Database schema (optional, defaults to public)", } }, }, },
- src/index.ts:234-242 (schema)Defines the input schema for the generate_types tool, specifying an optional 'schema' string parameter.inputSchema: { type: "object", properties: { schema: { type: "string", description: "Database schema (optional, defaults to public)", } }, },
- src/index.ts:82-85 (helper)Type guard function to validate input arguments for generate_types tool.const isValidTypeGenArgs = (args: any): args is TypeGenArgs => typeof args === "object" && args !== null && (args.schema === undefined || typeof args.schema === "string");
- src/index.ts:51-53 (schema)TypeScript interface defining the expected arguments for generate_types.interface TypeGenArgs { schema?: string; }