Yazdani Supabase PostgreSQL MCP server

Provides a bridge between Supabase PostgreSQL databases and natural language queries, enabling schema inspection, SQL execution, migration management, and query conversion with built-in safety controls and mock database fallback mechanisms.
Back to servers
Provider
Yazdani
Release date
Mar 24, 2025
Language
Python

This Yazdani-Supabase-MCP Server integrates with Supabase PostgreSQL and uses Claude 3.7 for natural language query processing. It enables database schema inspection, SQL execution, and translating natural language queries into SQL, all designed for seamless integration with React Native applications.

Installation

Prerequisites

  • Python 3.8 or higher
  • Access to a Supabase PostgreSQL database (optional with mock mode)
  • Anthropic API key (for Claude integration)

Setup

  1. Clone the repository:

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

    pip install -r requirements.txt
    
  3. Create a .env file with your credentials:

    # Supabase credentials
    SUPABASE_PROJECT_REF=your_project_ref
    SUPABASE_URL=https://your_project_ref.supabase.co
    SUPABASE_DB_PASSWORD=your_db_password
    SUPABASE_REGION=your_region
    SUPABASE_ACCESS_TOKEN=your_access_token
    SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
    
    # Database connection
    POSTGRES_HOST=db.your_project_ref.supabase.co
    POSTGRES_PORT=5432
    POSTGRES_DB=postgres
    POSTGRES_USER=postgres
    SUPABASE_POOLER_HOST=aws-0-ca-central-1.pooler.supabase.com
    
    # Claude API
    ANTHROPIC_API_KEY=your_anthropic_api_key
    
    # Optional: for mock database mode
    # USE_MOCK_DB=true
    
  4. Install as a package (optional):

    pip install -e .
    

Usage

Running the Server

With Live Database:

python run_server.py

With Mock Database:

# Windows
improved_mock_server.bat

# Unix/macOS
USE_MOCK_DB=true python run_server.py

As Installed Package:

yazdani-supabase-mcp-server

Testing the Connection

Verify your connection is working properly:

python connection_test.py

Natural Language Testing

Test natural language to SQL capabilities with the provided tools:

# Windows - Run the full test environment
run_nl_test.bat

# Manual setup
python http_server.py --port 8000   # Terminal 1
python nl_test_client.py            # Terminal 2

Sample Natural Language Queries

Try these examples in the natural language test client:

  • "Show me all tables in the public schema"
  • "Get all users who signed up in the last month"
  • "What is the total number of users in the database?"

Integration with React Native

Setting Up for Your App

  1. Run the server using either mock or live database mode

  2. Make the server accessible to your React Native application:

    • For local development, ensure React Native can access your local network
    • For production, host the server where it can be accessed by your app
  3. Connect from React Native using MCP client libraries, configuring with the server's address and port

Available API Endpoints

The MCP server provides these tools through the MCP protocol:

  • get_schemas: List all database schemas
  • get_tables: List tables in a schema
  • get_table_schema: Get detailed table structure
  • execute_postgresql: Execute SQL statements
  • retrieve_migrations: List database migrations
  • generate_sql: Generate SQL from natural language

Troubleshooting

Connection Format

The server uses Supabase Session pooler with this connection format:

postgresql://postgres.{project_ref}:{password}@{pooler_host}:5432/postgres

Common Connection Issues

If experiencing connection problems:

  1. Verify your Supabase project is active
  2. Check database credentials in .env file
  3. Ensure your IP address is allowed in Supabase settings
  4. Verify you're using the correct pooler host for your region
  5. Try mock database mode with USE_MOCK_DB=true
  6. Run connection tests:
    python test_pooler_connection.py
    python connection_test.py
    

Mock Database Mode Features

  • Auto-fallbacks to mock data when connection fails
  • Consistent interface between real and mock data
  • Clear indication when mock data is being used
  • Improved logging for troubleshooting

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later