9.5 KiB
title, type, weight, description
| title | type | weight | description |
|---|---|---|---|
| PostgreSQL using MCP | docs | 2 | Connect your IDE to PostgreSQL using Toolbox. |
Model Context Protocol (MCP) is an open protocol for connecting Large Language Models (LLMs) to data sources like Postgres. This guide covers how to use MCP Toolbox for Databases to expose your developer assistant tools to a Postgres instance:
- Cursor
- Windsurf (Codium)
- Visual Studio Code (Copilot)
- Cline (VS Code extension)
- Claude desktop
- Claude code
- Gemini CLI
- Gemini Code Assist
{{< notice tip >}} This guide can be used with AlloyDB Omni. {{< /notice >}}
Set up the database
-
Create or select a PostgreSQL instance.
-
Create or reuse a database user and have the username and password ready.
Install MCP Toolbox
-
Download the latest version of Toolbox as a binary. Select the correct binary corresponding to your OS and CPU architecture. You are required to use Toolbox version V0.6.0+:
{{< tabpane persist=header >}} {{< tab header="linux/amd64" lang="bash" >}} curl -O https://storage.googleapis.com/genai-toolbox/v0.20.0/linux/amd64/toolbox {{< /tab >}}
{{< tab header="darwin/arm64" lang="bash" >}} curl -O https://storage.googleapis.com/genai-toolbox/v0.20.0/darwin/arm64/toolbox {{< /tab >}}
{{< tab header="darwin/amd64" lang="bash" >}} curl -O https://storage.googleapis.com/genai-toolbox/v0.20.0/darwin/amd64/toolbox {{< /tab >}}
{{< tab header="windows/amd64" lang="bash" >}} curl -O https://storage.googleapis.com/genai-toolbox/v0.20.0/windows/amd64/toolbox.exe {{< /tab >}} {{< /tabpane >}}
-
Make the binary executable:
chmod +x toolbox -
Verify the installation:
./toolbox --version
Configure your MCP Client
{{< tabpane text=true >}} {{% tab header="Claude code" lang="en" %}}
-
Install Claude Code.
-
Create a
.mcp.jsonfile in your project root if it doesn't exist. -
Add the following configuration, replace the environment variables with your values, and save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } } -
Restart Claude code to apply the new configuration. {{% /tab %}}
{{% tab header="Claude desktop" lang="en" %}}
-
Open Claude desktop and navigate to Settings.
-
Under the Developer tab, tap Edit Config to open the configuration file.
-
Add the following configuration, replace the environment variables with your values, and save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } } -
Restart Claude desktop.
-
From the new chat screen, you should see a hammer (MCP) icon appear with the new MCP server available. {{% /tab %}}
{{% tab header="Cline" lang="en" %}}
-
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, replace the environment variables with your values, and save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } } -
You should see a green active status after the server is successfully connected. {{% /tab %}}
{{% tab header="Cursor" lang="en" %}}
-
Create a
.cursordirectory in your project root if it doesn't exist. -
Create a
.cursor/mcp.jsonfile if it doesn't exist and open it. -
Add the following configuration, replace the environment variables with your values, and save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } } -
Cursor and navigate to Settings > Cursor Settings > MCP. You should see a green active status after the server is successfully connected. {{% /tab %}}
{{% tab header="Visual Studio Code (Copilot)" lang="en" %}}
-
Open VS Code and create a
.vscodedirectory in your project root if it doesn't exist. -
Create a
.vscode/mcp.jsonfile if it doesn't exist and open it. -
Add the following configuration, replace the environment variables with your values, and save:
{ "servers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } }
{{% /tab %}}
{{% tab header="Windsurf" lang="en" %}}
-
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, replace the environment variables with your values, and save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } }
{{% /tab %}}
{{% tab header="Gemini CLI" lang="en" %}}
-
Install the Gemini CLI.
-
In your working directory, create a folder named
.gemini. Within it, create asettings.jsonfile. -
Add the following configuration, replace the environment variables with your values, and then save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } }
{{% /tab %}}
{{% tab header="Gemini Code Assist" lang="en" %}}
-
Install the Gemini Code Assist extension in Visual Studio Code.
-
Enable Agent Mode in Gemini Code Assist chat.
-
In your working directory, create a folder named
.gemini. Within it, create asettings.jsonfile. -
Add the following configuration, replace the environment variables with your values, and then save:
{ "mcpServers": { "postgres": { "command": "./PATH/TO/toolbox", "args": ["--prebuilt","postgres","--stdio"], "env": { "POSTGRES_HOST": "", "POSTGRES_PORT": "", "POSTGRES_DATABASE": "", "POSTGRES_USER": "", "POSTGRES_PASSWORD": "" } } } }
{{% /tab %}} {{< /tabpane >}}
Use Tools
Your AI tool is now connected to Postgres using MCP. Try asking your AI assistant to list tables, create a table, or define and execute other SQL statements.
The following tools are available to the LLM:
- list_tables: lists tables and descriptions
- execute_sql: execute any SQL statement
{{< notice note >}} Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs will adapt to the tools available, so this shouldn't affect most users. {{< /notice >}}