airis-mcp-supabase-selfhost

airis-mcp-supabase-selfhost

MCP server for self-hosted Supabase with RLS-aware PostgreSQL and PostgREST layers, enabling safe database introspection, SQL queries, and PostgREST access via natural language.

Category
Visit Server

README

Supabase Self-hosted MCP Server

MCP (Model Context Protocol) server for self-hosted Supabase with RLS-aware PostgreSQL + PostgREST layers.


🌟 Part of the AIRIS Ecosystem

This MCP server is designed to work with the AIRIS Suite - accessible via airis-mcp-gateway for token-efficient integration.

The AIRIS Suite

Component Purpose For Who
airis-agent 🧠 Intelligence layer for all editors (confidence checks, deep research, self-review) All developers using Claude Code, Cursor, Windsurf, Codex, Gemini CLI
airis-mcp-gateway 🚪 Unified MCP proxy with 90% token reduction via lazy loading Claude Code users who want faster startup
mindbase šŸ’¾ Local cross-session memory with semantic search Developers who want persistent conversation history
airis-workspace šŸ—ļø Docker-first monorepo manager Teams building monorepos
airiscode šŸ–„ļø Terminal-first autonomous coding agent CLI-first developers

MCP Servers (Included via Gateway)

  • airis-mcp-supabase-selfhost (this repo) - Self-hosted Supabase MCP with RLS support
  • mindbase - Memory search & storage tools (mindbase_search, mindbase_store)

Recommended: Install via AIRIS MCP Gateway

This MCP server comes pre-configured with AIRIS MCP Gateway. No additional setup required.

# Install the Gateway (includes this server)
brew install agiletec-inc/tap/airis-mcp-gateway

# Start the gateway
airis-mcp-gateway up

# Add to Claude Code
claude mcp add --transport http airis-mcp-gateway http://api.gateway.localhost:9400/api/v1/mcp

Alternative: Standalone Installation

If you need to run this server independently:

git clone https://github.com/agiletec-inc/airis-mcp-supabase-selfhost.git
cd airis-mcp-supabase-selfhost && pnpm install

What you get with the full suite:

  • āœ… Confidence-gated workflows (prevents wrong-direction coding)
  • āœ… Deep research with evidence synthesis
  • āœ… 94% token reduction via repository indexing
  • āœ… Cross-session memory across all editors
  • āœ… Self-review and post-implementation validation

✨ Features

  • 2-Layer Backend: PostgREST (RLS-respected) + Direct PostgreSQL (schema introspection & diagnostics)
  • Token-Optimized: Lazy advertise, schema digest, minimal tool descriptions
  • Safety-First: READ_ONLY mode by default, DML/DDL/DCL blocked, SQL validation
  • Feature Flags: Selective tool activation (database, docs, postgrest, functions, storage)
  • RLS Awareness: PostgREST layer respects Row Level Security policies
  • Supabase Compatible: Works with official Supabase self-hosted deployments

šŸ—ļø Architecture

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  LLM (Claude, GPT, etc.)               │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                │ MCP Protocol (JSON-RPC)
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā–¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Supabase Self-hosted MCP Server       │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”   │
│  │  Feature Flags & Safety Guards  │   │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜   │
│         │                    │          │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā–¼ā”€ā”€ā”€ā”€ā”€ā”€ā”      ā”Œā”€ā”€ā”€ā”€ā”€ā–¼ā”€ā”€ā”€ā”€ā”€ā”€ā”   │
│  │  PostgREST  │      │   Direct   │   │
│  │   Layer     │      │    PG      │   │
│  │ (RLS aware) │      │ (read-only)│   │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”˜      ā””ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”˜   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
          │                  │
          ā–¼                  ā–¼
    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
    │   Supabase Self-hosted      │
    │   (PostgreSQL + PostgREST)  │
    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

šŸš€ Quick Start

Prerequisites

  • Node.js >= 20.0.0
  • Self-hosted Supabase instance running (localhost:54321 or remote)
  • PostgreSQL read-only user (recommended)

1. Install Dependencies

pnpm install

2. Configure Environment

cp .env.example .env
# Edit .env with your Supabase credentials

Key Configuration:

# PostgreSQL (use read-only role for safety)
PG_DSN=postgres://mcp_ro:password@127.0.0.1:5432/postgres

# PostgREST endpoint
POSTGREST_URL=http://127.0.0.1:54321/rest/v1

# PostgREST JWT (anon key or service_role key)
POSTGREST_JWT=your_anon_key_here

# Safety mode (recommended: true)
READ_ONLY=true

# Feature flags
FEATURES=database,docs,postgrest

3. Create Read-Only PostgreSQL User (Recommended)

-- Connect to your Supabase PostgreSQL as superuser
CREATE ROLE mcp_ro WITH LOGIN PASSWORD 'secure_password';
GRANT pg_read_all_data TO mcp_ro;
GRANT USAGE ON SCHEMA public TO mcp_ro;
GRANT USAGE ON SCHEMA information_schema TO mcp_ro;

4. Start Server

# Development mode (with auto-reload)
pnpm dev

# Production mode
pnpm build
pnpm start

