supabase-secure
A secure MCP server that gives AI agents safe, audited access to two Supabase stored procedures without raw SQL.
Retrieve customer metrics (
get_customer_metrics) — read-only, aggregated metrics for a givenstartDate(YYYY-MM-DD), with an optionallimitof 1–50 results (default 10).Update customer status (
update_customer_status) — set a customer's status toactive,suspended, orarchivedby UUID; a mutation requiring an admin token and admin scope (blocked by default inREAD_ONLYmode).Safety guarantees — strict parameter validation (date regex, UUID format, numeric bounds), SQL-injection and scope-violation rejection, sanitized error traces, and an immutable audit log of every call in
mcp_audit_logs.
Provides safe AI-agent access to Supabase database stored procedures through pre-written RPCs, with read-only scope enforcement, strict parameter validation, audit logging, and sanitized error responses.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@supabase-secure get customer metrics for customer 42"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Secure Supabase Model Context Protocol (MCP) Server
An enterprise-grade Model Context Protocol (MCP) server that grants AI agents (Antigravity IDE/CLI, Cursor, Claude Desktop) safe access to Supabase database stored procedures without exposing raw SQL execution.
1. Problem Statement
Connecting LLMs directly to SQL databases introduces critical vulnerabilities:
SQL Injection & Data Loss: Unchecked LLM parameter generation can trigger unintended
DROP TABLEorDELETEcommands.Schema Leakage: Exposing raw internal database tables increases the attack surface.
Zero Visibility: Lack of execution tracking makes auditing LLM query intents and latency impossible.
Related MCP server: MCP Postgres Guard
2. Architecture & Security Defenses
graph TD
Client[LLM Client: Antigravity CLI / IDE] -->|JSON-RPC over STDIO| MCP[Secure MCP Server Layer]
subgraph Execution Safeguards
MCP -->|1. Type Guard| Zod[Zod v4 Native Schema Validator]
MCP -->|2. Mode Guard| Scope[Scope Control Middleware]
MCP -->|3. Error Sanitizer| ErrorHandler[Postgres Trace Sanitizer]
MCP -->|4. Interceptor| Audit[Async Audit Interceptor]
end
Zod -->|Validated RPC Params| Supabase[(Supabase Stored Procedures)]
Scope -->|Blocked Mutations| Client
Audit -->|Execution Records| AuditTable[(mcp_audit_logs Table)]Key Security Features
Air-Gapped Tool Layer: AI agents execute pre-written database functions (RPCs). Dynamic SQL construction and raw queries are strictly prohibited.
Native Zod v4 Schema Validation: Employs Zod v4's
z.toJSONSchema(schema, { io: "input" })for native OpenAPI tool registration, enforcing strict parameter boundaries (ISO dates, UUIDs, numeric bounds).Scope Control Middleware: Enforces
READ_ONLYmode by default, trapping state-modifying operations unless an explicit admin token is provided.Immutable Audit Trail: Asynchronously writes caller role, tool parameters, execution duration, and status (
SUCCESS,BLOCKED,ERROR) tomcp_audit_logs.Trace Sanitization: Strips internal PostgREST stack traces and database internal names before returning errors to the LLM client.
3. Quickstart
3.1 - Prerequisites
Node.js
>= 20.0.0Supabase project with Service Role key access
Antigravity CLI / IDE, Cursor, or Claude Desktop
3.2 - Installation & Build
git clone https://github.com/minhajadab3836/supabase-mcp-secure.git
cd supabase-mcp-secure
npm install
npm run build3.3 - Database Setup (Supabase Migration)
Run the SQL migration located in supabase/migrations/20260101000000_init_security_schema.sql inside your Supabase SQL Editor. This initializes:
mcp_audit_logs(immutable audit trail table with indexes)customers&orders(demo tables with sample seed records)get_customer_metrics(read-only analytical stored procedure)update_customer_status(audited mutation stored procedure)
3.4 - Environment Setup
Create a .env file in the root directory (refer to .env.example):
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-supabase-service-role-key
MCP_MODE=READ_ONLY
ADMIN_TOKEN=secret-admin-token-1233.5 - Security Test Suite
Run the automated assertion script to test SQL injection rejection, scope enforcement, parameter bounding, trace sanitization, and audit logging:
npm testExpected Output:
🔒 Starting Secure MCP Security Test Suite...
Test 1: SQL Injection in date parameter
✅ PASSED: SQL Injection attempt caught by Zod schema validation.
Test 2: Unauthorized mutation execution in READ_ONLY mode
[AUDIT] 2026-11-07T13:42:34.721Z | Tool: update_customer_status | Status: BLOCKED | Duration: 0ms
✅ PASSED: Scope Control guard blocked unauthorized mutation.
Test 3: Parameter overflow constraint check
✅ PASSED: Parameter bound correctly enforced by Zod max limit.
Test 4: Error trace sanitization
✅ PASSED: Sensitive database details stripped from error output.
Test 5: Scope authorization verification
✅ PASSED: Scope guard correctly validates admin credentials.
🎉 Security suite complete. All 5 defense boundaries verified.4. Client Integration
Option 1: Antigravity IDE Workspace Auto-Discovery (.antigravity/mcp.json)
Place or update .antigravity/mcp.json in your workspace root:
{
"mcpServers": {
"supabase-secure": {
"command": "node",
"args": ["./dist/index.js"],
"env": {
"SUPABASE_URL": "https://your-project.supabase.co",
"SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key",
"MCP_MODE": "READ_ONLY",
"ADMIN_TOKEN": "secret-admin-token-123"
}
}
}
}Option 2: Antigravity CLI Manual Registration
Register the binary directly via CLI:
antigravity mcp add supabase-secure \
--command node \
--args "$(pwd)/dist/index.js" \
--env SUPABASE_URL="https://your-project.supabase.co" \
--env SUPABASE_SERVICE_ROLE_KEY="your-service-role-key" \
--env MCP_MODE="READ_ONLY"5. Security Threat & Defense Matrix
Threat Vector | Input Payload Attempt | Defense Mechanism | System Outcome |
SQL Injection |
| Zod Date Regex Constraint | Throws |
Unauthorized Write | Mutation tool call under | Scope Control Guard | Intercepts call, returns |
Parameter Overflow |
| Zod Range Constraint ( | Throws |
Schema Leakage | Database execution failure or missing relation | Error Sanitizer Middleware | Strips internal Postgres engine details ( |
Audit Bypass | Any tool execution attempt | Async Audit Interceptor | Logs caller role, parameters, latency, and status to |
6. Architecture & Threat Model
For the in-depth isolation specifications and architectural boundary breakdown, see docs/architecture.md.
7. License
MIT License. See LICENSE for details.
Available Tools
2 toolsget_customer_metricsC
Retrieves aggregated customer metrics. Read-only execution.
Inputs: startDate (required), limit.
update_customer_statusB
Updates account status for a customer UUID. Mutation (Requires Admin Scope).
Inputs: status (required), customerId (required), adminToken.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools have clearly distinct purposes: one read-only metrics retrieval and one admin-scoped customer status mutation. An agent can easily tell them apart by action and resource.
Both tools follow a consistent snake_case verb_noun pattern: get_customer_metrics and update_customer_status. The naming is predictable and readable.
Two tools is thin for a server named supabase-secure, even if each tool is meaningful. It feels like a narrow slice of a broader secure customer-management surface.
The surface covers customer metrics retrieval and status updates but lacks obvious related operations such as listing customers, getting a customer, reading current status, or creating/deleting customer records. These gaps could force agents into dead ends.
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Permission checks, human approval cards, and signed audit trails for AI agent tool calls.
Security layer for AI agents: Retrieve for controlled SQL reads, Guard for allow/deny writes.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to safely interact with Supabase through read-only and gated-write tools, with bounded queries, allowlists, and explicit project targeting.-
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely query PostgreSQL by intercepting and auditing every generated SQL statement before it reaches the database, blocking destructive commands like DROP/TRUNCATE, unbounded DELETE/UPDATE statements, stacked queries, and SQL injection probes. It exposes tools for validating query safety and enforcing a strict read-only (SELECT/EXPLAIN) policy.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to query PostgreSQL databases securely with read-only defaults, PII masking, rate limiting, and human-approved, expiring mutation tokens.91Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.MIT