Use Cloud SQL for PostgreSQL with MCP, Gemini CLI, and other agents

MySQL  |  PostgreSQL  |  SQL Server

This page shows you how to connect your Cloud SQL instance to various AIdeveloper assistance tools, including the following:

For an integrated experience, we recommend using the dedicatedGemini CLI extension for Cloud SQL for PostgreSQL.

As Google Cloud's next-generation command-line interface, Gemini CLIbundles the underlying MCP server directly into the extension, which simplifiessetup and configuration. You can configure Gemini Code Assist to usethe Gemini CLI, offering similar setup benefits in your IDE.

For other developer tools that support theModel Context Protocol (MCP),you can connect by manually configuring theMCP Toolbox for Databases (Toolbox). Toolbox is an open-source MCP server that connects AI agents to your data bymanaging tasks such as authentication and connection pooling. This lets youinteract with your data using natural language directly from your IDE. For thesetools, this method provides core database interaction capabilities.

For more information, seePrebuilt toolsandMCP Toolbox for Databases on GitHub.

About Gemini CLI and extensions

Gemini CLI is an open-source AI agent designed to assist with developmentworkflows by assisting with coding, debugging, data exploration, and contentcreation. It provides an agentic interface for interacting withdatabase and analytics services and popular open-source databases.

How extensions work

Gemini CLI is highly extensible, allowing for the addition of new toolsand capabilities through extensions. You can load the extensions from a GitHubURL, a local directory, or a configurable registry. They provide new tools, slashcommands, and prompts to assist with your workflow.

Use the Gemini CLI extensions in Cloud SQL for PostgreSQL

The Cloud SQL Gemini CLI extension is based on MCP Toolbox forDatabases.MCP Toolbox for Databases is currently in beta (pre-v1.0), and may seebreaking changes until the first stable release (v1.0).

The integration with Gemini CLI is through a dedicated extension thatoffers additional capabilities compared to the standard Toolbox connection. Theextension offers a streamlined installation process and a set of tools.

For more information, see GitHub documentation for theGemini CLI extension for Cloud SQL for PostgreSQL.

Gemini CLI extension for Cloud SQL for PostgreSQL databases

Thecloud-sql-postgresql extension includes tools for querying thedatabase, managing Cloud SQL resources, and monitoring database health.

CategoryTools
Database operations
  • list_tables: Lists all the tables and their corresponding descriptions found in a database.
  • execute_sql: Executes any SQL statement.
  • list_active_queries: Lists currently running queries on a Cloud SQL instance.
  • list_available_extensions: Lists available PostgreSQL extensions for installation on a Cloud SQL instance.
  • list_installed_extensions: Lists the installed PostgreSQL extensions on a Cloud SQL instance.
  • get_query_plan: Gets the query plan for a single statement from a Cloud SQL instance.
Resource management for instances, & users
  • create_user: Creates a new user in a Cloud SQL instance.
  • list_databases: Lists all databases for a Cloud SQL instance.
  • create_database: Creates a new database within a Cloud SQL instance.
  • list_instances: Lists Cloud SQL instances in a given project.
  • get_instance: Get the details about a specific Cloud SQL instance.
  • create_instance: Creates a new Cloud SQL instance.
  • wait_for_operation: Polls the operations API until an operation is complete.
Database health & maintenance
  • list_autovacuum_configurations: Lists autovacuum settings on a Cloud SQL instance. Vacuum operations remove dead tuples to help free up disk space, prevent table bloat, and improve read and write performance.
  • list_memory_configurations: Lists the instance-level memory settings on a Cloud SQL instance. Displays parameters like shared_buffers and work_mem, to help you assess and optimize resource allocation for query execution and caching.
  • list_top_bloated_tables: Lists the tables in a Cloud SQL instance with the most unused space (bloat). This information can be used to help you schedule maintenance, including vacuuming or reindexing, to reclaim disk space and improve query speed.
  • list_replication_slots: Lists the replication slot details, such as write-ahead logging (WAL) on a Cloud SQL instance. Helps support management and troubleshooting of replication-related issues.
  • list_invalid_indexes: Lists invalid indexes on a Cloud SQL instance. You can use this information to rebuild or drop invalid indexes for improved query performance.

Thecloud-sql-postgresql-observability extension provides a unifiedinterface for managing and monitoring database performance and health directlyfrom the Gemini CLI.

CategoryTools
Observability
  • get_system_metrics: Retrieves system metrics for a Cloud SQL instance.
  • get_query_metrics: Retrieves query-related metrics for a Cloud SQL instance.

Gemini CLI extension for PostgreSQL databases

For a list of those operations, seeMCP Toolbox for DatabasesandGemini CLI extension for PostgreSQL.

Before you begin

Install the MCP Toolbox

Note: This step isn't required for Gemini CLI extensions.
  1. To install the toolbox, download the binary that corresponds to youroperating system and CPU architecture.

    linux/amd64

    curl -O https://storage.googleapis.com/genai-toolbox/v0.7.0/linux/amd64/toolbox

    darwin/arm64

    curl -O https://storage.googleapis.com/genai-toolbox/v0.7.0/darwin/arm64/toolbox

    darwin/amd64

    curl -O https://storage.googleapis.com/genai-toolbox/v0.7.0/darwin/amd64/toolbox

    windows/amd64

    curl -O https://storage.googleapis.com/genai-toolbox/v0.7.0/windows/amd64/toolbox
  2. Make the binary executable:

    chmod+xtoolbox
  3. Verify the installation using the following command:

    ./toolbox--version

Configure the MCP Client

