使用说明
Supabase MCP服务器
用于与Supabase数据库交互的模型上下文协议(MCP)服务器。此服务器提供了通过MCP接口查询表和生成TypeScript类型的工具。
特性
-
查询表:在任何表上执行查询,支持:
- 模式选择
- 列过滤
- 带有多个运算符的条款
- 分页
- 错误处理
-
类型生成:为数据库生成TypeScript类型:
- 支持任何模式(public、auth、api等)
- 适用于本地和远程Supabase项目
- 直接输出到控制台
- 自动项目参考检测
先决条件
- Node.js(v16或更高版本)
- Supabase项目(本地或托管)
- Supabase CLI(用于类型生成)
安装
- 克隆存储库:
git clone https://github.com/yourusername/supabase-mcp-server.git
cd supabase-mcp-server
- 安装依赖项:
npm install
- 安装Supabase CLI(类型生成所需):
# Using npm
npm install -g supabase
# Or using Homebrew on macOS
brew install supabase/tap/supabase
配置
-
获取您的Supabase凭据:
-
对于托管项目:
- 转到您的Supabase项目仪表板
- 导航到“项目设置”>“API”
- 复制项目URL和service_role密钥(不是anon密钥)
-
对于本地项目:
- 启动本地Supabase实例
- 使用本地URL(通常http://localhost:54321)
- 使用本地service_role密钥
-
-
配置环境变量:
# Create a .env file (this will be ignored by git)
echo "SUPABASE_URL=your_project_url
SUPABASE_KEY=your_service_role_key" > .env
- 构建服务器:
npm run build
与Claude Desktop集成
-
打开克劳德桌面设置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗户:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
添加服务器配置:
{
"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扩展集成
-
打开VSCode设置:
- macOS:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json - 窗户:
%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
- macOS:
-
添加服务器配置(格式与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>
可用工具
查询表
使用模式选择和where子句支持查询特定表。
参数:
schema(可选):数据库架构(默认为公共)table(必填):要查询的表的名称select(可选):以逗号分隔的列列表where(可选):条件数组,包括:column:列名operator:eq、neq、gt、gte、lt、lte、like、ilike中的一个是value:要比较的值
generate_type
为您的Supabase数据库模式生成TypeScript类型。
参数:
schema(可选):数据库架构(默认为公共)
故障排除
类型生成问题
- 确保安装了Supabase CLI:
supabase --version
-
对于本地项目:
- 确保您的本地Supabase实例正在运行
- 验证您的service_role密钥是否正确
-
对于托管项目:
- 确认您的项目参考是正确的(从URL中提取)
- 验证您使用的是service_role密钥,而不是anon密钥
查询问题
- 检查您的架构和表名
- 验证select和where子句中的列名
- 确保您的service_role密钥具有必要的权限
贡献
- 分叉存储库
- 创建特征分支:
git checkout -b feature/my-feature - 提交您的更改:
git commit -am 'Add my feature' - 推到分支:
git push origin feature/my-feature - 提交拉取请求
许可证
MIT许可证-有关详细信息,请参阅许可证文件