Supabase MCP 服务器使用说明

项目简介

Supabase MCP 服务器是一个基于 Model Context Protocol (MCP) 构建的后端应用,旨在为大型语言模型(LLM)客户端提供与 Supabase 数据库交互的能力。通过此服务器,LLM 可以使用预定义的工具来查询 Supabase 数据库中的数据,并生成 TypeScript 类型定义,从而更方便地与 Supabase 集成。

主要功能点

  • 查询 Supabase 表格:允许 LLM 客户端通过 'query_table' 工具查询 Supabase 数据库中的表格数据。支持指定 schema、表名、选择列以及使用 'where' 条件进行数据过滤。
  • 生成 TypeScript 类型:允许 LLM 客户端通过 'generate_types' 工具为 Supabase 数据库的 schema 生成对应的 TypeScript 类型定义,方便在前端或后端应用中使用。

安装步骤

  1. 克隆仓库
    git clone https://github.com/NightTrek/Supabase-MCP.git
    cd Supabase-MCP
  2. 安装依赖
    npm install
  3. 安装 Supabase CLI (用于类型生成功能)
    npm install -g supabase
    或者使用 Homebrew (macOS):
    brew install supabase/tap/supabase

服务器配置 (MCP 客户端配置)

要将此 MCP 服务器配置到 MCP 客户端(例如 Claude Desktop 或 VSCode 插件),您需要编辑客户端的配置文件,添加如下 JSON 配置信息。请根据您的实际环境修改配置中的路径和 Supabase 密钥。

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

配置参数说明:

  • 'server name': 'supabase' (服务器名称,可以自定义,用于在 MCP 客户端中引用)
  • 'command': 'node' (启动服务器的命令,这里使用 Node.js 运行)
  • 'args': '["/absolute/path/to/Supabase-MCP/build/index.js"]' (命令参数,指向编译后的服务器入口文件 'index.js' 的绝对路径。请将 '/absolute/path/to/Supabase-MCP' 替换为您克隆仓库的实际绝对路径)
  • 'env': 环境变量配置
    • 'SUPABASE_URL': 'your_project_url' (您的 Supabase 项目 URL,例如 'https://your-project-ref.supabase.co')
    • 'SUPABASE_KEY': 'your_service_role_key' (您的 Supabase 服务角色密钥,请务必使用 service_role 密钥,而非 anon 密钥,在 Supabase 控制台的 "项目设置" -> "API" 中可以找到)

注意:

  • 请确保将 '/absolute/path/to/Supabase-MCP' 替换为 Supabase-MCP 仓库在您本地文件系统中的绝对路径
  • 'SUPABASE_URL' 和 'SUPABASE_KEY' 需要替换为您自己的 Supabase 项目的 URL 和 Service Role 密钥。

基本使用方法

在 MCP 客户端中配置好服务器后,您可以在 LLM 的 Prompt 中使用以下工具标签来调用 Supabase MCP 服务器的功能:

  • 查询表格 (query_table)

    <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>
  • 生成 TypeScript 类型 (generate_types)

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

请参考仓库 'README.md' 文件中 "Usage Examples" 和 "Available Tools" 部分,了解更多工具参数和使用细节。

信息

分类

数据库与文件