Back to Genai Toolbox

AlloyDB for PostgreSQL MCP Server

docs/ALLOYDBPG_README.md

1.1.05.2 KB
Original Source

AlloyDB for PostgreSQL MCP Server

The AlloyDB Model Context Protocol (MCP) Server gives AI-powered development tools the ability to work with your Google Cloud AlloyDB for PostgreSQL resources. It supports full lifecycle control, from exploring schemas and running queries to monitoring your database.

Features

An editor configured to use the AlloyDB MCP server can use its AI capabilities to help you:

  • Explore Schemas and Data - List tables, get table details, and view data
  • Execute SQL - Run SQL queries directly from your editor
  • Monitor Performance - View active queries, query plans, and other performance metrics (via observability tools)
  • Manage Extensions - List available and installed PostgreSQL extensions

For AlloyDB infrastructure management, search the MCP store for the AlloyDB for PostgreSQL Admin MCP Server.

Prerequisites

  • Node.js installed.
  • A Google Cloud project with the AlloyDB API enabled.
  • Ensure Application Default Credentials are available in your environment.
  • IAM Permissions:
    • AlloyDB Client (roles/alloydb.client) (for connecting and querying)
    • Service Usage Consumer (roles/serviceusage.serviceUsageConsumer)

Note: If your AlloyDB instance uses private IPs, you must run the MCP server in the same Virtual Private Cloud (VPC) network.

Install & Configuration

  1. In the Antigravity MCP Store, click the "Install" button.

    [!NOTE] On first use, the installation process automatically downloads and uses MCP Toolbox >=0.26.0. To update MCP Toolbox, use: npm i -g @toolbox-sdk/server@latest To always run the latest version, update the MCP server configuration to use: npx -y @toolbox-sdk/server@latest --prebuilt alloydb-postgres.

  2. Add the required inputs for your cluster in the configuration pop-up, then click "Save". You can update this configuration at any time in the "Configure" tab.

[!NOTE] If you encounter issues with Windows Defender blocking the execution, you may need to configure an allowlist. See Configure exclusions for Microsoft Defender Antivirus for more details.

You'll now be able to see all enabled tools in the "Tools" tab.

Usage

Once configured, the MCP server will automatically provide AlloyDB capabilities to your AI assistant. You can:

  • "Show me all tables in the 'orders' database."
  • "What are the columns in the 'products' table?"
  • "How many orders were placed in the last 30 days?"

Server Capabilities

The AlloyDB MCP server provides the following tools:

Tool NameDescription
list_tablesLists detailed schema information for user-created tables.
execute_sqlExecutes a SQL query.
list_active_queriesList currently running queries.
list_available_extensionsList available extensions for installation.
list_installed_extensionsList installed extensions.
get_query_planGet query plan for a SQL statement.
list_autovacuum_configurationsList autovacuum configurations and their values.
list_memory_configurationsList memory configurations and their values.
list_top_bloated_tablesList top bloated tables.
list_replication_slotsList replication slots.
list_invalid_indexesList invalid indexes.

Custom MCP Server Configuration

The AlloyDB MCP server is configured using environment variables.

bash
export ALLOYDB_POSTGRES_PROJECT="<your-gcp-project-id>"
export ALLOYDB_POSTGRES_REGION="<your-alloydb-region>"
export ALLOYDB_POSTGRES_CLUSTER="<your-alloydb-cluster-id>"
export ALLOYDB_POSTGRES_INSTANCE="<your-alloydb-instance-id>"
export ALLOYDB_POSTGRES_DATABASE="<your-database-name>"
export ALLOYDB_POSTGRES_USER="<your-database-user>"  # Optional
export ALLOYDB_POSTGRES_PASSWORD="<your-database-password>"  # Optional
export ALLOYDB_POSTGRES_IP_TYPE="PUBLIC"  # Optional: `PUBLIC`, `PRIVATE`, `PSC`. Defaults to `PUBLIC`.

Add the following configuration to your MCP client (e.g., settings.json for Gemini CLI, mcp_config.json for Antigravity):

json
{
  "mcpServers": {
    "alloydb-postgres": {
      "command": "npx",
      "args": ["-y", "@toolbox-sdk/server", "--prebuilt", "alloydb-postgres", "--stdio"]
    }
  }
}

Documentation

For more information, visit the AlloyDB for PostgreSQL documentation.