Connect Supabase to AI Assistants: A Guide to Using Supabase MCP Server
Want to connect your Supabase projects to AI assistants like Cursor, Claude, and Windsurf? The Supabase MCP server makes it possible! This article will guide you through setting up and using the Supabase MCP server to enhance your AI workflows.
What is Supabase MCP Server?
The Model Context Protocol (MCP) is a standard for communication between Large Language Models (LLMs) and external services like Supabase. The Supabase MCP server acts as a bridge, enabling AI assistants to interact directly with your Supabase project. It allows them to perform tasks like:
- Managing database tables.
- Fetching project configurations.
- Querying your Supabase data.
Ultimately, this integration empowers AI to automate and assist with database-driven tasks.
Why Use Supabase with AI Assistants?
Integrating Supabase with AI offers powerful benefits:
- Automated Database Management: Let AI handle routine database tasks.
- Intelligent Data Retrieval: Quickly extract insights from your Supabase data.
- Streamlined Development: Speed up your development process with AI-powered assistance.
Prerequisites: Getting Ready for Supabase MCP
Before you begin, ensure you have Node.js installed on your machine. Open your terminal and run node -v
. If Node.js is not installed, download it from the official Node.js website.
Step-by-Step Setup of Supabase MCP Server
Here's how to configure the Supabase MCP server and connect it to your AI assistant:
1. Generate a Personal Access Token (PAT)
Navigate to your Supabase settings and create a new personal access token. Give it a descriptive name (e.g., "Cursor MCP Server").
This token authenticates the MCP server with your Supabase account. Important: Copy the token immediately, as you won't be able to view it again.
2. Configure Your MCP Client
Configure your MCP client (like Cursor) to utilize the newly created server. Most clients use a JSON configuration format.
Here's a general example of the JSON structure:
Remember to replace "YOUR_SUPABASE_PAT"
with the access token you obtained earlier.
If your MCP client doesn't support JSON, use the direct CLI command:
Note: This command is intended to be executed by your MCP client. npx
downloads the latest MCP server version from npm
and executes it, so you always have the newest features.
Special Configuration for Windows Users
If using Windows, prefix the command with cmd /c
:
Alternatively, use wsl
if Node.js is running inside WSL:
Ensure Node.js is added to your system's PATH
environment variable on Windows. If running Node.js natively, follow the steps below:
-
Get the path to
npm
: -
Add the directory to your PATH:
Replace
<NPM_PATH>
with the output from the previous command. -
Restart your MCP client for the changes to take effect.
Available Supabase Tools for LLMs
Once set up, your LLM can access various Supabase tools through the MCP server. Here's a listing of the available tools:
Project Management
list_projects
: Lists all your Supabase projects.get_project
: Fetches details for a specific project.create_project
: Creates a new Supabase project.pause_project
: Pauses a project.restore_project
: Restores a paused project.list_organizations
: Displays organizations you belong to.get_organization
: Retrieves details for a specific organization.
Database Operations
list_tables
: Lists tables within specified schemas.list_extensions
: Lists extensions in the database.list_migrations
: Shows database migrations.apply_migration
: Applies SQL migrations (for schema changes).execute_sql
: Executes raw SQL queries (for data retrieval).get_logs
: Retrieves logs by service type (API, Postgres, etc.) for debugging.
Project Configuration
get_project_url
: Gets the API URL for a project.get_anon_key
: Gets the anonymous API key.
Branching (Experimental, Paid Plans)
create_branch
: Creates a development branch from production.list_branches
: Lists development branches.delete_branch
: Deletes a development branch.merge_branch
: Merges changes from a development branch to production.reset_branch
: Resets a development branch's migrations.rebase_branch
: Updates a development branch with production changes.
Development Tools
generate_typescript_types
: Creates TypeScript types from your database schema.
Connecting with PostgREST: @supabase/mcp-server-postgrest
Another valuable tool is the @supabase/mcp-server-postgrest
server. This allows you to connect your users to your app via a REST API. More details can be found in its project README.
Dive Deeper into Supabase and AI
The Supabase MCP server opens incredible opportunities to integrate your database with leading AI assistants. Start exploring today and discover how AI can revolutionize your Supabase workflows. For more information on the Model Context Protocol, visit Model Context Protocol.