mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 22:59:11 +03:00
* feat(docs): fetch conn string Add option to ProjectConfigVariables to fetch the Supavisor session mode connection string, for setting up MCP server * docs(mcp): reminder to replace password placeholder in connection string * fix: display helpful message if project paused --------- Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
125 lines
4.4 KiB
Plaintext
125 lines
4.4 KiB
Plaintext
---
|
|
id: 'ai-tools-mcp'
|
|
title: 'Model context protocol (MCP)'
|
|
description: 'Connect AI tools to Supabase using MCP'
|
|
sidebar_label: 'Model context protocol (MCP)'
|
|
---
|
|
|
|
The [Model Context Protocol](https://modelcontextprotocol.io/introduction) (MCP) is a standard for connecting Large Language Models (LLMs) to external services.
|
|
|
|
This guide covers how to connect Supabase to the following AI tools using MCP:
|
|
|
|
- [Cursor](https://www.cursor.com/)
|
|
- [Windsurf](https://docs.codeium.com/windsurf) (Codium)
|
|
- [Cline](https://github.com/cline/cline) (VS Code extension)
|
|
- [Claude desktop](https://claude.ai/download)
|
|
- [Claude code](https://claude.ai/code)
|
|
|
|
Once connected, you can use natural language commands to run read-only database queries in the AI tool.
|
|
|
|
## Connect to Supabase using MCP
|
|
|
|
Supabase uses the [Postgres MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres) to provide MCP access to your database. The MCP server runs all queries as read-only transactions.
|
|
|
|
### 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
|
|
|
|
<ProjectConfigVariables variable="sessionPooler" />
|
|
|
|
Log in and choose a project above to find your connection string, or find it in the Dashboard:
|
|
|
|
1. Navigating to your project's [Connection settings](/dashboard/project/_/settings/database?showConnect=true)
|
|
1. Copying the connection string found under **Session pooler**.
|
|
|
|
<Admonition type="note">
|
|
|
|
Be sure to replace `[YOUR-PASSWORD]` with your database password.
|
|
|
|
</Admonition>
|
|
|
|
#### For a local Supabase instance
|
|
|
|
When running a local instance of Supabase via the [CLI](/docs/reference/cli/introduction), you can find your connection string by running:
|
|
|
|
```shell
|
|
supabase status
|
|
```
|
|
|
|
or if you are using `npx`:
|
|
|
|
```shell
|
|
npx 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](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres). Below are instructions on to connect to the Postgres MCP server using popular AI tools:
|
|
|
|
#### Cursor
|
|
|
|
1. Open Cursor and create a `.cursor` directory in your project root if it doesn't exist.
|
|
1. Create a `.cursor/mcp.json` file if it doesn't exist and open it.
|
|
1. Add the following configuration:
|
|
|
|
<$Partial path="mcp_config.mdx" variables={{ "app": "Cursor" }} />
|
|
|
|
1. Save the configuration file.
|
|
|
|
1. Open Cursor and navigate to **Settings/MCP**. You should see a green active status after the server is successfully connected.
|
|
|
|
#### Windsurf
|
|
|
|
1. Open Windsurf and navigate to the Cascade assistant.
|
|
1. Tap on the hammer (MCP) icon, then **Configure** to open the configuration file.
|
|
1. Add the following configuration:
|
|
|
|
<$Partial path="mcp_config.mdx" variables={{ "app": "Windsurf" }} />
|
|
|
|
1. Save the configuration file and reload by tapping **Refresh** in the Cascade assistant.
|
|
|
|
1. You should see a green active status after the server is successfully connected.
|
|
|
|
#### Cline
|
|
|
|
1. Open the Cline extension in VS Code and tap the **MCP Servers** icon.
|
|
1. Tap **Configure MCP Servers** to open the configuration file.
|
|
1. Add the following configuration:
|
|
|
|
<$Partial path="mcp_config.mdx" variables={{ "app": "VS Code" }} />
|
|
|
|
1. Save the configuration file. Cline should automatically reload the configuration.
|
|
|
|
1. You should see a green active status after the server is successfully connected.
|
|
|
|
#### Claude desktop
|
|
|
|
1. Open Claude desktop and navigate to **Settings**.
|
|
1. Under the **Developer** tab, tap **Edit Config** to open the configuration file.
|
|
1. Add the following configuration:
|
|
|
|
<$Partial path="mcp_config.mdx" variables={{ "app": "Claude desktop" }} />
|
|
|
|
1. Save the configuration file and restart Claude desktop.
|
|
|
|
1. From the new chat screen, you should see a hammer (MCP) icon appear with the new MCP server available.
|
|
|
|
#### Claude code
|
|
|
|
1. Create a `.mcp.json` file in your project root if it doesn't exist.
|
|
1. Add the following configuration:
|
|
|
|
<$Partial path="mcp_config.mdx" variables={{ "app": "Claude code" }} />
|
|
|
|
1. Save the configuration file.
|
|
|
|
1. Restart Claude code to apply the new configuration.
|
|
|
|
## Next steps
|
|
|
|
Your AI tool is now connected to Supabase using MCP. Try asking the AI tool to query your database using natural language commands.
|