MCP ExplorerExplorer

Supabase Mcpserver

@amraly83on a year ago
1 MIT
FreeCommunity
AI Systems
Supabase MCP Server enables AI assistants to interact with Supabase databases via a standardized interface.

Overview

What is Supabase Mcpserver

Supabase MCP Server is a Model Context Protocol (MCP) server that facilitates interaction with a Supabase database, allowing AI assistants to perform database operations through a standardized interface.

Use cases

Use cases include creating and managing database tables, integrating AI assistants with Supabase for data retrieval and manipulation, and automating backend operations in web applications.

How to use

To use Supabase MCP Server, clone the repository, install the dependencies, and provide Supabase credentials in client requests. You can also build and run the server using Docker.

Key features

Key features include a standardized interface for database operations, support for Supabase credentials in requests, and the ability to run the server in a Docker container.

Where to use

Supabase MCP Server can be used in applications that require database interactions, particularly in AI-driven projects where automated data handling is essential.

Content

Supabase MCP Server

This project implements a Model Context Protocol (MCP) server that provides tools for interacting with a Supabase database. The server enables AI assistants to perform database operations through a standardized interface.

Setup

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_name>
    
  2. Install the dependencies:

    pip install -r requirements.txt
    
  3. The server now accepts Supabase credentials from client requests instead of requiring environment variables.
    Clients should provide these in their request:

{
  "supabase_url": "your_supabase_url",
  "supabase_key": "your_supabase_service_role_key",
  "tool": "create_table",
  "arguments": {
    "table_name": "users",
    "schema": [
      {
        "name": "id",
        "type": "SERIAL PRIMARY KEY"
      },
      {
        "name": "name",
        "type": "TEXT"
      }
    ]
  }
}

Docker

  1. Build the Docker container:

    docker build -t mcp-server .
    
  2. Run the container:

    docker run -p 8000:8000 mcp-server
    

    This will build an image named mcp-server and then run it, mapping port 8000 on your host to port 8000 in the container.

GitHub Repository

To push the files to a GitHub repository, follow these steps:

  1. Initialize a Git repository in the current directory:

    git init
    
  2. Add all the files to the staging area:

    git add .
    
  3. Commit the changes:

    git commit -m "Initial commit"
    
  4. Rename the branch to main:

    git branch -M main
    
  5. Add the remote repository:

    git remote add origin https://github.com/amraly83/supabase-mcp-server.git
    
  6. Push the files to the repository:

    git push -u origin main
    

    You may be prompted for your GitHub username and password. If you have 2FA enabled, you’ll need to use a personal access token instead of your password.

Usage

The server provides the following tools:

  • read_rows(table_name: str = None, limit: int = 10): Reads rows from a Supabase table.
    • table_name: The name of the table to read from. This is an optional parameter. If no table name is provided, it will return rows from all tables.
    • limit: The maximum number of rows to return. Defaults to 10. This is an optional parameter.
  • create_record(table_name: str, record: dict): Creates a new record in a Supabase table.
    • table_name: The name of the table to create the record in.
    • record: A dictionary containing the data for the new record.
  • update_record(table_name: str, record_id: int, updates: dict): Updates an existing record in a Supabase table.
    • table_name: The name of the table to update the record in.
    • record_id: The ID of the record to update.
    • updates: A dictionary containing the updates to apply to the record.
  • delete_record(table_name: str, record_id: int): Deletes a record from a Supabase table.
    • table_name: The name of the table to delete the record from.
    • record_id: The ID of the record to delete.
  • list_tables(): Lists all tables in the Supabase database.
  • create_table(table_name: str, schema: list): Creates a new table in the Supabase database.
    • table_name: The name of the table to create.
    • schema: A list of dictionaries, where each dictionary represents a column in the table. Each dictionary must have the keys “name” and “type”.

Example

To use the server, you can send JSON requests to the server’s standard input. For example, to read the first 5 rows from a table named “products”, you would send the following JSON:

{
  "supabase_url": "your_supabase_url",
  "supabase_key": "your_supabase_service_role_key",
  "tool": "read_rows",
  "arguments": {
    "table_name": "products",
    "limit": 5
  }
}

To list all tables in the Supabase database, you would send the following JSON:

{
  "supabase_url": "your_supabase_url",
  "supabase_key": "your_supabase_service_role_key",
  "tool": "list_tables",
  "arguments": {}
}

To create a new table named “users” with columns “id” (SERIAL PRIMARY KEY) and “name” (TEXT), you would send the following JSON:

{
  "supabase_url": "your_supabase_url",
  "supabase_key": "your_supabase_service_role_key",
  "tool": "create_table",
  "arguments": {
    "table_name": "users",
    "schema": [
      {
        "name": "id",
        "type": "SERIAL PRIMARY KEY"
      },
      {
        "name": "name",
        "type": "TEXT"
      }
    ]
  }
}

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers