home / mcp / supabase mcp server

Supabase MCP Server

Self-hosted MCP server to query a Supabase PostgreSQL database via natural language prompts.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "chaichungsang-mcp_supabase_self_host": {
      "command": "sh",
      "args": [
        "-c",
        "npx -y @modelcontextprotocol/server-postgres 'postgres://postgres:your_postgres_password@db:5432/your_database_name'"
      ]
    }
  }
}

You can run a self-hosted MCP Server on macOS to query your Supabase PostgreSQL database. This setup lets you ask natural language questions and have them translated into SQL queries against your Supabase data, all from a local environment.

How to use

Access the MCP Server at http://localhost:3000 from a web browser or an API client. You can use natural language prompts to request data, run queries, or perform SQL operations against your Supabase database through the MCP interface. The server handles translating your natural language requests into SQL and delivering the results back to you.

How to install

Prerequisites you need before starting:

- Docker Desktop for macOS installed.

Follow these concrete steps to set up and run the MCP server locally.

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
    # This command runs the MCP server using npx.
    # Replace the connection string values with your own credentials.
    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:

Note: Replace "your_postgres_password" with your actual PostgreSQL password and "your_database_name" with your actual database name.

This file defines two services:
- db: Runs the official Supabase PostgreSQL container. It exposes port 5432 and persists data using a Docker volume named "db-data".
- mcp: Uses a Node 18 container to run the MCP server via npx. It connects to the PostgreSQL container with the given connection string and is exposed on port 3000.

Additional sections

Configuration notes: Ensure the Supabase connection details (password and database name) in the docker-compose.yml file match your setup. If you want to manage these values separately, you can use a .env file to store them and reference them from docker-compose.

Security: Keep access to http://localhost:3000 restricted to your development environment. Do not expose this local MCP Server to the public internet without proper authentication and security controls.

Troubleshooting tips: If the MCP Server fails to start, check container logs with docker-compose logs -f and verify that the database container is up and reachable at db:5432 from the MCP container.