Supabase MCP Server

Supabase MCP Server

Enables AI assistants to perform CRUD operations on Supabase databases through natural language. Supports advanced filtering, pagination, and safety checks for seamless database interaction.

Category
访问服务器

README

Supabase MCP Server

A Model Context Protocol (MCP) server that provides seamless integration between AI assistants and Supabase databases. This server enables LLMs to perform CRUD operations on any Supabase database through standardized, well-documented tools.

🚀 Features

  • Full CRUD Operations: Read, Create, Update, and Delete records in any Supabase table
  • Advanced Filtering: Support for complex queries with multiple filter conditions
  • Safety First: Built-in safety checks for destructive operations
  • Type Safety: Full type hints and Pydantic validation
  • Comprehensive Error Handling: Detailed error messages and logging
  • Flexible Querying: Support for pagination, ordering, and column selection
  • Upsert Support: Insert or update records in a single operation

📋 Prerequisites

  • Python 3.11 or higher
  • A Supabase project (self-hosted or cloud)
  • Supabase service role key with appropriate permissions

🛠️ Installation

  1. Clone or download the project:

    git clone <repository-url>
    cd supabase-mcp-server
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

    cp .env.example .env
    # Edit .env with your Supabase credentials
    
  4. Configure your environment: Edit the .env file with your Supabase credentials:

    SUPABASE_URL=https://your-project-id.supabase.co
    SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here
    

🔧 Configuration

Environment Variables

Edit .env file with your configuration:

# Required: Your existing Supabase instance
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here

# Optional: Server configuration
LOG_LEVEL=INFO

Finding Your Supabase Credentials

  1. Go to your Supabase project dashboard
  2. Navigate to SettingsAPI
  3. Copy the Project URL for SUPABASE_URL
  4. Copy the service_role secret for SUPABASE_SERVICE_ROLE_KEY

⚠️ Important: Use the service_role key, not the anon key, as it has full database access.

📁 GitHub Repository Setup

🔗 Complete GitHub Setup & SSH Deployment Guide

Quick setup:

  1. Create GitHub repository
  2. Push code: git init && git add . && git commit -m "Initial commit" && git push
  3. SSH deploy: git clone YOUR_REPO && cd PROJECT && ./scripts/deploy.sh

💡 SSH Quick Deploy Reference - 3-command deployment

🚀 Usage

Local Development

Running the Server

python src/server.py

The server will start with stdio transport, which is the standard for MCP servers.

Installing in Claude Desktop

  1. Add to your Claude Desktop MCP configuration:
    {
      "servers": {
        "supabase": {
          "command": "python",
          "args": ["path/to/supabase-mcp-server/src/server.py"],
          "env": {
            "SUPABASE_URL": "https://your-project-id.supabase.co",
            "SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key"
          }
        }
      }
    }
    

Using with MCP Inspector

For development and testing:

npx @modelcontextprotocol/inspector python src/server.py

🐳 Cloud Deployment

Deploy to your cloud Docker instance in minutes!

Quick Deploy (Automated)

  1. Upload files to your cloud server:

    scp -r supabase-mcp-server/ user@your-server.com:/home/user/
    
  2. SSH and deploy:

    ssh user@your-server.com
    cd supabase-mcp-server
    chmod +x scripts/deploy.sh
    ./scripts/deploy.sh
    

Manual Deploy

# Configure environment
cp .env.production .env
nano .env  # Add your Supabase credentials

# Deploy MCP server only (recommended)
docker-compose -f docker-compose.mcp-only.yml up -d

# Or deploy full stack (includes self-hosted Supabase)
docker-compose up -d

Access: Server available on port 8085

📖 Complete Deployment Guide - Includes security, monitoring, scaling, and troubleshooting

🔨 Available Tools

1. Read Table Rows

Query data from any table with filtering, ordering, and pagination.

Usage: "Show me all users where status is 'active'"

{
  "table_name": "users",
  "filters": [{"column": "status", "operator": "eq", "value": "active"}],
  "order_by": "created_at",
  "limit": 10
}

2. Create Table Records

