SupabaseSelfHostMCP

kodiii/SupabaseSelfHostMCP

3.1

If you are the rightful owner of SupabaseSelfHostMCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server designed for self-hosted Supabase instances, enabling seamless interaction with local or privately hosted Supabase projects.

Supabase Self-Host MCP Server

A Model Context Protocol (MCP) server designed specifically for self-hosted Supabase instances. This server bridges MCP clients (e.g., IDE extensions) with local or privately hosted Supabase projects, facilitating database introspection, management, and interaction directly from the development environment.

Features

  • Database schema introspection and querying
  • Database migration management
  • Database statistics and connection inspection
  • Authentication user management
  • Supabase Storage interaction
  • Type definition generation

Prerequisites

  • Node.js (v16 or higher)
  • A self-hosted Supabase instance
  • PostgreSQL database access

Installation

  1. Clone this repository:

    git clone https://github.com/yourusername/supabase-selfhost-mcp.git
    cd supabase-selfhost-mcp
    
  2. Install dependencies:

    npm install
    
  3. Create a .env file based on the example:

    cp .env.example .env
    
  4. Update the .env file with your Supabase and database configuration.

Configuration

Create a .env file in the root of the project and add the following environment variables. You can use the .env.example file as a template.

VariableDescriptionDefault
PORTThe port the server will run on.3010
NODE_ENVThe environment mode. Can be development or production.development
SUPABASE_URLThe URL of your Supabase instance.http://localhost:8000
SUPABASE_SERVICE_ROLE_KEYThe service role key for your Supabase instance.
SUPABASE_ANON_KEYThe anonymous key for your Supabase instance.
DB_HOST(Optional) The host of your PostgreSQL database. If not provided, the server will attempt to connect using SUPABASE_URL.localhost
DB_PORT(Optional) The port of your PostgreSQL database. If not provided, the server will attempt to connect using SUPABASE_URL.5432
DB_NAME(Optional) The name of your PostgreSQL database. If not provided, the server will attempt to connect using SUPABASE_URL.postgres
DB_USER(Optional) The username for your PostgreSQL database. If not provided, the server will attempt to connect using SUPABASE_URL.postgres
DB_PASSWORD(Optional) The password for your PostgreSQL database. If not provided, the server will attempt to connect using SUPABASE_URL.postgres
JWT_SECRETA secret key for signing JWTs.
JWT_EXPIRYThe expiration time for JWTs (e.g., 24h, 1d).24h
LOG_LEVELThe logging level. Can be info, warn, error, debug.info

Usage

Development

npm run dev

Production

npm run build
npm start

API Endpoints

Database

  • GET /api/database/schemas: List all schemas
  • GET /api/database/tables: List all tables
  • GET /api/database/tables/:schema/:table: Get table details
  • POST /api/database/query: Execute SQL query

Migrations

  • GET /api/migrations: List all migrations
  • POST /api/migrations: Create a new migration
  • POST /api/migrations/apply: Apply pending migrations

Authentication

  • GET /api/auth/users: List all users
  • POST /api/auth/users: Create a new user
  • PUT /api/auth/users/:id: Update a user
  • DELETE /api/auth/users/:id: Delete a user

Storage

  • GET /api/storage/buckets: List all buckets
  • GET /api/storage/buckets/:id/objects: List objects in a bucket
  • POST /api/storage/buckets/:id/objects: Upload an object
  • DELETE /api/storage/buckets/:id/objects/:path: Delete an object

Types

  • GET /api/types/generate: Generate type definitions

Security Considerations

This server is designed to be used in a trusted environment. It uses service role keys to access Supabase resources, which have full access to your database and other services. Make sure to:

  1. Run this server in a secure environment
  2. Use strong JWT secrets
  3. Implement proper authentication for API endpoints
  4. Restrict network access to the server
  5. Regularly update dependencies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.