Model context protocol (MCP)
The Model Context Protocol (MCP) is a standard for connecting Large Language Models (LLMs) to external services. This guide will walk you through how to connect AI tools to Supabase using MCP.
There are a number of popular AI tools that support MCP, including:
- Cursor
- Windsurf (Codium)
- Cline (VS Code extension)
- Claude desktop
Connecting these tools to Supabase will allow you to query your database and perform other SQL operations using natural language commands.
Connect to Supabase using MCP
We will use the Postgres MCP server to connect AI tools to Supabase.
Step 1: Find your database connection string
To get started, you will need to retrieve your database connection string. These will differ depending on whether you are using a hosted or local instance of Supabase.
For a hosted Supabase instance
When running a hosted instance of Supabase, you can find your connection string by:
- Navigating to your project's Connection settings
- Copying the connection string found under Session pooler.
For a local Supabase instance
When running a local instance of Supabase via the CLI, you can find your connection string by running:
1supabase status
or if you are using npx
:
1npx supabase status
This will output a list of details about your local Supabase instance. Copy the DB URL
field in the output.
Step 2: Configure in your AI tool
MCP compatible tools can connect to Supabase using the Postgres MCP server. Below are instructions on to connect to the Postgres MCP server using popular AI tools:
Cursor
-
Open Cursor and create a
.cursor
directory in your project root if it doesn't exist. -
Create a
.cursor/mcp.json
file if it doesn't exist and open it. -
Add the following configuration:
12345678{ "mcpServers": { "supabase": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"] } }}Replace
<connection-string>
with your connection string. -
Save the configuration file.
-
Open Cursor and navigate to Settings/MCP. You should see a green active status after the server is successfully connected.
Windsurf
-
Open Windsurf and navigate to the Cascade assistant.
-
Tap on the hammer (MCP) icon, then Configure to open the configuration file.
-
Add the following configuration:
12345678{ "mcpServers": { "supabase": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"] } }}Replace
<connection-string>
with your connection string. -
Save the configuration file and reload by tapping Refresh in the Cascade assistant.
-
You should see a green active status after the server is successfully connected.
Cline
-
Open the Cline extension in VS Code and tap the MCP Servers icon.
-
Tap Configure MCP Servers to open the configuration file.
-
Add the following configuration:
12345678{ "mcpServers": { "supabase": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"] } }}Replace
<connection-string>
with your connection string. -
Save the configuration file. Cline should automatically reload the configuration.
-
You should see a green active status after the server is successfully connected.
Claude desktop
-
Open Claude desktop and navigate to Settings.
-
Under the Developer tab, tap Edit Config to open the configuration file.
-
Add the following configuration:
12345678{ "mcpServers": { "supabase": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"] } }}Replace
<connection-string>
with your connection string. -
Save the configuration file and restart Claude desktop.
-
From the new chat screen, you should see a hammer (MCP) icon appear with the new MCP server available.
Next steps
You are now connected to Supabase using MCP! You can now interact with your database using natural language commands. Try asking your AI tool to query your database, create a new table, or perform other SQL operations.