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

# Supabase Database Agent

> Create an AI agent that can interact with your Supabase database

<Check icon="clock">Estimated time to complete: 5 minutes</Check>

<img className="block rounded-xl" src="https://mintcdn.com/pompeiilabsinc/INRokfUt_EitWThD/assets/templates/supabase/supabase-header.png?fit=max&auto=format&n=INRokfUt_EitWThD&q=85&s=f937c1aec5886dab2d6e983a1ee2ec6b" alt="Supabase Agent Demo" width="2400" height="1350" data-path="assets/templates/supabase/supabase-header.png" />

## Overview

Welcome to Magma! 🌋

This template will help you create:

* An AI agent hosted on Magma
* A secure connection to your Supabase database
* Natural language interactions with your database to run complex queries

<Info>
  **Prerequisites**:

  * A Supabase project with database access
  * Your database's master password
  * If you've lost the password, reset it in the Supabase dashboard before continuing
</Info>

## Getting Started

<Steps>
  <Step title="Install the CLI">
    If you have already installed the CLI, you can skip this step

    ```bash theme={null}
    npm install -g @pompeii-labs/cli
    ```
  </Step>

  <Step title="Login to Magma">
    ```bash theme={null}
    magma login
    ```
  </Step>

  Use the `magma init` command to create a new agent using the `supabase-db` template

  <Step title="Use the Supabase Template">
    ```bash theme={null}
    magma init --template supabase-db [agent-name]

    cd [agent-name]
    ```
  </Step>
</Steps>

## Supabase Configuration

### Getting Your Connection String

<Steps>
  <Step title="Access Supabase Dashboard">
    1. Go to your Supabase project dashboard
    2. Click the "Connect" button at the top of the screen

    <img className="block rounded-lg border border-zinc-200 dark:border-zinc-700 mt-4" src="https://mintcdn.com/pompeiilabsinc/INRokfUt_EitWThD/assets/templates/supabase/supabase-connect-button.png?fit=max&auto=format&n=INRokfUt_EitWThD&q=85&s=9eb3d06dec8c600d80016fcd7048baa2" alt="Supabase Connect Button" width="682" height="148" data-path="assets/templates/supabase/supabase-connect-button.png" />
  </Step>

  <Step title="Find Connection Details">
    Locate the "Transaction Pooler" section in the connection panel

    <img className="block rounded-lg border border-zinc-200 dark:border-zinc-700 mt-4" src="https://mintcdn.com/pompeiilabsinc/INRokfUt_EitWThD/assets/templates/supabase/supabase-connection-string.png?fit=max&auto=format&n=INRokfUt_EitWThD&q=85&s=8d4aee7c022987e4e9e2641139be44e6" alt="Supabase Transaction Pooler Connection String" width="1027" height="712" data-path="assets/templates/supabase/supabase-connection-string.png" />

    <Warning>
      Make sure to use the Transaction Pooler connection string, not the direct connection string!
    </Warning>
  </Step>

  <Step title="Copy Connection String">
    Copy the entire postgres connection string (starts with `postgresql://`)
  </Step>

  <Step title="Set Environment Variable">
    Add the connection string to your `.env` file:

    ```bash theme={null}
    POSTGRES_URL=postgresql://postgres.your-project-id:[YOUR-PASSWORD]...
    ```
  </Step>

  <Step title="Update database password">
    Replace `[YOUR-PASSWORD]` with your database's master password in the POSTGRES\_URL environment variable.
  </Step>
</Steps>

## Testing and Deployment

<Steps>
  <Step title="Local Testing">
    Test your agent locally first:

    ```bash theme={null}
    magma run
    ```
  </Step>

  <Step title="Deploy">
    When everything works locally, deploy to Magma:

    ```bash theme={null}
    magma deploy
    ```
  </Step>
</Steps>

Now, your agent is deployed on [Magma](https://magmadeploy.com) and ready to use!!

## Troubleshooting

<AccordionGroup>
  <Accordion title="Database Connection Issues">
    If you're experiencing DNS or connection errors:

    * Verify you're using the **Transaction Pooler** connection string
    * Check that your connection string is properly formatted
    * Ensure your database password is correct
  </Accordion>

  <Accordion title="Deployment Errors">
    If you encounter Anthropic SDK related deployment issues:

    1. Open `tsconfig.json`
    2. Add `"skipLibCheck": true` to the `compilerOptions` section
    3. Run `magma deploy` again
  </Accordion>
</AccordionGroup>

<CardGroup cols={2}>
  <Card title="Need Help?" icon="question" href="mailto:founders@pompeiilabs.com">
    Contact our support team for assistance
  </Card>

  <Card title="Join Community" icon="slack" href="https://magmacommunity.slack.com">
    Connect with other Magma developers
  </Card>
</CardGroup>
