
Supabase自托管
自托管MCP服务器查询Supabase数据库
自托管MCP服务器查询Supabase数据库
This guide explains how to set up a local instance of the Model Context Protocol (MCP) server to query your Supabase PostgreSQL database on macOS using Docker.
Download and install Docker Desktop for macOS by following the instructions on Docker’s website.
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
Note:
This file defines two services:
Make sure that your Supabase connection details (e.g., database password and database name) are correctly updated in the docker-compose.yml file. You can also use a separate .env file to manage these variables if desired.
Open Terminal.
Navigate to the directory containing your docker-compose.yml file.
Run the following command to start the containers in detached mode:
docker-compose up -d
This command pulls the necessary images (if not already available), creates the containers, and starts them in the background.
To check that everything is running properly, execute:
docker-compose ps
You should see both "supabase-db" and "mcp-supabase" containers with a status of "Up". To troubleshoot any issues, view the logs with:
docker-compose logs -f
Once the MCP server is running, access it via your web browser or API client at:
From here, you can use natural language queries to interact with your Supabase database. This endpoint can also be integrated with any MCP-compatible AI tool to perform SQL operations.
You have successfully set up a self-hosted MCP server on macOS to query your Supabase PostgreSQL database. This setup can be extended or integrated with other services in your development environment, enabling you to experiment with natural language queries and build custom integrations.
Happy coding!