> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zerotwo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase Integration

> Connect Supabase to ZeroTwo for AI-powered database management and backend operations

The Supabase integration enables ZeroTwo to interact with your Supabase projects via Model Context Protocol, providing AI-assisted database management, query building, and backend operations.

## What you can do

<CardGroup cols={2}>
  <Card title="Database queries" icon="database">
    Query and analyze your Supabase database with natural language
  </Card>

  <Card title="Schema management" icon="diagram-project">
    View and modify database schemas and tables
  </Card>

  <Card title="API operations" icon="code">
    Interact with Supabase APIs and functions
  </Card>

  <Card title="Data analysis" icon="chart-line">
    Analyze data patterns and generate insights
  </Card>
</CardGroup>

## Connecting Supabase

<Steps>
  <Step title="Open integrations">
    Settings → Integrations → Supabase
  </Step>

  <Step title="Configure connection">
    Enter your Supabase project URL and API keys.

    **Required information:**

    * Project URL
    * Service role key (for admin operations)
    * Anon key (for client operations)
  </Step>

  <Step title="Test connection">
    Verify the connection to your Supabase project.
  </Step>

  <Step title="Confirm">
    <Check>
      Supabase integration is active via MCP.
    </Check>
  </Step>
</Steps>

<Warning>
  Store your Supabase keys securely. ZeroTwo encrypts credentials, but treat service role keys with care as they have admin-level access.
</Warning>

## Using Supabase

### Database queries

<CodeGroup>
  ```text Simple queries theme={null}
  "Show me all users in the database"
  "Find orders from last week"
  "List products with price over $100"
  ```

  ```text Complex queries theme={null}
  "Show me users who haven't logged in for 30 days"
  "Calculate total revenue by product category"
  "Find customers with more than 5 orders this month"
  ```

  ```text Aggregations theme={null}
  "What's the average order value?"
  "Count users by signup date"
  "Show top 10 best-selling products"
  ```
</CodeGroup>

### Schema operations

```text theme={null}
"Show me the schema for the 'orders' table"
"List all tables in the database"
"What columns does the 'users' table have?"
"Show relationships between tables"
```

### Data manipulation

<Tabs>
  <Tab title="Insert">
    ```text theme={null}
    "Add a new user: email john@example.com, name John Doe"
    "Insert a product with name 'Widget' and price $29.99"
    "Create an order for user ID 123"
    ```
  </Tab>

  <Tab title="Update">
    ```text theme={null}
    "Update user email for ID 456 to newemail@example.com"
    "Set product status to 'active' for all items in category 'electronics'"
    "Mark order #789 as shipped"
    ```
  </Tab>

  <Tab title="Delete">
    ```text theme={null}
    "Delete canceled orders older than 90 days"
    "Remove user with ID 999"
    ```

    <Warning>
      Deletion operations are permanent. ZeroTwo will ask for confirmation before executing delete commands.
    </Warning>
  </Tab>
</Tabs>

### API and functions

```text theme={null}
"Call the 'calculate_shipping' function with weight 5kg"
"Execute the 'send_welcome_email' function for user ID 123"
"Test the authentication flow"
```

## Advanced features

### Data analysis

```text theme={null}
"Analyze user growth trends over the last 6 months"
"Find patterns in customer purchase behavior"
"Identify products with declining sales"
"Show correlation between user activity and conversions"
```

### Query optimization

```text theme={null}
"Suggest indexes for the orders table"
"Analyze query performance for the dashboard"
"Identify slow queries in the database"
```

### Real-time subscriptions

```text theme={null}
"Show active real-time subscriptions"
"Monitor changes to the orders table"
"List connected users in real-time"
```

### Database administration

```text theme={null}
"Show database size and usage statistics"
"List all active connections"
"Check database health and performance"
"Show recent error logs"
```

## SQL generation

ZeroTwo can generate SQL queries from natural language:

<Steps>
  <Step title="Describe what you need">
    ```text theme={null}
    "Generate SQL to find users who registered this month and made a purchase"
    ```
  </Step>

  <Step title="Review generated SQL">
    ```sql theme={null}
    SELECT u.id, u.email, u.created_at, COUNT(o.id) as order_count
    FROM users u
    LEFT JOIN orders o ON u.id = o.user_id
    WHERE u.created_at >= DATE_TRUNC('month', CURRENT_DATE)
    GROUP BY u.id, u.email, u.created_at
    HAVING COUNT(o.id) > 0;
    ```
  </Step>

  <Step title="Execute or refine">
    Execute the query or ask for modifications before running.
  </Step>
</Steps>

<Tip>
  Generated SQL includes explanatory comments and follows best practices for security and performance.
</Tip>

## Privacy and security

<Info>
  **Security measures:**

  * API keys encrypted and securely stored
  * Queries executed with appropriate permission levels
  * Row-level security policies respected
  * Audit logging of all database operations
  * No persistent storage of query results

  **Permission levels:**

  * **Service role**: Full admin access (use carefully)
  * **Anon key**: Respects RLS policies (recommended for most operations)
</Info>

<Check>
  ZeroTwo respects your Supabase Row Level Security (RLS) policies. Queries are executed with the permissions you configure.
</Check>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection errors">
    **Solutions:**

    * Verify project URL is correct
    * Check API keys are valid and not expired
    * Ensure Supabase project is active
    * Confirm network connectivity
    * Check if IP is allowed in Supabase settings
  </Accordion>

  <Accordion title="Permission denied errors">
    **Solutions:**

    * Verify RLS policies allow the operation
    * Check service role key for admin operations
    * Ensure user has necessary permissions
    * Review policy conditions and filters
  </Accordion>

  <Accordion title="Query timeout">
    **Solutions:**

    * Simplify complex queries
    * Add appropriate indexes
    * Reduce result set size with LIMIT
    * Check database performance metrics
    * Consider query optimization
  </Accordion>

  <Accordion title="Data not appearing">
    **Solutions:**

    * Check RLS policies aren't filtering data
    * Verify you're querying the correct table
    * Confirm data exists with admin access
    * Check for soft deletes or archive flags
  </Accordion>
</AccordionGroup>

## Use cases

### Application development

```text theme={null}
"Show me the database schema and suggest improvements"
"Generate TypeScript types for the 'users' table"
"Create sample seed data for testing"
```

### Data analysis

```text theme={null}
"Analyze user engagement metrics for the last month"
"Create a report of top-performing products"
"Identify user churn patterns"
```

### Database maintenance

```text theme={null}
"Find and archive old records"
"Identify unused tables or columns"
"Suggest performance optimizations"
```

### Debugging

```text theme={null}
"Show me recent failed authentication attempts"
"Find orphaned records in the orders table"
"Check data integrity across related tables"
```

## Related integrations

<CardGroup cols={2}>
  <Card title="MCP overview" icon="plug" href="/integrations/mcp-overview">
    Learn about Model Context Protocol
  </Card>

  <Card title="Code interpreter" icon="terminal" href="/tools/code-interpreter">
    Run and test database queries
  </Card>

  <Card title="GitHub" icon="github" href="/integrations/github">
    Version control for migrations
  </Card>

  <Card title="All integrations" icon="grid" href="/integrations">
    Browse all integrations
  </Card>
</CardGroup>

## Next steps

<CardGroup cols={2}>
  <Card title="Custom extensions" icon="puzzle-piece" href="/tools/custom-extensions">
    Build custom Supabase workflows
  </Card>

  <Card title="Tool permissions" icon="shield" href="/tools/permissions-and-privacy">
    Understanding integration security
  </Card>
</CardGroup>
