S

Supabase-MCP 数据库查询工具

@NightTrek/Supabase-MCP
0 Stars 477 次浏览 NightTrek 更新于 2026-08-23

通过模型上下文协议接口,启用对 Supabase 数据库的查询以及生成 TypeScript 类型的功能,支持模式选择、列过滤和分页等功能。

该服务暂未提供标准配置,请参考 README 手动接入

可用工具 (2 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

query_table 4 个参数 需填 1 项

Query a specific table with schema selection and where clause support

必填参数:table

generate_types 1 个参数

Generate TypeScript types for your Supabase database schema

该工具无需必填参数,直接调用即可

服务介绍

Supabase MCP 服务器

一个用于与 Supabase 数据库交互的 Model Context Protocol (MCP) 服务器。此服务器通过 MCP 接口提供了查询表和生成 TypeScript 类型的工具。

功能

  • 查询表:执行任何表的查询,支持:

    • 模式选择
    • 列过滤
    • 带有多个操作符的 Where 子句
    • 分页
    • 错误处理
  • 类型生成:为您的数据库生成 TypeScript 类型:

    • 支持任何模式(公共、认证、API 等)
    • 适用于本地和远程 Supabase 项目
    • 直接输出到控制台
    • 自动项目引用检测

先决条件

  1. Node.js (v16 或更高版本)
  2. 一个 Supabase 项目(本地或托管)
  3. Supabase CLI(用于类型生成)

安装

  1. 克隆仓库:
git clone https://github.com/yourusername/supabase-mcp-server.git
cd supabase-mcp-server
  1. 安装依赖项:
npm install
  1. 安装 Supabase CLI(类型生成必需):
# Using npm
npm install -g supabase

# Or using Homebrew on macOS
brew install supabase/tap/supabase

配置

  1. 获取您的 Supabase 凭证:

    • 对于托管项目:

      1. 转到您的 Supabase 项目仪表板
      2. 导航至项目设置 > API
      3. 复制项目 URL 和 service_role 密钥(不是 anon 密钥)
    • 对于本地项目:

      1. 启动本地 Supabase 实例
      2. 使用本地 URL(通常是 http://localhost:54321)
      3. 使用本地 service_role 密钥
  2. 配置环境变量:

# Create a .env file (this will be ignored by git)
echo "SUPABASE_URL=your_project_url
SUPABASE_KEY=your_service_role_key" > .env
  1. 构建服务器:
npm run build

与 Claude Desktop 的集成

  1. 打开 Claude Desktop 设置:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  2. 添加服务器配置:

{
  "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"
      }
    }
  }
}

与 VSCode 扩展的集成

  1. 打开 VSCode 设置:

    • 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. 添加服务器配置(与 Claude Desktop 格式相同)。

使用示例

查询表

// Query with schema selection and where clause
<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>

生成类型

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

可用工具

query_table

查询特定表,支持模式选择和 Where 子句。

参数:

  • schema (可选): 数据库模式(默认为 public)
  • table (必需): 要查询的表名
  • select (可选): 逗号分隔的列列表
  • where (可选): 条件数组,包含:
    • column: 列名
    • operator: 以下之一:eq, neq, gt, gte, lt, lte, like, ilike, is
    • value: 比较值

generate_types

为您的 Supabase 数据库模式生成 TypeScript 类型。

参数:

  • schema (可选): 数据库模式(默认为 public)

故障排除

类型生成问题

  1. 确保已安装 Supabase CLI:
supabase --version
  1. 对于本地项目:

    • 确保您的本地 Supabase 实例正在运行
    • 验证您的 service_role 密钥是否正确
  2. 对于托管项目:

    • 确认您的项目引用是正确的(从 URL 中提取)
    • 确认您使用的是 service_role 密钥,而不是 anon 密钥

查询问题

  1. 检查您的模式和表名
  2. 验证 select 和 where 子句中的列名
  3. 确保您的 service_role 密钥具有必要的权限

贡献

  1. 叉取仓库
  2. 创建您的功能分支:git checkout -b feature/my-feature
  3. 提交您的更改:git commit -am 'Add my feature'
  4. 推送到该分支:git push origin feature/my-feature
  5. 提交一个拉取请求

许可证

MIT 许可证 - 详情请参阅 LICENSE 文件

相关 MCP 服务