Supabase MCP Server
Connect your AI to your PostgreSQL database
Supabase MCP Server
The Supabase MCP server allows your AI assistant to interact directly with your PostgreSQL database. This is enhancing for building features that require complex queries or RLS policies.
Features
- Schema Inspection: The AI can read your entire database structure (tables, columns, types, relationships).
- SQL Generation: It generates highly accurate SQL queries because it knows your exact schema.
- Data Querying: It can fetch sample data to understand the content (e.g., "Show me 5 recent users").
- RLS Policy Assistant: It can help write and debug Row Level Security policies by understanding your auth setup.
Installation & Configuration
Prerequisites
- Supabase Project Created
SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEYavailable.
Security Warning: You must use the Service Role Key (found in Project Settings > API) for the MCP server to function correctly (it needs admin access to read system schemas). NEVER commit this key to git. Add it to your .env or secure storage.
Setup for Cursor
- Open Cursor Settings > Features > MCP.
- Click + Add New MCP Server.
- Fill in the details:
| Field | Value |
|---|---|
| Name | supabase |
| Type | command |
| Command | npx -y @modelcontextprotocol/server-supabase |
- Add Environment Variables:
| Variable | Value |
|---|---|
SUPABASE_URL | https://your-project-ref.supabase.co |
SUPABASE_SERVICE_ROLE_KEY | your-service-role-key |
Setup for Claude Code
Add the following to your claude_config.json (or equivalent configuration):
{
"mcpServers": {
"supabase": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-supabase"],
"env": {
"SUPABASE_URL": "your-project-url",
"SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key"
}
}
}
}Usage Examples
Once connected, try these prompts with your AI:
1. Understand your data:
"Analyze my database schema and tell me how the
usersandsubscriptionstables are related."
2. Write complex queries:
"Write a SQL function to calculate the monthly recurring revenue (MRR) for the last 12 months based on the
paymentstable."
3. specific constraints:
"I need to add a constraint to
user_profilesensuringusernameis alphanumeric. Write the migration SQL."