Getting Started

Model context protocol (MCP)


The Model Context Protocol (MCP) is a standard for connecting Large Language Models (LLMs) to external services. This guide will walk you through how to connect AI tools to Supabase using MCP.

There are a number of popular AI tools that support MCP, including:

Connecting these tools to Supabase will allow you to query your database and perform other SQL operations using natural language commands.

Connect to Supabase using MCP

We will use the Postgres MCP server to connect AI tools to Supabase.

Step 1: Find your database connection string

To get started, you will need to retrieve your database connection string. These will differ depending on whether you are using a local or hosted instance of Supabase.

For a local Supabase instance

When running a local instance of Supabase via the CLI, you can find your connection string by running:


_10
supabase status

or if you are using npx:


_10
npx supabase status

This will output a list of details about your local Supabase instance. Copy the DB URL field in the output.

For a hosted Supabase instance

When running a hosted instance of Supabase, you can find your connection string by:

  1. Navigating to your project's Connection settings
  2. Copying the connection string found under Session pooler.

Step 2: Configure in your AI tool

All MCP compatible tools can connect to Supabase using the Postgres MCP server. Pass the following CLI command to your tool:


_10
npx -y @modelcontextprotocol/server-postgres <connection-string>

Replace <connection-string> with the connection string you retrieved in Step 1.

Below are some ways to connect to the Postgres MCP server using popular AI tools:

Cursor

  1. Open Cursor and navigate to Cursor Settings.

  2. Under the Features tab, tap + Add new MCP server under the MCP Servers section.

  3. Enter the following details:

    • Name: Supabase (or your project name)

    • Type: command

    • Command: npx -y @modelcontextprotocol/server-postgres <connection-string>

      (replace <connection-string> with your connection string)

  4. You should see a green active status after the server is successfully connected.

Claude desktop

  1. Open Claude desktop and navigate to Settings.

  2. Under the Developer tab, tap Edit Config to open the configuration file.

  3. Add the following configuration:


    _10
    {
    _10
    "mcpServers": {
    _10
    "supabase": {
    _10
    "command": "npx",
    _10
    "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"]
    _10
    }
    _10
    }
    _10
    }

    Replace <connection-string> with your connection string.

  4. Save the configuration file and restart Claude desktop.

  5. From the new chat screen, you should see a hammer (MCP) icon appear with the new MCP server available.

Cline

  1. Open the Cline extension in VS Code and tap the MCP Servers icon.

  2. Tap Configure MCP Servers to open the configuration file.

  3. Add the following configuration:


    _10
    {
    _10
    "mcpServers": {
    _10
    "supabase": {
    _10
    "command": "npx",
    _10
    "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"]
    _10
    }
    _10
    }
    _10
    }

    Replace <connection-string> with your connection string.

  4. Save the configuration file. Cline should automatically reload the configuration.

  5. You should see a green active status after the server is successfully connected.

Windsurf

  1. Open Windsurf and navigate to the Cascade assistant.

  2. Tap on the hammer (MCP) icon, then Configure to open the configuration file.

  3. Add the following configuration:


    _10
    {
    _10
    "mcpServers": {
    _10
    "supabase": {
    _10
    "command": "npx",
    _10
    "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"]
    _10
    }
    _10
    }
    _10
    }

    Replace <connection-string> with your connection string.

  4. Save the configuration file and reload by tapping Refresh in the Cascade assistant.

  5. You should see a green active status after the server is successfully connected.

Next steps

You are now connected to Supabase using MCP! You can now interact with your database using natural language commands. Try asking your AI tool to query your database, create a new table, or perform other SQL operations.