Supabase MCP Server 精选
这个服务器通过 MCP 协议实现与 Supabase PostgreSQL 数据库的交互,从而能够与 Cursor 和 Windsurf IDE 无缝集成,以进行安全且经过验证的数据库管理。
Tools
get_schemas
List all database schemas with their sizes and table counts.
get_table_schema
Get detailed table structure including columns, keys, and relationships. Returns comprehensive information about a specific table's structure: - Column definitions (names, types, constraints) - Primary key information - Foreign key relationships - Indexes - Constraints - Triggers Parameters: - schema_name: Name of the schema (e.g., 'public', 'auth') - table: Name of the table to inspect SAFETY: This is a low-risk read operation that can be executed in SAFE mode.
execute_postgresql
Execute PostgreSQL statements against your Supabase database. IMPORTANT: All SQL statements must end with a semicolon (;). OPERATION TYPES AND REQUIREMENTS: 1. READ Operations (SELECT, EXPLAIN, etc.): - Can be executed directly without special requirements - Example: SELECT * FROM public.users LIMIT 10; 2. WRITE Operations (INSERT, UPDATE, DELETE): - Require UNSAFE mode (use live_dangerously('database', True) first) - Example: INSERT INTO public.users (email) VALUES ('user@example.com'); 3. SCHEMA Operations (CREATE, ALTER, DROP): - Require UNSAFE mode (use live_dangerously('database', True) first) - Destructive operations (DROP, TRUNCATE) require additional confirmation - Example: CREATE TABLE public.test_table (id SERIAL PRIMARY KEY, name TEXT); MIGRATION HANDLING: All queries that modify the database will be automatically version controlled by the server. You can provide optional migration name, if you want to name the migration. - Respect the following format: verb_noun_detail. Be descriptive and concise. - Examples: - create_users_table - add_email_to_profiles - enable_rls_on_users - If you don't provide a migration name, the server will generate one based on the SQL statement - The system will sanitize your provided name to ensure compatibility with database systems - Migration names are prefixed with a timestamp in the format YYYYMMDDHHMMSS SAFETY SYSTEM: Operations are categorized by risk level: - LOW RISK: Read operations (SELECT, EXPLAIN) - allowed in SAFE mode - MEDIUM RISK: Write operations (INSERT, UPDATE, DELETE) - require UNSAFE mode - HIGH RISK: Schema operations (CREATE, ALTER) - require UNSAFE mode - EXTREME RISK: Destructive operations (DROP, TRUNCATE) - require UNSAFE mode and confirmation TRANSACTION HANDLING: - DO NOT use transaction control statements (BEGIN, COMMIT, ROLLBACK) - The database client automatically wraps queries in transactions - The SQL validator will reject queries containing transaction control statements - This ensures atomicity and provides rollback capability for data modifications MULTIPLE STATEMENTS: - You can send multiple SQL statements in a single query - Each statement will be executed in order within the same transaction - Example: CREATE TABLE public.test_table (id SERIAL PRIMARY KEY, name TEXT); INSERT INTO public.test_table (name) VALUES ('test'); CONFIRMATION FLOW FOR HIGH-RISK OPERATIONS: - High-risk operations (DROP TABLE, TRUNCATE, etc.) will be rejected with a confirmation ID - The error message will explain what happened and provide a confirmation ID - Review the risks with the user before proceeding - Use the confirm_destructive_operation tool with the provided ID to execute the operation IMPORTANT GUIDELINES: - The database client starts in SAFE mode by default for safety - Only enable UNSAFE mode when you need to modify data or schema - Never mix READ and WRITE operations in the same transaction - For destructive operations, be prepared to confirm with the confirm_destructive_operation tool WHEN TO USE OTHER TOOLS INSTEAD: - For Auth operations (users, authentication, etc.): Use call_auth_admin_method instead of direct SQL The Auth Admin SDK provides safer, validated methods for user management - For project configuration, functions, storage, etc.: Use send_management_api_request The Management API handles Supabase platform features that aren't directly in the database Note: This tool operates on the PostgreSQL database only. API operations use separate safety controls.
get_tables
List all tables, foreign tables, and views in a schema with their sizes, row counts, and metadata. Provides detailed information about all database objects in the specified schema: - Table/view names - Object types (table, view, foreign table) - Row counts - Size on disk - Column counts - Index information - Last vacuum/analyze times Parameters: - schema_name: Name of the schema to inspect (e.g., 'public', 'auth', etc.) SAFETY: This is a low-risk read operation that can be executed in SAFE mode.
retrieve_migrations
Retrieve a list of all migrations a user has from Supabase. Returns a list of migrations with the following information: - Version (timestamp) - Name - SQL statements (if requested) - Statement count - Version type (named or numbered) Parameters: - limit: Maximum number of migrations to return (default: 50, max: 100) - offset: Number of migrations to skip for pagination (default: 0) - name_pattern: Optional pattern to filter migrations by name. Uses SQL ILIKE pattern matching (case-insensitive). The pattern is automatically wrapped with '%' wildcards, so "users" will match "create_users_table", "add_email_to_users", etc. To search for an exact match, use the complete name. - include_full_queries: Whether to include the full SQL statements in the result (default: false) SAFETY: This is a low-risk read operation that can be executed in SAFE mode.
send_management_api_request
Execute a Supabase Management API request. This tool allows you to make direct calls to the Supabase Management API, which provides programmatic access to manage your Supabase project settings, resources, and configurations. REQUEST FORMATTING: - Use paths exactly as defined in the API specification - The {ref} parameter will be automatically injected from settings - Format request bodies according to the API specification PARAMETERS: - method: HTTP method (GET, POST, PUT, PATCH, DELETE) - path: API path (e.g. /v1/projects/{ref}/functions) - path_params: Path parameters as dict (e.g. {"function_slug": "my-function"}) - use empty dict {} if not needed - request_params: Query parameters as dict (e.g. {"key": "value"}) - use empty dict {} if not needed - request_body: Request body as dict (e.g. {"name": "test"}) - use empty dict {} if not needed PATH PARAMETERS HANDLING: - The {ref} placeholder (project reference) is automatically injected - you don't need to provide it - All other path placeholders must be provided in the path_params dictionary - Common placeholders include: * {function_slug}: For Edge Functions operations * {id}: For operations on specific resources (API keys, auth providers, etc.) * {slug}: For organization operations * {branch_id}: For database branch operations * {provider_id}: For SSO provider operations * {tpa_id}: For third-party auth operations EXAMPLES: 1. GET request with path and query parameters: method: "GET" path: "/v1/projects/{ref}/functions/{function_slug}" path_params: {"function_slug": "my-function"} request_params: {"version": "1"} request_body: {} 2. POST request with body: method: "POST" path: "/v1/projects/{ref}/functions" path_params: {} request_params: {} request_body: {"name": "test-function", "slug": "test-function"} SAFETY SYSTEM: API operations are categorized by risk level: - LOW RISK: Read operations (GET) - allowed in SAFE mode - MEDIUM/HIGH RISK: Write operations (POST, PUT, PATCH, DELETE) - require UNSAFE mode - EXTREME RISK: Destructive operations - require UNSAFE mode and confirmation - BLOCKED: Some operations are completely blocked for safety reasons SAFETY CONSIDERATIONS: - By default, the API client starts in SAFE mode, allowing only read operations - To perform write operations, first use live_dangerously(service="api", enable=True) - High-risk operations will be rejected with a confirmation ID - Use confirm_destructive_operation with the provided ID after reviewing risks - Some operations may be completely blocked for safety reasons For a complete list of available API endpoints and their parameters, use the get_management_api_spec tool. For details on safety rules, use the get_management_api_safety_rules tool.
get_management_api_spec
Get the complete Supabase Management API specification. Returns the full OpenAPI specification for the Supabase Management API, including: - All available endpoints and operations - Required and optional parameters for each operation - Request and response schemas - Authentication requirements - Safety information for each operation This tool can be used in four different ways: 1. Without parameters: Returns all domains (default) 2. With path and method: Returns the full specification for a specific API endpoint 3. With domain only: Returns all paths and methods within that domain 4. With all_paths=True: Returns all paths and methods Parameters: - params: Dictionary containing optional parameters: - path: Optional API path (e.g., "/v1/projects/{ref}/functions") - method: Optional HTTP method (e.g., "GET", "POST") - domain: Optional domain/tag name (e.g., "Auth", "Storage") - all_paths: Optional boolean, if True returns all paths and methods Available domains: - Analytics: Analytics-related endpoints - Auth: Authentication and authorization endpoints - Database: Database management endpoints - Domains: Custom domain configuration endpoints - Edge Functions: Serverless function management endpoints - Environments: Environment configuration endpoints - OAuth: OAuth integration endpoints - Organizations: Organization management endpoints - Projects: Project management endpoints - Rest: RESTful API endpoints - Secrets: Secret management endpoints - Storage: Storage management endpoints This specification is useful for understanding: - What operations are available through the Management API - How to properly format requests for each endpoint - Which operations require unsafe mode - What data structures to expect in responses SAFETY: This is a low-risk read operation that can be executed in SAFE mode.
get_auth_admin_methods_spec
Get Python SDK methods specification for Auth Admin. Returns a comprehensive dictionary of all Auth Admin methods available in the Supabase Python SDK, including: - Method names and descriptions - Required and optional parameters for each method - Parameter types and constraints - Return value information This tool is useful for exploring the capabilities of the Auth Admin SDK and understanding how to properly format parameters for the call_auth_admin_method tool. No parameters required.
call_auth_admin_method
Call an Auth Admin method from Supabase Python SDK. This tool provides a safe, validated interface to the Supabase Auth Admin SDK, allowing you to: - Manage users (create, update, delete) - List and search users - Generate authentication links - Manage multi-factor authentication - And more IMPORTANT NOTES: - Request bodies must adhere to the Python SDK specification - Some methods may have nested parameter structures - The tool validates all parameters against Pydantic models - Extra fields not defined in the models will be rejected AVAILABLE METHODS: - get_user_by_id: Retrieve a user by their ID - list_users: List all users with pagination - create_user: Create a new user - delete_user: Delete a user by their ID - invite_user_by_email: Send an invite link to a user's email - generate_link: Generate an email link for various authentication purposes - update_user_by_id: Update user attributes by ID - delete_factor: Delete a factor on a user EXAMPLES: 1. Get user by ID: method: "get_user_by_id" params: {"uid": "user-uuid-here"} 2. Create user: method: "create_user" params: { "email": "user@example.com", "password": "secure-password" } 3. Update user by ID: method: "update_user_by_id" params: { "uid": "user-uuid-here", "attributes": { "email": "new@email.com" } } For complete documentation of all methods and their parameters, use the get_auth_admin_methods_spec tool.
live_dangerously
Toggle unsafe mode for either Management API or Database operations. WHAT THIS TOOL DOES: This tool switches between safe (default) and unsafe operation modes for either the Management API or Database operations. SAFETY MODES EXPLAINED: 1. Database Safety Modes: - SAFE mode (default): Only low-risk operations like SELECT queries are allowed - UNSAFE mode: Higher-risk operations including INSERT, UPDATE, DELETE, and schema changes are permitted 2. API Safety Modes: - SAFE mode (default): Only low-risk operations that don't modify state are allowed - UNSAFE mode: Higher-risk state-changing operations are permitted (except those explicitly blocked for safety) OPERATION RISK LEVELS: The system categorizes operations by risk level: - LOW: Safe read operations with minimal impact - MEDIUM: Write operations that modify data but don't change structure - HIGH: Operations that modify database structure or important system settings - EXTREME: Destructive operations that could cause data loss or service disruption WHEN TO USE THIS TOOL: - Use this tool BEFORE attempting write operations or schema changes - Enable unsafe mode only when you need to perform data modifications - Always return to safe mode after completing write operations USAGE GUIDELINES: - Start in safe mode by default for exploration and analysis - Switch to unsafe mode only when you need to make changes - Be specific about which service you're enabling unsafe mode for - Consider the risks before enabling unsafe mode, especially for database operations - For database operations requiring schema changes, you'll need to enable unsafe mode first Parameters: - service: Which service to toggle ("api" or "database") - enable_unsafe_mode: True to enable unsafe mode, False for safe mode (default: False) Examples: 1. Enable database unsafe mode: live_dangerously(service="database", enable_unsafe_mode=True) 2. Return to safe mode after operations: live_dangerously(service="database", enable_unsafe_mode=False) 3. Enable API unsafe mode: live_dangerously(service="api", enable_unsafe_mode=True) Note: This tool affects ALL subsequent operations for the specified service until changed again.
confirm_destructive_operation
Execute a destructive database or API operation after confirmation. Use this only after reviewing the risks with the user. HOW IT WORKS: - This tool executes a previously rejected high-risk operation using its confirmation ID - The operation will be exactly the same as the one that generated the ID - No need to retype the query or api request params - the system remembers it STEPS: 1. Explain the risks to the user and get their approval 2. Use this tool with the confirmation ID from the error message 3. The original query will be executed as-is PARAMETERS: - operation_type: Type of operation ("api" or "database") - confirmation_id: The ID provided in the error message (required) - user_confirmation: Set to true to confirm execution (default: false) NOTE: Confirmation IDs expire after 5 minutes for security
README
Query | Supabase 的 MCP 服务器
<p align="center"> <a href="https://thequery.dev"><img src="https://github.com/user-attachments/assets/7e9c49b5-e784-4e70-b39e-7410c22da066" alt="使用自然语言控制 Supabase" width="800" /></a> </p>
<p align="center"> <strong>Query MCP 是一个开源的 MCP 服务器,让你的 IDE 可以安全地运行 SQL,管理模式更改,调用 Supabase Management API,并使用 Auth Admin SDK — 所有这些都内置了安全控制。</strong> </p>
<p align="center"> ⚡ 永久免费和开源。 💎 高级功能即将推出。 🧪 抢先体验版已在 <a href="https://thequery.dev">thequery.dev</a> 上线。 📢 在 GitHub issues 上或通过 feedback@thequery.dev 分享您的反馈。 </p> <p>
<p align="center"> <a href="https://pypi.org/project/supabase-mcp-server/"><img src="https://img.shields.io/pypi/v/supabase-mcp-server.svg" alt="PyPI 版本" /></a> <a href="https://github.com/alexander-zuev/supabase-mcp-server/actions"><img src="https://github.com/alexander-zuev/supabase-mcp-server/workflows/CI/badge.svg" alt="CI 状态" /></a> <a href="https://codecov.io/gh/alexander-zuev/supabase-mcp-server"><img src="https://codecov.io/gh/alexander-zuev/supabase-mcp-server/branch/main/graph/badge.svg" alt="代码覆盖率" /></a> <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.12%2B-blue.svg" alt="Python 3.12+" /></a> <a href="https://github.com/astral-sh/uv"><img src="https://img.shields.io/badge/uv-package%20manager-blueviolet" alt="uv 包管理器" /></a> <a href="https://pepy.tech/project/supabase-mcp-server"><img src="https://static.pepy.tech/badge/supabase-mcp-server" alt="PyPI 下载量" /></a> <a href="https://smithery.ai/server/@alexander-zuev/supabase-mcp-server"><img src="https://smithery.ai/badge/@alexander-zuev/supabase-mcp-server" alt="Smithery.ai 下载量" /></a> <a href="https://modelcontextprotocol.io/introduction"><img src="https://img.shields.io/badge/MCP-Server-orange" alt="MCP 服务器" /></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="许可证" /></a> </p>
目录
<p align="center"> <a href="#getting-started">开始使用</a> • <a href="#feature-overview">功能概述</a> • <a href="#troubleshooting">问题排查</a> • <a href="#changelog">更新日志</a> </p>
✨ 主要功能
- 💻 兼容 Cursor、Windsurf、Cline 和其他支持
stdio
协议的 MCP 客户端 - 🔐 控制 SQL 查询执行的只读和读写模式
- 🔍 运行时 SQL 查询验证,并进行风险等级评估
- 🛡️ 用于 SQL 操作的三层安全系统:安全、写入和破坏性
- 🔄 强大的事务处理,适用于直接和池化数据库连接
- 📝 数据库模式更改的自动版本控制
- 💻 使用 Supabase Management API 管理您的 Supabase 项目
- 🧑💻 通过 Python SDK 使用 Supabase Auth Admin 方法管理用户
- 🔨 预构建的工具,可帮助 Cursor 和 Windsurf 更有效地使用 MCP
- 📦 通过包管理器(uv、pipx 等)进行极其简单的安装和设置
开始使用
前提条件
安装服务器需要在您的系统上安装以下内容:
- Python 3.12+
如果您计划通过 uv
安装,请确保已安装。
PostgreSQL 安装
MCP 服务器本身不再需要 PostgreSQL 安装,因为它现在使用 asyncpg,而 asyncpg 不依赖于 PostgreSQL 开发库。
但是,如果您运行本地 Supabase 实例,您仍然需要 PostgreSQL:
MacOS
brew install postgresql@16
Windows
- 从 https://www.postgresql.org/download/windows/ 下载并安装 PostgreSQL 16+
- 确保在安装过程中选择“PostgreSQL Server”和“Command Line Tools”
步骤 1. 安装
自 v0.2.0 起,我引入了对包安装的支持。您可以使用您喜欢的 Python 包管理器通过以下方式安装服务器:
# 如果已安装 pipx(推荐)
pipx install supabase-mcp-server
# 如果已安装 uv
uv pip install supabase-mcp-server
建议使用 pipx
,因为它为每个包创建隔离的环境。
您还可以通过克隆存储库并从根目录运行 pipx install -e .
来手动安装服务器。
从源代码安装
如果您想从源代码安装,例如用于本地开发:
uv venv
# 在 Mac 上
source .venv/bin/activate
# 在 Windows 上
.venv\Scripts\activate
# 以可编辑模式安装包
uv pip install -e .
通过 Smithery.ai 安装
您可以在此处找到有关如何使用 Smithery.ai 连接到此 MCP 服务器的完整说明。
步骤 2. 配置
Supabase MCP 服务器需要配置才能连接到您的 Supabase 数据库,访问 Management API,并使用 Auth Admin SDK。本节介绍所有可用的配置选项以及如何设置它们。
🔑 重要提示:自 v0.4 起,MCP 服务器需要一个 API 密钥,您可以在 thequery.dev 免费获取该密钥才能使用此 MCP 服务器。
环境变量
服务器使用以下环境变量:
变量 | 是否必需 | 默认值 | 描述 |
---|---|---|---|
SUPABASE_PROJECT_REF |
是 | 127.0.0.1:54322 |
您的 Supabase 项目引用 ID(或本地主机:端口) |
SUPABASE_DB_PASSWORD |
是 | postgres |
您的数据库密码 |
SUPABASE_REGION |
是* | us-east-1 |
您的 Supabase 项目托管的 AWS 区域 |
SUPABASE_ACCESS_TOKEN |
否 | None | Supabase Management API 的个人访问令牌 |
SUPABASE_SERVICE_ROLE_KEY |
否 | None | Auth Admin SDK 的服务角色密钥 |
QUERY_API_KEY |
是 | None | 来自 thequery.dev 的 API 密钥(所有操作都需要) |
注意:默认值配置为本地 Supabase 开发。对于远程 Supabase 项目,您必须为
SUPABASE_PROJECT_REF
和SUPABASE_DB_PASSWORD
提供您自己的值。
🚨 关键配置说明:对于远程 Supabase 项目,您必须使用
SUPABASE_REGION
指定您的项目托管的正确区域。如果您遇到“找不到租户或用户”错误,则几乎可以肯定是因为您的区域设置与项目的实际区域不匹配。您可以在 Supabase 仪表板的项目设置下找到您的项目区域。
连接类型
数据库连接
- 服务器使用事务池连接点连接到您的 Supabase PostgreSQL 数据库
- 本地开发使用与
127.0.0.1:54322
的直接连接 - 远程项目使用以下格式:
postgresql://postgres.[project_ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
⚠️ 重要提示:不支持会话池连接。服务器专门使用事务池,以便更好地与 MCP 服务器架构兼容。
Management API 连接
- 需要设置
SUPABASE_ACCESS_TOKEN
- 连接到
https://api.supabase.com
上的 Supabase Management API - 仅适用于远程 Supabase 项目(不适用于本地开发)
Auth Admin SDK 连接
- 需要设置
SUPABASE_SERVICE_ROLE_KEY
- 对于本地开发,连接到
http://127.0.0.1:54321
- 对于远程项目,连接到
https://[project_ref].supabase.co
配置方法
服务器按以下顺序查找配置(优先级从高到低):
- 环境变量:直接在您的环境中设置的值
- 本地
.env
文件:当前工作目录中的.env
文件(仅在从源代码运行时有效) - 全局配置文件:
- Windows:
%APPDATA%\supabase-mcp\.env
- macOS/Linux:
~/.config/supabase-mcp/.env
- Windows:
- 默认设置:本地开发默认值(如果未找到其他配置)
⚠️ 重要提示:当使用通过 pipx 或 uv 安装的包时,不会检测到项目目录中的本地
.env
文件。您必须使用环境变量或全局配置文件。
设置配置
选项 1:客户端特定配置(推荐)
直接在您的 MCP 客户端配置中设置环境变量(请参阅步骤 3 中的客户端特定设置说明)。大多数 MCP 客户端都支持此方法,该方法可将您的配置与您的客户端设置保持一致。
选项 2:全局配置
创建一个全局 .env
配置文件,该文件将用于所有 MCP 服务器实例:
# 创建配置目录
# 在 macOS/Linux 上
mkdir -p ~/.config/supabase-mcp
# 在 Windows 上 (PowerShell)
mkdir -Force "$env:APPDATA\supabase-mcp"
# 创建并编辑 .env 文件
# 在 macOS/Linux 上
nano ~/.config/supabase-mcp/.env
# 在 Windows 上 (PowerShell)
notepad "$env:APPDATA\supabase-mcp\.env"
将您的配置值添加到文件中:
QUERY_API_KEY=your-api-key
SUPABASE_PROJECT_REF=your-project-ref
SUPABASE_DB_PASSWORD=your-db-password
SUPABASE_REGION=us-east-1
SUPABASE_ACCESS_TOKEN=your-access-token
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
选项 3:项目特定配置(仅限源代码安装)
如果您从源代码运行服务器(而不是通过包),您可以在您的项目目录中创建一个 .env
文件,其格式与上述相同。
查找您的 Supabase 项目信息
- 项目引用:在您的 Supabase 项目 URL 中找到:
https://supabase.com/dashboard/project/<project-ref>
- 数据库密码:在项目创建期间设置或在项目设置 → 数据库中找到
- 访问令牌:在 https://supabase.com/dashboard/account/tokens 生成
- 服务角色密钥:在项目设置 → API → 项目 API 密钥中找到
支持的区域
服务器支持所有 Supabase 区域:
us-west-1
- 美国西部(北加利福尼亚)us-east-1
- 美国东部(北弗吉尼亚)- 默认us-east-2
- 美国东部(俄亥俄州)ca-central-1
- 加拿大(中部)eu-west-1
- 欧盟西部(爱尔兰)eu-west-2
- 欧洲西部(伦敦)eu-west-3
- 欧盟西部(巴黎)eu-central-1
- 欧盟中部(法兰克福)eu-central-2
- 欧洲中部(苏黎世)eu-north-1
- 欧盟北部(斯德哥尔摩)ap-south-1
- 南亚(孟买)ap-southeast-1
- 东南亚(新加坡)ap-northeast-1
- 东北亚(东京)ap-northeast-2
- 东北亚(首尔)ap-southeast-2
- 大洋洲(悉尼)sa-east-1
- 南美洲(圣保罗)
限制
- 不支持自托管:服务器仅支持官方 Supabase.com 托管的项目和本地开发
- 不支持连接字符串:不支持自定义连接字符串
- 没有会话池:数据库连接仅支持事务池
- API 和 SDK 功能:Management API 和 Auth Admin SDK 功能仅适用于远程 Supabase 项目,不适用于本地开发
步骤 3. 用法
通常,任何支持 stdio
协议的 MCP 客户端都应与此 MCP 服务器一起使用。此服务器经过明确测试,可与以下工具一起使用:
- Cursor
- Windsurf
- Cline
- Claude Desktop
此外,您还可以使用 smithery.ai 在许多客户端中安装此服务器,包括上述客户端。
按照以下指南在您的客户端中安装此 MCP 服务器。
Cursor
转到 Settings -> Features -> MCP Servers 并添加一个具有以下配置的新服务器:
# 可以设置为任何名称
name: supabase
type: command
# 如果您使用 pipx 安装
command: supabase-mcp-server
# 如果您使用 uv 安装
command: uv run supabase-mcp-server
# 如果以上方法不起作用,请使用完整路径(推荐)
command: /full/path/to/supabase-mcp-server # 使用 'which supabase-mcp-server' (macOS/Linux) 或 'where supabase-mcp-server' (Windows) 查找
如果配置正确,您应该会看到一个绿色圆点指示器以及服务器公开的工具数量。
Windsurf
转到 Cascade -> 单击锤子图标 -> Configure -> 填写配置:
{
"mcpServers": {
"supabase": {
"command": "/Users/username/.local/bin/supabase-mcp-server", // 更新路径
"env": {
"QUERY_API_KEY": "your-api-key", // 必需 - 在 thequery.dev 获取您的 API 密钥
"SUPABASE_PROJECT_REF": "your-project-ref",
"SUPABASE_DB_PASSWORD": "your-db-password",
"SUPABASE_REGION": "us-east-1", // 可选,默认为 us-east-1
"SUPABASE_ACCESS_TOKEN": "your-access-token", // 可选,用于 Management API
"SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key" // 可选,用于 Auth Admin SDK
}
}
}
}
如果配置正确,您应该会看到绿色圆点指示器以及可用服务器列表中的可单击的 supabase 服务器。
Claude Desktop
Claude Desktop 还通过 JSON 配置支持 MCP 服务器。按照以下步骤设置 Supabase MCP 服务器:
-
找到可执行文件的完整路径(此步骤至关重要):
# 在 macOS/Linux 上 which supabase-mcp-server # 在 Windows 上 where supabase-mcp-server
复制返回的完整路径(例如,
/Users/username/.local/bin/supabase-mcp-server
)。 -
在 Claude Desktop 中配置 MCP 服务器:
- 打开 Claude Desktop
- 转到 Settings → Developer -> Edit Config MCP Servers
- 添加一个具有以下 JSON 的新配置:
{ "mcpServers": { "supabase": { "command": "/full/path/to/supabase-mcp-server", // 替换为步骤 1 中的实际路径 "env": { "QUERY_API_KEY": "your-api-key", // 必需 - 在 thequery.dev 获取您的 API 密钥 "SUPABASE_PROJECT_REF": "your-project-ref", "SUPABASE_DB_PASSWORD": "your-db-password", "SUPABASE_REGION": "us-east-1", // 可选,默认为 us-east-1 "SUPABASE_ACCESS_TOKEN": "your-access-token", // 可选,用于 Management API "SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key" // 可选,用于 Auth Admin SDK } } } }
⚠️ 重要提示:与 Windsurf 和 Cursor 不同,Claude Desktop 需要可执行文件的完整绝对路径。仅使用命令名称 (
supabase-mcp-server
) 将导致“spawn ENOENT”错误。
如果配置正确,您应该会在 Claude Desktop 中看到 Supabase MCP 服务器列为可用。
Cline
Cline 还通过类似的 JSON 配置支持 MCP 服务器。按照以下步骤设置 Supabase MCP 服务器:
-
找到可执行文件的完整路径(此步骤至关重要):
# 在 macOS/Linux 上 which supabase-mcp-server # 在 Windows 上 where supabase-mcp-server
复制返回的完整路径(例如,
/Users/username/.local/bin/supabase-mcp-server
)。 -
在 Cline 中配置 MCP 服务器:
- 在 VS Code 中打开 Cline
- 单击 Cline 侧栏中的“MCP Servers”选项卡
- 单击“Configure MCP Servers”
- 这将打开
cline_mcp_settings.json
文件 - 添加以下配置:
{ "mcpServers": { "supabase": { "command": "/full/path/to/supabase-mcp-server", // 替换为步骤 1 中的实际路径 "env": { "QUERY_API_KEY": "your-api-key", // 必需 - 在 thequery.dev 获取您的 API 密钥 "SUPABASE_PROJECT_REF": "your-project-ref", "SUPABASE_DB_PASSWORD": "your-db-password", "SUPABASE_REGION": "us-east-1", // 可选,默认为 us-east-1 "SUPABASE_ACCESS_TOKEN": "your-access-token", // 可选,用于 Management API "SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key" // 可选,用于 Auth Admin SDK } } } }
如果配置正确,您应该会在 Cline MCP Servers 列表中看到 Supabase MCP 服务器旁边的绿色指示器,并且在面板底部会看到一条消息,确认“supabase MCP server connected”。
问题排查
以下是一些可能对您有所帮助的提示和技巧:
- 调试安装 - 直接从终端运行
supabase-mcp-server
以查看它是否有效。如果无效,则可能是安装有问题。 - MCP 服务器配置 - 如果上述步骤有效,则表示服务器已正确安装和配置。只要您提供了正确的命令,IDE 应该能够连接。确保提供服务器可执行文件的正确路径。
- “未找到工具”错误 - 如果您在 Cursor 中看到“Client closed - no tools available”,即使已安装该软件包:
- 通过运行
which supabase-mcp-server
(macOS/Linux) 或where supabase-mcp-server
(Windows) 找到可执行文件的完整路径 - 在您的 MCP 服务器配置中使用完整路径,而不仅仅是
supabase-mcp-server
- 例如:
/Users/username/.local/bin/supabase-mcp-server
或C:\Users\username\.local\bin\supabase-mcp-server.exe
- 通过运行
- 环境变量 - 要连接到正确的数据库,请确保您在
mcp_config.json
中或放置在全局配置目录中的.env
文件中设置了 env 变量(macOS/Linux 上为~/.config/supabase-mcp/.env
,Windows 上为%APPDATA%\supabase-mcp\.env
)。 - 访问日志 - MCP 服务器将详细日志写入文件:
- 日志文件位置:
- macOS/Linux:
~/.local/share/supabase-mcp/mcp_server.log
- Windows:
%USERPROFILE%\.local\share\supabase-mcp\mcp_server.log
- macOS/Linux:
- 日志包括连接状态、配置详细信息和操作结果
- 使用任何文本编辑器或终端命令查看日志:
# 在 macOS/Linux 上 cat ~/.local/share/supabase-mcp/mcp_server.log # 在 Windows 上 (PowerShell) Get-Content "$env:USERPROFILE\.local\share\supabase-mcp\mcp_server.log"
- 日志文件位置:
如果您遇到问题或上述任何说明不正确,请提出 issue。
MCP Inspector
MCP Inspector 是一个非常有用的工具,可帮助调试 MCP 服务器问题。如果您从源代码安装,您可以从项目存储库运行 supabase-mcp-inspector
,它将运行 inspector 实例。与日志结合使用,这将为您提供服务器中发生情况的完整概述。
📝 如果从包安装,运行
supabase-mcp-inspector
无法正常工作 - 我将在即将发布的版本中验证并修复。
功能概述
数据库查询工具
自 v0.3+ 起,服务器提供全面的数据库管理功能,并内置安全控制:
-
SQL 查询执行:执行 PostgreSQL 查询,并进行风险评估
- 三层安全系统:
safe
:只读操作 (SELECT) - 始终允许write
:数据修改 (INSERT, UPDATE, DELETE) - 需要不安全模式destructive
:模式更改 (DROP, CREATE) - 需要不安全模式 + 确认
- 三层安全系统:
-
SQL 解析和验证:
- 使用 PostgreSQL 的解析器 (pglast) 进行准确分析,并提供有关安全要求的明确反馈
-
自动迁移版本控制:
- 更改数据库的操作会自动进行版本控制
- 根据操作类型和目标生成描述性名称
-
安全控制:
- 默认 SAFE 模式仅允许只读操作
- 所有语句都通过
asyncpg
在事务模式下运行 - 对高风险操作进行 2 步确认
-
可用工具:
get_schemas
:列出具有大小和表计数的模式get_tables
:列出具有元数据的表、外部表和视图get_table_schema
:获取详细的表结构(列、键、关系)execute_postgresql
:针对您的数据库执行 SQL 语句confirm_destructive_operation
:在确认后执行高风险操作retrieve_migrations
:获取具有筛选和分页选项的迁移live_dangerously
:在安全模式和不安全模式之间切换
Management API 工具
自 v0.3.0 起,服务器提供对 Supabase Management API 的安全访问,并内置安全控制:
-
可用工具:
send_management_api_request
:将任意请求发送到 Supabase Management API,并自动注入项目引用get_management_api_spec
:获取具有安全信息的丰富 API 规范- 支持多种查询模式:按域、按特定路径/方法或所有路径
- 包括每个端点的风险评估信息
- 提供详细的参数要求和响应格式
- 帮助 LLM 了解 Supabase Management API 的全部功能
get_management_api_safety_rules
:获取所有具有人类可读解释的安全规则live_dangerously
:在安全和不安全操作模式之间切换
-
安全控制:
- 使用与数据库操作相同的安全管理器进行一致的风险管理
- 操作按风险级别分类:
safe
:只读操作 (GET) - 始终允许unsafe
:更改状态的操作 (POST, PUT, PATCH, DELETE) - 需要不安全模式blocked
:破坏性操作(删除项目等)- 永远不允许
- 默认安全模式可防止意外的状态更改
- 基于路径的模式匹配,用于精确的安全规则
注意:Management API 工具仅适用于远程 Supabase 实例,并且与本地 Supabase 开发设置不兼容。
Auth Admin 工具
我计划向 MCP 服务器添加对 Python SDK 方法的支持。经过考虑,我决定仅添加对 Auth 管理员方法的支持,因为我经常发现自己手动创建测试用户,这很容易出错且耗时。现在,我可以要求 Cursor 创建一个测试用户,并且可以无缝完成。查看完整的 Auth Admin SDK 方法文档,了解它可以做什么。
自 v0.3.6 起,服务器支持通过 Python SDK 直接访问 Supabase Auth Admin 方法:
- 包括以下工具:
get_auth_admin_methods_spec
用于检索所有可用 Auth Admin 方法的文档call_auth_admin_method
用于直接调用 Auth Admin 方法,并进行正确的参数处理
- 支持的方法:
get_user_by_id
:按 ID 检索用户list_users
:列出所有用户,并进行分页create_user
:创建新用户delete_user
:按 ID 删除用户invite_user_by_email
:将邀请链接发送到用户的电子邮件generate_link
:生成用于各种身份验证目的的电子邮件链接update_user_by_id
:按 ID 更新用户属性delete_factor
:删除用户上的因子(当前未在 SDK 中实现)
为什么使用 Auth Admin SDK 而不是原始 SQL 查询?
Auth Admin SDK 提供了优于直接 SQL 操作的几个关键优势:
-
功能:启用仅使用 SQL 无法实现的操作(邀请、魔法链接、MFA)
-
准确性:比在 auth 模式上创建和执行原始 SQL 查询更可靠
-
简单性:提供具有正确验证和错误处理的清晰方法
- 响应格式:
- 所有方法都返回结构化的 Python 对象,而不是原始字典
- 可以使用点表示法访问对象属性(例如,
user.id
而不是user["id"]
)
- 边缘情况和限制:
- UUID 验证:许多方法都需要用户 ID 的有效 UUID 格式,并且会返回特定的验证错误
- 电子邮件配置:
invite_user_by_email
和generate_link
等方法需要在您的 Supabase 项目中配置电子邮件发送 - 链接类型:生成链接时,不同的链接类型具有不同的要求:
signup
链接不需要用户存在magiclink
和recovery
链接需要用户已存在于系统中
- 错误处理:服务器提供来自 Supabase API 的详细错误消息,这些消息可能与仪表板界面不同
- 方法可用性:某些方法(如
delete_factor
)在 API 中公开,但未在 SDK 中完全实现
- 响应格式:
日志和分析
服务器提供对 Supabase 日志和分析数据的访问,从而更容易监控和排除应用程序故障:
-
可用工具:
retrieve_logs
- 访问来自任何 Supabase 服务的日志 -
日志集合:
postgres
:数据库服务器日志api_gateway
:API 网关请求auth
:身份验证事件postgrest
:RESTful API 服务日志pooler
:连接池日志storage
:对象存储操作realtime
:WebSocket 订阅日志edge_functions
:无服务器函数执行cron
:计划作业日志pgbouncer
:连接池日志
-
功能:按时间筛选、搜索文本、应用字段筛选器或使用自定义 SQL 查询
简化了跨 Supabase 堆栈的调试,而无需在界面之间切换或编写复杂的查询。
数据库更改的自动版本控制
“能力越大,责任越大。” 虽然 execute_postgresql
工具与恰当命名的 live_dangerously
工具相结合,提供了一种强大而简单的方式来管理您的 Supabase 数据库,但这也意味着删除表或修改表只需一条聊天消息即可完成。为了降低不可逆转更改的风险,自 v0.3.8 起,服务器支持:
- 自动创建迁移脚本,用于对数据库执行的所有写入和破坏性 sql 操作
- 改进的查询执行安全模式,其中所有查询都分为以下几类:
safe
类型:始终允许。包括所有只读操作。write
类型:需要用户启用write
模式。destructive
类型:需要用户启用write
模式,并且对于不自动执行工具的客户端,需要对查询执行进行 2 步确认。
通用安全模式
自 v0.3.8 起,安全模式已使用通用安全管理器在所有服务(数据库、API、SDK)中标准化。这为整个 MCP 服务器提供了一致的风险管理和用于控制安全设置的统一界面。
所有操作(SQL 查询、API 请求、SDK 方法)都分为风险级别:
Low
风险:不修改数据或结构的只读操作(SELECT 查询、GET API 请求)Medium
风险:修改数据但不修改结构的写入操作(INSERT/UPDATE/DELETE、大多数 POST/PUT API 请求)High
风险:修改数据库结构或可能导致数据丢失的破坏性操作(DROP/TRUNCATE、DELETE API 端点)Extreme
风险:具有严重后果的操作,完全被阻止(删除项目)
安全控制基于风险级别应用:
- 始终允许低风险操作
- 中等风险操作需要启用不安全模式
- 高风险操作需要启用不安全模式和显式确认
- 永远不允许极端风险操作
确认流程如何工作
即使在 unsafe
模式下,任何高风险操作(无论是 postgresql 还是 api 请求)都将被阻止。
您必须显式确认并批准每个高风险操作才能执行它。
更新日志
- 📦 通过包管理器简化安装 - ✅ (v0.2.0)
- 🌎 支持不同的 Supabase 区域 - ✅ (v0.2.2)
- 🎮 通过安全控制以编程方式访问 Supabase 管理 API - ✅ (v0.3.0)
- 👷♂️ 通过安全控制读取和读写数据库 SQL 查询 - ✅ (v0.3.0)
- 🔄 强大的事务处理,适用于直接和池化连接 - ✅ (v0.3.2)
- 🐍 支持本机 Python SDK 中可用的方法和对象 - ✅ (v0.3.6)
- 🔍 更强大的 SQL 查询验证 ✅ (v0.3.8)
- 📝 数据库更改的自动版本控制 ✅ (v0.3.8)
- 📖 彻底改进了 api 规范的知识和工具 ✅ (v0.3.8)
- ✍️ 改进了与迁移相关的工具的一致性,以实现更有组织的数据库 vcs ✅ (v0.3.10)
- 🥳 Query MCP 已发布 (v0.4.0)
有关更详细的路线图,请参阅 GitHub 上的此讨论。
Star 历史记录
尽情享受!☺️
推荐服务器

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Neon MCP Server
MCP server for interacting with Neon Management API and databases
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
AIO-MCP Server
🚀 All-in-one MCP server with AI search, RAG, and multi-service integrations (GitLab/Jira/Confluence/YouTube) for AI-enhanced development workflows. Folk from
Knowledge Graph Memory Server
为 Claude 实现持久性记忆,使用本地知识图谱,允许 AI 记住用户的信息,并可在自定义位置存储,跨对话保持记忆。
Hyperbrowser
欢迎来到 Hyperbrowser,人工智能的互联网。Hyperbrowser 是下一代平台,旨在增强人工智能代理的能力,并实现轻松、可扩展的浏览器自动化。它专为人工智能开发者打造,消除了本地基础设施和性能瓶颈带来的麻烦,让您能够:
db-mcp-tool
一个强大的模型上下文协议(MCP)工具,用于探索和管理不同类型的数据库,包括 PostgreSQL、MySQL 和 Firestore。

any-chat-completions-mcp
将 Claude 与任何 OpenAI SDK 兼容的聊天完成 API 集成 - OpenAI、Perplexity、Groq、xAI、PyroPrompts 等。
Exa MCP Server
一个模型上下文协议服务器,它使像 Claude 这样的人工智能助手能够以安全和受控的方式,使用 Exa AI 搜索 API 执行实时网络搜索。
BigQuery MCP Server
这是一个服务器,可以让你的大型语言模型(LLM,比如Claude)直接与你的BigQuery数据对话!可以把它想象成一个友好的翻译器,它位于你的AI助手和数据库之间,确保它们可以安全高效地进行交流。