Codea Bien Logo
Supabase + AI Agents: MCP Server and Intelligent Automation
Supabase

Supabase + AI Agents: MCP Server and Intelligent Automation

Kevin Dávila

Kevin Dávila

supabase mcp serverai agentsclaudecursordatabase automation

I asked Claude to check the tables in my Supabase project and tell me which ones were missing RLS. No copying the schema, no pasting SQL. Thirty seconds later I had the list and a migration ready to apply. All I had written was one sentence.

That's what Supabase's MCP Server does: it connects your database to agents like Claude or Cursor so they can work with your real data. In this post you'll set it up step by step and see how far it goes: reading your schema, running queries, and generating migrations.

What is MCP Server

MCP (Model Context Protocol) is a protocol that allows AI agents to communicate with external tools. Supabase's MCP Server connects your database with agents like:

  • Claude (Anthropic)

  • Cursor

  • GitHub Copilot

  • Any MCP-compatible agent

This means you can ask your AI agent about your database, and it can:

  • Read your table schemas

  • Run SELECT queries

  • Generate SQL migrations

  • Write code that matches your DB

Configure the MCP Server

Install

// terminal
npm install -g @supabase/mcp-server-supabase

Get your Access Token

  1. Go to supabase.com/dashboard/account/tokens

  2. Create a new token with read permissions

  3. Copy the token

Configure in Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "supabase": {
      "command": "npx",
      "args": [
        "-y",
        "@supabase/mcp-server-supabase@latest",
        "--access-token",
        "YOUR_ACCESS_TOKEN"
      ]
    }
  }
}

Configure in Cursor

In .cursor/mcp.json:

{
  "mcpServers": {
    "supabase": {
      "command": "npx",
      "args": [
        "-y",
        "@supabase/mcp-server-supabase@latest",
        "--access-token",
        "YOUR_ACCESS_TOKEN"
      ]
    }
  }
}

Project-specific configuration

To limit MCP to a specific project:

{
  "mcpServers": {
    "supabase": {
      "command": "npx",
      "args": [
        "-y",
        "@supabase/mcp-server-supabase@latest",
        "--access-token",
        "YOUR_ACCESS_TOKEN",
        "--project-ref",
        "your-project-ref"
      ]
    }
  }
}

What can the MCP Server do

Read the schema

You can ask:

  • "What tables do I have in my database?"

  • "Show me the schema of the users table"

  • "What columns does the orders table have?"

The agent runs list_tables and list_extensions to get this information.

Run queries

You can ask:

  • "How many users do I have?"

  • "Show me the last 10 orders"

  • "Which products are out of stock?"

The agent runs execute_sql to run SELECT queries.

Generate code

You can ask:

  • "Generate an Angular component to display users"

  • "Create a function to insert orders"

  • "Write the Supabase service for this table"

The agent uses the schema to generate typed code that matches your database.

Generate migrations

You can ask:

  • "I need a comments table with a relation to posts"

  • "Add an email_verified field to the users table"

  • "Create an index on created_at for the orders table"

The agent generates migration SQL based on your current schema.

Practical example

Question 1: "What tables do I have?"

The agent runs:

list_tables → Returns list of tables with columns and types

Response: "You have 5 tables:

  • users (id, email, name, created_at)

  • tasks (id, user_id, title, completed, created_at)

  • projects (id, name, owner_id)

  • project_members (id, project_id, user_id, role)

  • comments (id, task_id, user_id, content, created_at)"

Question 2: "How many completed tasks are there?"

The agent runs:

SELECT COUNT(*) FROM tasks WHERE completed = true

Response: "There are 47 completed tasks."

Question 3: "Generate a service to handle tasks"

The agent generates:

// src/services/task.service.ts
import { supabase } from '../lib/supabase'

export interface Task {
  id: string
  user_id: string
  title: string
  completed: boolean
  created_at: string
}

export class TaskService {
  async getTasks(userId: string) {
    const { data, error } = await supabase
      .from('tasks')
      .select('*')
      .eq('user_id', userId)
      .order('created_at', { ascending: false })

    if (error) throw error
    return data as Task[]
  }

  async createTask(userId: string, title: string) {
    const { data, error } = await supabase
      .from('tasks')
      .insert({ user_id: userId, title })
      .select()
      .single()

    if (error) throw error
    return data as Task
  }

  async toggleTask(taskId: string, completed: boolean) {
    const { data, error } = await supabase
      .from('tasks')
      .update({ completed })
      .eq('id', taskId)
      .select()
      .single()

    if (error) throw error
    return data as Task
  }
}

Security

Is it safe to give access to my database?

The MCP Server uses your Supabase access token, which has the same permissions as your account. Recommendations:

  • Use a token with read-only permissions if you don't need writes

  • Limit to a specific project with --project-ref

  • Don't share the token

Can the agent modify my database?

By default, the MCP Server only allows SELECT queries. For writes:

  • You need to explicitly enable write permissions

  • Generated migrations are just SQL - they don't execute automatically

Real use cases

1. Rapid development

Ask the agent to generate components, services, and APIs based on your existing schema.

2. Documentation

Ask the agent to document your schema, relationships, and RLS policies.

3. Debugging

Ask the agent to investigate problems:

  • "Why is this query slow?"

  • "Is there inconsistent data in table X?"

  • "What RLS policies apply to this table?"

4. Migrations

Ask the agent to generate migrations for new features:

  • "I need a comments system with likes"

  • "Add tag support to tasks"

Codea Bien reference

For more on AI agents and Angular, check: RAG en Angular: Búsqueda inteligente con embeddings y Gemini

What's next

In the next article we cover From MVP to Production: how to take your Supabase app from development to the real world. We'll see performance, security, monitoring, and costs.