Server starts on http://localhost:3100

šŸ› ļø Available Tools

MVP Tools (Current Implementation)

Tool Prefix: All tools use sbsh_ prefix to avoid collision with official Supabase MCP and PostgreSQL MCP servers.

1. sbsh_introspect_schema

Get token-optimized schema summary for specified schemas.

{
  "name": "sbsh_introspect_schema",
  "arguments": {
    "schemas": ["public"]
  }
}

Output: Digest format with table names, column types, index/constraint counts, RLS status.

2. sbsh_execute_sql

Execute SELECT queries or EXPLAIN plans safely.

{
  "name": "sbsh_execute_sql",
  "arguments": {
    "sql": "SELECT * FROM users WHERE created_at > '2024-01-01' LIMIT 10",
    "limit": 100
  }
}

Safety: In READ_ONLY mode, DML/DDL/DCL are blocked.

3. sbsh_postgrest_get

GET request via PostgREST with RLS respected.

{
  "name": "sbsh_postgrest_get",
  "arguments": {
    "table": "users",
    "query": {
      "select": "id,email,created_at",
      "eq": "status:active",
      "order": "created_at.desc",
      "limit": 10
    }
  }
}

Security: Uses provided JWT, respects RLS policies.

4. sbsh_get_table_doc

Get detailed documentation for a specific table.

{
  "name": "sbsh_get_table_doc",
  "arguments": {
    "table": "public.users"
  }
}

Output: Columns, constraints, RLS policies, comments.

šŸ” Security Features

READ_ONLY Mode (Default)

  • Enabled by default for safety
  • Blocks all DML/DDL/DCL operations
  • Only allows SELECT and EXPLAIN queries
  • Recommended for production use

SQL Validation

  • Regex-based detection of mutating operations
  • Blocks: INSERT, UPDATE, DELETE, TRUNCATE, ALTER, DROP, CREATE, GRANT, REVOKE, etc.
  • Allows: SELECT, EXPLAIN

RLS Respect

  • PostgREST layer automatically enforces Row Level Security
  • Direct PostgreSQL layer uses read-only role (no write permissions)
  • JWT-based authentication for user-scoped access

Feature Flags

Control tool availability via FEATURES environment variable:

  • database: Schema introspection and SQL execution
  • docs: Table documentation
  • postgrest: PostgREST API wrapper
  • functions: Edge Functions (not yet implemented)
  • storage: Storage API (not yet implemented)

šŸ“Š Token Optimization

Lazy Advertise

  • Only advertise enabled features
  • Minimal tool descriptions (detailed help on demand)
  • Feature flags reduce initial token load

Schema Digest

  • introspect_schema returns compressed summary
  • Full details via docs.get_table_doc on demand
  • Column format: name:type! (! = NOT NULL)

Result Sampling

  • Configurable row limits (max 1000)
  • Field metadata included for context
  • Truncation warnings

šŸ”§ Development Roadmap

Phase 1: MVP (Current)

  • [x] Project setup
  • [x] Core tools: introspect_schema, execute_sql, postgrest.get, docs
  • [x] READ_ONLY mode
  • [x] Feature flags
  • [x] Token optimization

Phase 2: Enhanced Safety

  • [ ] Dry-run mode for DML operations
  • [ ] Audit logging
  • [ ] Rate limiting
  • [ ] Query cost estimation

Phase 3: Extended Features

  • [ ] Edge Functions support
  • [ ] Storage API integration
  • [ ] Real-time subscriptions
  • [ ] Multi-project support

Phase 4: Advanced Optimization

  • [ ] Schema caching with invalidation
  • [ ] Result pagination
  • [ ] Streaming responses
  • [ ] Connection pooling optimization

šŸ¤ Integration

With airis-mcp-gateway

This server is designed to work with dynamic MCP gateway patterns:

// Load only when Supabase tools are needed
await gateway.loadServer('airis-mcp-supabase-selfhost', {
  url: 'http://localhost:3100/mcp',
  features: 'database,docs'
})

// Use tools
await gateway.call('airis-mcp-supabase-selfhost', 'sbsh_introspect_schema', {})

// Unload after use
await gateway.unloadServer('airis-mcp-supabase-selfhost')

With Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "airis-mcp-supabase-selfhost": {
      "command": "node",
      "args": ["/path/to/dist/server.js"],
      "env": {
        "PG_DSN": "postgres://mcp_ro:pass@localhost:5432/postgres",
        "POSTGREST_URL": "http://localhost:54321/rest/v1",
        "POSTGREST_JWT": "your_jwt_here",
        "READ_ONLY": "true",
        "FEATURES": "database,docs,postgrest"
      }
    }
  }
}

šŸ”— Related Projects

Explore other tools in the AIRIS ecosystem:


šŸ¤ Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

šŸ“ License

MIT


šŸ™ Acknowledgments

šŸ’– Support

agiletec is a one-person studio building these tools full-time and open source. If they earn a spot in your workflow, a sponsorship keeps them maintained and independent.

Sponsor agiletec


Built with ā¤ļø by the Agiletec team

Agiletec Inc. | Documentation | Issues | Discussions

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured