Supabase MCP server

Bridges Supabase databases with natural language commands for querying tables, generating TypeScript types, and exploring schemas.
Back to servers
Provider
NightTrek
Release date
Jan 08, 2025
Language
TypeScript
Stats
11 stars

This MCP server for Supabase enables you to interact with Supabase databases by querying tables and generating TypeScript types. It provides a standardized way to access your data through Claude's Model Context Protocol interface, making database operations more accessible through AI-powered tools.

Prerequisites

  • Node.js (v16 or higher)
  • A Supabase project (either local or hosted)
  • Supabase CLI (for type generation)

Installation

  1. Clone the repository:

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

    npm install
    
  3. Install the Supabase CLI (required for type generation):

    # Using npm
    npm install -g supabase
    
    # Or using Homebrew on macOS
    brew install supabase/tap/supabase
    

Configuration

Setting Up Your Supabase Credentials

  1. Get your Supabase credentials:

    • For hosted projects:

      • Go to your Supabase project dashboard
      • Navigate to Project Settings > API
      • Copy the Project URL and service_role key (NOT the anon key)
    • For local projects:

      • Start your local Supabase instance
      • Use the local URL (typically http://localhost:54321)
      • Use your local service_role key
  2. Configure environment variables:

    # Create a .env file (this will be ignored by git)
    echo "SUPABASE_URL=your_project_url
    SUPABASE_KEY=your_service_role_key" > .env
    
  3. Build the server:

    npm run build
    

Integration with Claude Desktop

  1. Open Claude Desktop settings file at:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  2. Add the server configuration:

    {
      "mcpServers": {
        "supabase": {
          "command": "node",
          "args": ["/absolute/path/to/supabase-mcp-server/build/index.js"],
          "env": {
            "SUPABASE_URL": "your_project_url",
            "SUPABASE_KEY": "your_service_role_key"
          }
        }
      }
    }
    

Integration with VSCode Extension

  1. Open VSCode settings file at:

    • macOS: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
    • Windows: %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
    • Linux: ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
  2. Add the server configuration (same format as Claude Desktop).

Usage Examples

Querying Tables

Query tables with schema selection, column filtering, and where clauses:

<use_mcp_tool>
<server_name>supabase</server_name>
<tool_name>query_table</tool_name>
<arguments>
{
  "schema": "public",
  "table": "users",
  "select": "id,name,email",
  "where": [
    {
      "column": "is_active",
      "operator": "eq",
      "value": true
    }
  ]
}
</arguments>
</use_mcp_tool>

Generating Types

Generate TypeScript types for your database schema:

<use_mcp_tool>
<server_name>supabase</server_name>
<tool_name>generate_types</tool_name>
<arguments>
{
  "schema": "public"
}
</arguments>
</use_mcp_tool>

Available Tools

query_table

Query a specific table with schema selection and where clause support.

Parameters:

  • schema (optional): Database schema (defaults to public)
  • table (required): Name of the table to query
  • select (optional): Comma-separated list of columns
  • where (optional): Array of conditions with:
    • column: Column name
    • operator: One of: eq, neq, gt, gte, lt, lte, like, ilike, is
    • value: Value to compare against

generate_types

Generate TypeScript types for your Supabase database schema.

Parameters:

  • schema (optional): Database schema (defaults to public)

Troubleshooting

Type Generation Issues

  1. Ensure Supabase CLI is installed:

    supabase --version
    
  2. For local projects:

    • Make sure your local Supabase instance is running
    • Verify your service_role key is correct
  3. For hosted projects:

    • Confirm your project ref is correct (extracted from URL)
    • Verify you're using the service_role key, not the anon key

Query Issues

  • Check your schema and table names
  • Verify column names in select and where clauses
  • Ensure your service_role key has necessary permissions

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