This section describes how to configure various developer tools to connect toyour Cloud SQL instance usingToolbox.Toolbox acts as an open-sourceModel Context Protocol (MCP)server that sits between your IDE and your database, providing a secure andefficient control plane for your AI tools. Select the tab for your specific toolto see the configuration instructions.

Gemini CLI for Cloud SQL for PostgreSQL


  1. Install theGemini CLI.
  2. Install the Cloud SQL for PostgreSQL extension for Gemini CLI from the GitHubrepository using the following command:
      gemini extensions install https://github.com/gemini-cli-extensions/cloud-sql-postgresql
  3. Set environment variables to connect to your Cloud SQL instance:
      export CLOUD_SQL_POSTGRES_PROJECT="PROJECT_NAME"  export CLOUD_SQL_POSTGRES_REGION="REGION"  export CLOUD_SQL_POSTGRES_INSTANCE="INSTANCE_NAME"  export CLOUD_SQL_POSTGRES_DATABASE="DATABASE_NAME"  export CLOUD_SQL_POSTGRES_USER="DATABASE_USER_NAME"  export CLOUD_SQL_POSTGRES_PASSWORD="PASSWORD"  export CLOUD_SQL_POSTGRES_IP_TYPE="IP_TYPE"
    Replace the following:
    • PROJECT_NAME: The Google Cloud project ID.
    • REGION: The region of your Cloud SQL instance.
    • INSTANCE_NAME: The ID of your Cloud SQL instance.
    • DATABASE_NAME: The name of the database to connect to.
    • DATABASE_USER_NAME: Optional: The database username. Defaults to IAM authentication if unspecified.
    • PASSWORD: Optional: The password for the database user. Defaults to IAM authentication if unspecified.
    • IP_TYPE: Optional: The IP type, such as "Public" (default) or "Private".
  4. Start the Gemini CLI in interactive mode:
      gemini

    The CLI automatically loads the Gemini CLI extension for Cloud SQLand its tools, which you can use to interact with your database.

    In the Gemini CLI, use the/extensionscommand to verify the extension is installed and/mcp listcommand to see the tools.

Gemini CLI for PostgreSQL


1. Install theGemini CLI.
2. Install the PostgreSQL software extension for Gemini CLI from the GitHub repository using the following command:
      gemini extensions install https://github.com/gemini-cli-extensions/postgres
3. Set environment variables to connect to your PostgreSQL instance:
      export POSTGRES_HOST="HOST"      export POSTGRES_PORT="PORT"      export POSTGRES_DATABASE="DATABASE"      export POSTGRES_USER="USER"      export POSTGRES_PASSWORD="PASSWORD"      export POSTGRES_QUERY_PARAMETERS="QUERY_PARAMETERS"
Replace the following:
  • HOST: The hostname or IP address of the PostgreSQL server.
  • PORT: The port number for the PostgreSQL server.
  • DATABASE: The name of the database to connect to.
  • USER: The database username.
  • PASSWORD: The password for the database user.
  • QUERY_PARAMETERS: Optional: The raw query to be added to thedb connection string.
4. Start the Gemini CLI in interactive mode:
      gemini

The CLI automatically loads the Gemini CLI extension for PostgreSQL and its tools, which you can use to interact with your database.

Gemini Code Assist


1. Install theGemini Code Assist extension in Visual Studio Code.
2. Enable Agent Mode in Gemini Code Assist chat.
3. In your working directory, create a folder named.gemini. Within it, create asettings.json file.
4. Add the following configuration, replace the environment variables with your values, and then save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

Claude code


1. InstallClaude Code.
2. Create.mcp.json file in your project root if it does not exist.
3. Add configuration, replace the environment variables with your values, and save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

Claude desktop


1. OpenClaude Desktop and navigate to Settings.
2. Under the Developer tab, tap Edit Config to open the configuration file.
3. Add configuration, replace the environment variables with your values, and save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"    }  }}

5. Restart Claude Desktop.
6. The new chat screen displays a hammer (MCP) icon with the new MCP server available.

Cline


1. OpenCline extension in VS Code and tapMCP Servers icon.
2. Tap Configure MCP Servers to open the configuration file.
3. Add the following configuration, replace the environment variables with your values, and save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

4. A green active status appears after the server connects successfully.

Cursor


1. Create.cursor directory in your project root if it does not exist.
2. Create.cursor/mcp.json file if it does not exist and open it.
3. Add the following configuration, replace the environment variables with your values, and save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

4. OpenCursor and navigate toSettings > Cursor Settings > MCP. A green active status appears when the server connects.

Visual Studio Code (Copilot)


1. OpenVS Code and create.vscode directory in your project root if it does not exist.
2. Create.vscode/mcp.json file if it does not exist, and open it.
3. Add the following configuration, replace the environment variables with your values, and save:

{  "servers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

Windsurf


1. OpenWindsurf and navigate to Cascade assistant.
2. Tap MCP icon, then tapConfigure to open the configuration file.
3. Add the following configuration, replace the environment variables with your values, and save:

{  "mcpServers": {    "cloud-sql-postgres": {      "command": "./PATH/TO/toolbox",      "args": ["--prebuilt","cloud-sql-postgres","--stdio"],      "env": {        "CLOUD_SQL_POSTGRES_PROJECT": "PROJECT_ID",        "CLOUD_SQL_POSTGRES_REGION": "REGION",        "CLOUD_SQL_POSTGRES_INSTANCE": "INSTANCE_ID",        "CLOUD_SQL_POSTGRES_DATABASE": "DATABASE_NAME",        "CLOUD_SQL_POSTGRES_USER": "USER_ID",        "CLOUD_SQL_POSTGRES_PASSWORD": "PASSWORD"      }    }  }}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-24 UTC.