使用说明
Supabase MCP服务器🚀
🔥 一个强大的模型上下文协议(MCP)服务器,通过Cursor的Composer和Codeium的Cascade提供对Supabase PostgreSQL数据库的完全管理控制。该工具支持无缝数据库管理,具有表操作、记录管理、模式修改等全面功能。
📚 目录
🔧 先决条件
- Node.js>=16.x
- npm>=8.x
- Supabase项目包括:
- 项目ID
- 数据库密码
- PostgreSQL连接字符串
- Cursor IDE或Codeium的Cascade(面向付费用户)
🚀 快速开始
📥 安装
# Clone the repository
git clone https://github.com/Quegenx/supabase-mcp-server.git
cd supabase-mcp-server
# Install dependencies
npm install
# Build the project
npm run build
⚙️ 配置
-
安装依赖项并构建项目:
npm install npm run build -
在Cursor的MCP设置中,使用以下命令添加服务器:
/opt/homebrew/bin/node /path/to/dist/index.js postgresql://postgres.[PROJECT-ID]:[PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:5432/postgres替换:
/path/to/dist/index.js与你的实际路径[PROJECT-ID]使用您的Supabase项目ID[PASSWORD]使用您的数据库密码
注意:确保您的数据库凭据安全,切勿将其提交给版本控制。
🎯 集成
光标MCP集成
模型上下文协议(MCP)允许您在Cursor中为代理LLM提供自定义工具。此服务器可以与Cursor的Composer功能集成,通过自然语言命令直接访问所有数据库管理工具。
在Cursor中设置
-
打开光标设置>功能>MCP
-
点击“+添加新MCP服务器”按钮
-
填写模态表格:
- 名称:“Supabase MCP”(或您喜欢的任何昵称)
- 类型:
command(stdio传输) - 命令:包含连接详细信息的完整命令字符串
-
先构建项目:
npm install npm run build -
获取你的Node.js路径:
# On Mac/Linux which node # On Windows where node -
添加服务器命令:
/path/to/node /path/to/dist/index.js postgresql://postgres.[PROJECT-ID]:[PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:5432/postgres替换:
/path/to/node使用您的实际Node.js路径(从步骤5开始)/path/to/dist/index.js使用您构建的JavaScript文件的实际路径[PROJECT-ID]使用您的Supabase项目ID[PASSWORD]使用您的数据库密码
-
点击“添加服务器”,然后点击右上角的刷新按钮
在游标中使用工具
当您描述数据库任务时,Composer Agent将自动检测并使用相关工具。例如:
- “列出数据库中的所有表”
- “创建新用户表”
- “为电子邮件列添加索引”
当代理使用工具时,您将看到:
- 批准/拒绝工具调用的提示
- 工具调用参数(可扩展)
- 批准后的回复
注意:对于像这样的stdio服务器,该命令应该是有效的shell命令。如果您需要环境变量,请考虑使用包装器脚本。
Windsurf/Cascade集成
此MCP服务器还支持Codeium的Cascade(Windsurf)集成。请注意,此功能目前仅适用于付费个人用户(不适用于团队或企业用户)。
使用Cascade进行设置
-
创建或编辑
~/.codeium/windsurf/mcp_config.json:{ "mcpServers": { "supabase-mcp": { "command": "/path/to/node", "args": [ "/path/to/dist/index.js", "postgresql://postgres.[PROJECT-ID]:[PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:5432/postgres" ] } } } -
快速访问配置:
- 找到Cascade输入上方的工具栏
- 点击锤子图标
- 点击“配置”打开mcp_config.json
-
在配置中替换:
/path/to/node使用您的实际Node.js路径/path/to/dist/index.js与你的实际路径[PROJECT-ID]使用您的Supabase项目ID[PASSWORD]使用您的数据库密码
-
在级联中:
- 单击工具栏中的锤子图标
- 单击“配置”以验证您的设置
- 点击“刷新”加载MCP服务器
- 单击服务器名称查看可用工具
Cascade用户的重要注意事项
- 仅支持工具功能(无提示或资源)
- 无论成功或失败,MCP工具调用都将消耗积分
- 不支持图像输出
- 仅支持stdio传输类型
- 工具调用可以调用由任意服务器实现者编写的代码
- Cascade不对MCP工具调用失败承担责任
✨ 特性
🎯 可用的数据库工具
表格管理
- 桌子:
list_tables,create_table,drop_table,rename_table - 柱:
add_column,drop_column,alter_column - 记录:
fetch_records,create_record,update_record,delete_record
指标和约束
- 指标:
list_indexes,create_index,delete_index,update_index - 限制:
list_constraints,add_constraint,remove_constraint,update_constraint
数据库函数和触发器
- 功能:
list_functions,create_function,update_function,delete_function - 触发器:
list_triggers,create_trigger,update_trigger,delete_trigger
安全和访问控制
- 政策:
list_policies,create_policy,update_policy,delete_policy - 角色:
list_roles,create_role,update_role,delete_role
存储管理
- 水桶:
list_buckets,create_bucket,delete_bucket - 文件夹:
delete_file,bulk_delete_files - 文件夹:
list_folders
数据类型和出版物
- 枚举类型:
list_enumerated_types,create_enumerated_type,update_enumerated_type,delete_enumerated_type - 出版物:
list_publications,create_publication,update_publication,delete_publication
实时功能
- 政策:
list_realtime_policies,create_realtime_policy,update_realtime_policy,delete_realtime_policy - 频道:
list_realtime_channels,manage_realtime_channels,send_realtime_message,get_realtime_messages - 管理层:
manage_realtime_status,manage_realtime_views
用户管理
- 认证:
list_users,create_user,update_user,delete_user
直接SQL访问
- 查询:
query-执行自定义SQL查询
🚀 关键利益
- 自然语言控制:通过简单的对话命令管理您的Supabase数据库
- 全面覆盖:全套工具,涵盖表、记录、索引、函数、安全性等
- 无缝集成:直接在Cursor的Composer和Codeium的Cascade中工作
- 开发者友好:减少IDE和数据库管理工具之间的上下文切换
- 安全访问:通过适当的身份验证维护数据库安全
📁 项目结构
supabase-mcp-server/
├── dist/ # Compiled JavaScript files
│ ├── index.d.ts # TypeScript declarations
│ └── index.js # Main JavaScript file
├── src/ # Source code
│ └── index.ts # Main TypeScript file
├── package.json # Project configuration
├── package-lock.json # Dependency lock file
└── tsconfig.json # TypeScript configuration
💡 用法
配置后,MCP服务器通过Cursor的Composer提供所有数据库管理工具。只需描述你想对数据库做什么,人工智能就会使用适当的命令。
示例:
- 📋 “显示数据库中的所有表”
- ➕ 创建一个包含id、name和email列的新用户表
- 🔍 “在用户表的电子邮件列上添加索引”
🔒 安全说明
- 🔐 确保数据库连接字符串的安全
- ⚠️ 切勿将敏感凭据提交到版本控制
- 👮 使用适当的访问控制和权限
- 🛡️ 验证并清理所有输入以防止SQL注入
🛠️ 故障排除
常见连接问题
-
Node.js路径问题
- 确保你使用了正确的Node.js路径
- 在Mac/Linux上:使用
which node找到正确的路径 - 在Windows上:使用
where node找到正确的路径 - 替换
/usr/local/bin/node使用您的实际Node.js路径
-
文件路径问题
- 使用绝对路径而不是相对路径
- 在Mac/Linux上:使用
pwd在项目目录中获取完整路径 - 在Windows上:使用
cd获取完整路径 - 例子:
/Users/username/projects/supabase-mcp-server/dist/index.js
-
MCP未检测工具
- 单击Cursor的MCP设置中的刷新按钮
- 确保服务器正在运行(无错误消息)
- 检查您的连接字符串是否正确
- 验证您的Supabase凭据是否有效
-
权限问题
- 确保
dist目录存在(运行npm run build) - 检查文件权限(
chmod +x在Unix系统上) - 跑
npm install具有适当的权限
- 确保
调试模式
添加 DEBUG=true 在您的命令之前查看详细日志:
DEBUG=true /usr/local/bin/node /path/to/dist/index.js [connection-string]
平台特定注意事项
windows用户
# Use this format for the command
"C:\\Program Files\\nodejs\\node.exe" "C:\\path\\to\\dist\\index.js" "postgresql://..."
Linux用户
# Find Node.js path
which node
# Make script executable
chmod +x /path/to/dist/index.js
如果您仍然遇到问题,请 打开一个问题 与:
- 您的操作系统
- Node.js版本(
node --version) - 完整错误消息
- 重现步骤
🤝 贡献
欢迎投稿!请随时提交拉取请求。
📄 许可证
Built with ❤️ for the Cursor community