Supabase Self-Host MCP server

Self-hosted containerized MCP implementation with PostgreSQL backend for maintaining full control over sensitive data while providing persistent storage through Docker volumes.
Back to servers
Provider
Chai Chung Sang
Release date
Mar 20, 2025

This server implements the Model Context Protocol (MCP) to allow natural language querying of your Supabase PostgreSQL database on macOS. With this setup, you can interact with your database using conversational language rather than writing SQL queries directly.

Installation

Prerequisites

  • A Supabase account with your project credentials
  • Docker Desktop for macOS installed

Setting Up Your MCP Server

  1. Install Docker Desktop

    Download and install Docker Desktop for macOS from the official website.

  2. Create Docker Configuration

    Create a new file named docker-compose.yml and add the following content:

    version: '3.8'
    services:
      db:
        image: supabase/postgres:15.8.1.049
        container_name: supabase-db
        restart: unless-stopped
        environment:
          POSTGRES_PASSWORD: your_postgres_password
          POSTGRES_DB: your_database_name
        ports:
          - "5432:5432"
        volumes:
          - db-data:/var/lib/postgresql/data
    
      mcp:
        image: node:18
        container_name: mcp-supabase
        working_dir: /app
        command: >
          sh -c "npx -y @modelcontextprotocol/server-postgres 'postgres://postgres:your_postgres_password@db:5432/your_database_name'"
        depends_on:
          - db
        ports:
          - "3000:3000"
        environment:
          NODE_ENV: production
    
    volumes:
      db-data:
    
  3. Configure Connection Details

    In the docker-compose.yml file, replace:

    • your_postgres_password with your actual PostgreSQL password
    • your_database_name with your actual database name
  4. Start the Docker Containers

    Open Terminal, navigate to the directory containing your docker-compose.yml file, and run:

    docker-compose up -d
    
  5. Verify Your Installation

    Check that the services are running properly:

    docker-compose ps
    

    You should see both "supabase-db" and "mcp-supabase" containers with a status of "Up".

    To view the logs for troubleshooting:

    docker-compose logs -f
    

Using Your MCP Server

Accessing the Server

Once the MCP server is running, you can access it at:

http://localhost:3000

Making Natural Language Queries

With the server running, you can send natural language queries to interact with your Supabase database. This endpoint can be integrated with any MCP-compatible AI tool to perform SQL operations.

Example Usage

You can use tools like curl to send requests to your MCP server:

curl -X POST http://localhost:3000/query \
  -H "Content-Type: application/json" \
  -d '{"query": "Show me all users who signed up last month"}'

Troubleshooting

If you encounter issues:

  • Check the container logs for detailed error messages
  • Verify your database credentials are correct
  • Ensure Docker is running properly on your system
  • Confirm ports 3000 and 5432 are not being used by other applications

Stopping the Server

To stop the MCP server and database:

docker-compose down

To stop and remove all data volumes:

docker-compose down -v

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later