Insert new records into any table, with optional upsert functionality.

Usage: "Create a new user with name 'John' and email 'john@example.com'"

{
  "table_name": "users",
  "records": [{"name": "John", "email": "john@example.com"}]
}

3. Update Table Records

Modify existing records based on specified conditions.

Usage: "Update the status to 'completed' for task with id 123"

{
  "table_name": "tasks",
  "set_data": {"status": "completed"},
  "where_conditions": [{"column": "id", "operator": "eq", "value": 123}]
}

4. Delete Table Records

Remove records from tables with safety checks and confirmation.

Usage: "Delete all inactive users created before 2023"

{
  "table_name": "users",
  "where_conditions": [
    {"column": "status", "operator": "eq", "value": "inactive"},
    {"column": "created_at", "operator": "lt", "value": "2023-01-01"}
  ],
  "confirm_delete": true
}

🔍 Filter Operators

The server supports various filter operators for precise querying:

Operator Description Example
eq Equal to {"column": "status", "operator": "eq", "value": "active"}
neq Not equal to {"column": "status", "operator": "neq", "value": "deleted"}
gt Greater than {"column": "age", "operator": "gt", "value": 18}
gte Greater than or equal {"column": "score", "operator": "gte", "value": 80}
lt Less than {"column": "price", "operator": "lt", "value": 100}
lte Less than or equal {"column": "discount", "operator": "lte", "value": 50}
like Pattern matching (case-sensitive) {"column": "name", "operator": "like", "value": "%john%"}
ilike Pattern matching (case-insensitive) {"column": "email", "operator": "ilike", "value": "%@gmail.com"}
in Value in list {"column": "category", "operator": "in", "value": ["tech", "science"]}
is Is null/true/false {"column": "deleted_at", "operator": "is", "value": null}

🧪 Testing

Run the test suite:

pytest tests/

Run with coverage:

pytest tests/ --cov=src

🛡️ Security Features

  • Environment Variable Validation: Ensures required credentials are set
  • Input Validation: Pydantic models validate all input data
  • Safety Checks: Requires confirmation for destructive operations
  • Where Clause Requirements: Updates and deletes require explicit conditions
  • Error Handling: Comprehensive error handling with detailed logging

📁 Project Structure

supabase-mcp-server/
├── src/
│   └── server.py           # Main MCP server implementation
├── tests/
│   └── test_server.py      # Comprehensive test suite
├── requirements.txt        # Python dependencies
├── .env.example           # Environment variables template
├── README.md              # This file
├── PLANNING.md            # Project planning and architecture
├── TASK.md               # Task breakdown and progress
└── GLOBAL_RULES.md       # Development rules and standards

🔄 Example Usage Scenarios

Scenario 1: Content Management

"Show me all published blog posts from this year, ordered by publication date"

Scenario 2: User Management

"Create a new admin user and update their permissions"

Scenario 3: Data Cleanup

"Find and delete all expired session tokens"

Scenario 4: Analytics

"Get user count by registration month for the past year"

🐛 Troubleshooting

Common Issues

  1. Environment Variables Not Set

    • Error: "Missing environment variables"
    • Solution: Ensure .env file exists with correct SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY
  2. Database Connection Failed

    • Error: "Failed to initialize Supabase client"
    • Solution: Verify your Supabase URL and service role key are correct
  3. Permission Denied

    • Error: Various permission-related errors
    • Solution: Ensure your service role key has appropriate permissions for the tables you're accessing
  4. Table Not Found

    • Error: Table-specific errors
    • Solution: Verify the table name exists in your Supabase database

📚 Development

Code Style

  • Follow PEP 8 standards
  • Use type hints for all functions
  • Include comprehensive docstrings
  • Maximum 500 lines per file

Testing Requirements

  • Minimum 95% test coverage
  • Test all CRUD operations
  • Include edge cases and error scenarios
  • Use pytest for all tests

🤝 Contributing

  1. Follow the global rules defined in GLOBAL_RULES.md
  2. Ensure all tests pass before submitting changes
  3. Update documentation for any new features
  4. Add appropriate error handling and logging

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选