What You'll Build
A security audit workflow that uses Continue CLI with Supabase MCP to identify RLS vulnerabilities, generate secure policies, fix permission issues, and ensure your database follows security best practices.
What You’ll Learn
This cookbook teaches you to:- Use Supabase MCP to audit database security
- Identify tables without Row Level Security (RLS) enabled
- Find and fix overly permissive or missing RLS policies
- Generate secure RLS migrations following best practices
- Automate security audits with GitHub Actions
Prerequisites
Before starting, ensure you have:- Supabase account with an active project
- Node.js 18+ installed locally
- Continue CLI with active credits (required for API usage)
- Basic understanding of SQL and database concepts
1
Install Continue CLI
2
Set up Continue CLI Account & API Key
- Visit Continue Organizations
- Sign up or log in to your Continue account
- Navigate to your organization settings
- Click “API Keys” and then ”+ New API Key”
- Copy the API key immediately (you won’t see it again!)
- Login to the CLI:
cn login
Continue CLI can analyze your database schema and generate complex SQL queries - you just need to describe what you want in plain language!
Step 1: Set Up Your Credentials
First, you’ll need to set up access to your Supabase project.- Configure Supabase MCP
- Supabase Project Setup
Security First: Follow Supabase’s security best practices when using MCP:
- Never connect to production databases directly
- Use development or staging environments
- Enable read-only mode when possible
- Scope MCP access to specific projects
The MCP server can be scoped to a specific project for better security. Configure this during setup.
Supabase Database Workflow Options
Fastest Path to Success
Skip the manual setup and use our pre-built Supabase Continuous AI agent that includes
optimized prompts, rules, and the Supabase MCP for intelligent database management.
How Supabase MCP Works:
- Connects to your Supabase project via OAuth
- Provides tools for database queries, schema inspection, and migrations
- Supports read-only mode for safer operations
- Can be scoped to specific projects for security
- ⚡ Quick Start (Recommended)
- 🛠️ Manual Setup
Perfect for: Immediate database analysis with AI-powered query optimization and schema insights
1
Add the Pre-Built Agent
Visit the Supabase Continuous AI Agent on Continue Hub and click “Install Agent” or run:This agent includes:
- Optimized prompts for database analysis and query generation
- Built-in rules for SQL best practices and security
- Supabase MCP for secure database access
- Automatic authentication via OAuth flow
2
Run Database Analysis
Navigate to your project directory and enter this prompt in the Continue CLI TUI:That’s it! The agent handles everything automatically.
Why Use the Agent? Get consistent results with pre-tested prompts and built-in SQL optimization rules.
Agent Requirements
Agent Requirements
To use the pre-built agent, you need either:
- Continue CLI Pro Plan with the models add-on, OR
- Your own API keys added to Continue Hub secrets
- Supabase account with at least one project
- OAuth authentication (handled automatically)
- Development or staging environment (not production)
Security Best Practices:
- Never use MCP with production databases - Always use development or staging environments
- Enable read-only mode when analyzing data to prevent accidental modifications
- Scope to specific projects to limit access
- Use branch databases for testing schema changes
Step 2: Analyze Your Database with AI
Use Continue CLI to perform intelligent database analysis. Enter these prompts in the Continue CLI TUI:- Schema Analysis
- RLS Security Audit
- Fix RLS Policies
Prompt:
Available Supabase MCP Capabilities:
- Database Queries: Execute SQL queries and analyze results
- Schema Inspection: View table structures, relationships, and constraints
- Performance Analysis: Identify slow queries and optimization opportunities
- Security Review: Check RLS policies and access controls
- Migration Generation: Create SQL migrations for schema changes
Step 3: Generate Database Migrations
Create and apply database migrations based on AI recommendations. Enter this prompt in the Continue CLI TUI: Example: Complete RLS Security Fix- Enables RLS on all tables
- Creates secure, well-documented policies
- Follows Supabase security best practices
- Includes rollback capabilities
- Provides a security summary for your team
Best Practice: Always review AI-generated migrations before applying them. Test in a development branch first using Supabase’s branching feature.
Step 4: Set Up Automated Database Monitoring
Automate database health checks with Continue CLI and GitHub Actions:Required GitHub Secrets:
CONTINUE_API_KEY: Your Continue API key from hub.continue.dev/settings/api-keys
What You’ve Built
After completing this guide, you have a complete AI-powered database management system that:- Analyzes schema design - Identifies optimization opportunities and best practices
- Optimizes queries - Suggests indexes and query rewrites for better performance
- Generates migrations - Creates SQL code for schema improvements
- Monitors health - Runs automated checks for performance and security issues
- Provides insights - Delivers actionable recommendations based on data patterns
Continuous AI Database Management
Your system now operates at Level 2 Continuous AI - AI handles routine database analysis and optimization with human oversight for migration approval.
Advanced Database Prompts
Enhance your workflow with these advanced Continue CLI prompts:Real-time Performance
Monitor query performance in real-time and get alerts for slow queries exceeding threshold times
Data Quality Checks
Automatically validate data integrity, find duplicates, and ensure consistency across related tables
Access Pattern Analysis
Analyze API logs to understand data access patterns and optimize indexes accordingly
Cost Optimization
Review database usage and suggest ways to reduce costs while maintaining performance
Security Best Practices
Database Security Guidelines:
- Always use development/staging environments with MCP
- Enable read-only mode for analysis tasks
- Never store production credentials in code
- Review all AI-generated SQL before execution
- Use RLS policies to enforce access control
- Regularly audit database permissions
Troubleshooting
Supabase MCP Connection Issues
If you encounter connection issues:- Verify OAuth authentication is complete
- Check your Supabase project is accessible
- Ensure you’re not connecting to a production database
- Verify the MCP URL is correct:
https://mcp.supabase.com/mcp
Common Database Analysis Issues
| Issue | Solution |
|---|---|
| No tables found | Verify your database has tables created |
| Permission denied | Check OAuth scopes and project permissions |
| Slow query analysis | Ensure your database has query logs enabled |
| Migration failures | Test migrations in a branch database first |
Next Steps
- Set up Supabase Edge Functions for automated workflows
- Configure Supabase Realtime for live data monitoring
- Implement Database Webhooks for event-driven automation
- Join the Continue Discord for support