Supabase MCP 服务器实施计划
本文档概述了创建连接到 Supabase 的模型上下文协议 (MCP) 服务器的计划,允许 GitHub Copilot 等 AI 助手与您的 Supabase 数据库进行交互。
目录
概述
Supabase MCP 服务器将充当 AI 助手(例如 GitHub Copilot)和 Supabase 数据库之间的桥梁。这使得 AI 能够:
了解数据库架构
了解表和关系
协助撰写查询
提供与您的数据模型相关的上下文感知建议
先决条件
已安装 Node.js 18+
npm 或 yarn 包管理器
带有管理员 API 密钥的 Supabase 项目
支持 Copilot/MCP 的 VS Code
Git
实施步骤
1. 创建服务器包
2.安装依赖项
3. 基本服务器结构
创建以下文件:
src/index.js- 主入口点src/supabase-client.js- Supabase 连接处理src/schema-provider.js- 数据库模式提取src/query-handler.js- 安全查询执行.env.example- 环境变量模板config.js- 配置管理
4. 服务器实现细节
src/index.js
该文件将初始化 MCP 服务器并连接组件:
src/supabase-client.js
src/schema-provider.js
src/query-handler.js
配置.js
.env.示例
5. Supabase 数据库功能
您需要在 Supabase 中创建这些存储过程:
get_schema_information()- 返回数据库模式get_table_information(table_name TEXT)- 返回有关特定表的信息execute_query(query_string TEXT, query_params JSONB)- 安全执行查询
服务器架构
配置
将 Supabase MCP 服务器添加到你的 VS Code settings.json :
安全注意事项
API密钥管理:
使用具有最低所需权限的范围 API 密钥
安全存储 API 密钥,无需进行版本控制
考虑使用密钥轮换策略
查询限制:
为了安全起见,默认为仅选择
考虑实施查询允许列表方法
添加速率限制以防止滥用
数据保护:
避免暴露 PII 或敏感数据
在 Supabase 中实现行级安全性
考虑为敏感字段添加数据屏蔽
安装指南
本地开发
克隆存储库
git clone https://github.com/yourusername/mcp-server-supabase.git cd mcp-server-supabase安装依赖项
npm install从示例创建
.env文件cp .env.example .env使用你的 Supabase 凭证编辑
.env启动服务器
node src/index.js
VS Code 集成
使用服务器配置更新 VS Code
settings.json重启 VS Code
在 VS Code MCP 面板中验证服务器是否正在运行
使用示例
集成后,您可以通过多种方式使用 Supabase MCP 服务器:
模式探索:
What tables do I have in my Supabase database?表格信息:
What columns are in the users table?查询协助:
Help me write a query to get all users who signed up in the last 7 days
故障排除
服务器无法启动
检查你的 Node.js 版本(应为 18 岁以上)
验证您的 Supabase 凭据
检查终端中的错误日志
架构未加载
验证您的 Supabase 服务密钥是否具有必要的权限
检查数据库函数是否正确创建
VS Code 无法连接
检查settings.json中的服务器路径是否正确
配置更改后重新启动 VS Code
验证服务器进程是否正在运行
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
GitHub Copilot 和 Supabase 数据库等 AI 助手之间的桥梁,使 AI 能够理解模式、协助查询编写并提供与您的数据模型相关的上下文感知建议。
Related MCP Servers
- -securityFlicense-qualityEnables AI assistants to interact with Metabase databases and dashboards, allowing users to list and execute queries, access data visualizations, and interact with database resources through natural language.Last updated -71
- -securityFlicense-qualityEnables AI assistants to interact with Metabase, providing access to dashboards, questions, databases, and tools for executing queries and viewing data through natural language.
- -securityFlicense-qualityA Model Context Protocol server that integrates with Supabase, allowing AI assistants to access and manipulate store data through tools for product searching, filtering, and analysis.
- AsecurityAlicenseAqualityAI-powered code assistant that provides advanced search and discovery capabilities across GitHub and NPM ecosystems, helping users understand code patterns, implementations, and connections between repositories.Last updated -10526494TypeScriptMIT License