|
1 | | -# Gemini CLI Extension - Cloud SQL for PostgreSQL |
| 1 | +# Cloud SQL for PostgreSQL Agent Skills |
2 | 2 |
|
3 | 3 | > [!NOTE] |
4 | | -> This extension is currently in beta (pre-v1.0), and may see breaking changes until the first stable release (v1.0). |
| 4 | +> Currently in beta (pre-v1.0), and may see breaking changes until the first stable release (v1.0). |
5 | 5 |
|
6 | | -This Gemini CLI extension provides a set of skills to interact with [Cloud SQL for PostgreSQL](https://cloud.google.com/sql/docs/postgres) instances. It allows you to manage your databases, execute queries, explore schemas, and troubleshoot issues directly from the [Gemini CLI](https://google-gemini.github.io/gemini-cli/), using natural language prompts. |
| 6 | +This repository provides a set of agent skills to interact with [Cloud SQL for PostgreSQL](https://cloud.google.com/sql/docs/postgres) instances. These skills can be used with various AI agents, including [Gemini CLI](https://google-gemini.github.io/gemini-cli/), Claude Code, and Codex, to manage your databases, execute queries, explore schemas, and troubleshoot issues using natural language prompts. |
7 | 7 |
|
8 | | -Learn more about [Gemini CLI Extensions](https://github.com/google-gemini/gemini-cli/blob/main/docs/extensions/index.md). |
9 | 8 | > [!IMPORTANT] |
10 | 9 | > **We Want Your Feedback!** |
11 | | -> Please share your thoughts with us by filling out our feedback [form][form]. |
| 10 | +> Please share your thoughts with us by filling out our feedback [form][form]. |
12 | 11 | > Your input is invaluable and helps us improve the project for everyone. |
13 | 12 |
|
14 | 13 | [form]: https://docs.google.com/forms/d/e/1FAIpQLSfEGmLR46iipyNTgwTmIDJqzkAwDPXxbocpXpUbHXydiN1RTw/viewform?usp=pp_url&entry.157487=cloud-sql-postgresql |
15 | 14 |
|
16 | | -## Why Use the Cloud SQL for PostgreSQL Extension? |
| 15 | +## Table of Contents |
17 | 16 |
|
18 | | -* **Seamless Workflow:** As a Google-developed extension, it integrates seamlessly into the Gemini CLI environment. No need to constantly switch contexts for common database tasks. |
19 | | -* **Natural Language Queries:** Stop wrestling with complex commands. Explore schemas and query data by describing what you want in plain English. |
20 | | -* **Full Lifecycle Control:** Manage the entire lifecycle of your database, from creating instances to exploring schemas and running queries. |
21 | | -* **Code Generation:** Accelerate development by asking Gemini to generate data classes and other code snippets based on your table schemas. |
| 17 | +- [Why Use Cloud SQL for PostgreSQL Agent Skills?](#why-use-cloud-sql-for-postgresql-agent-skills) |
| 18 | +- [Prerequisites](#prerequisites) |
| 19 | +- [Getting Started](#getting-started) |
| 20 | + - [Configuration](#configuration) |
| 21 | + - [Installation & Usage](#installation--usage) |
| 22 | + - [Gemini CLI](#gemini-cli) |
| 23 | + - [Claude Code](#claude-code) |
| 24 | + - [Codex](#codex) |
| 25 | +- [Usage Examples](#usage-examples) |
| 26 | +- [Supported Skills](#supported-skills) |
| 27 | +- [Additional Agent Skills](#additional-agent-skills) |
| 28 | +- [Troubleshooting](#troubleshooting) |
22 | 29 |
|
| 30 | +## Why Use Cloud SQL for PostgreSQL Agent Skills? |
| 31 | + |
| 32 | +- **Seamless Workflow:** Integrates seamlessly into your AI agent's environment. No need to constantly switch contexts for common database tasks. |
| 33 | +- **Natural Language Queries:** Stop wrestling with complex commands. Explore schemas and query data by describing what you want in plain English. |
| 34 | +- **Full Lifecycle Control:** Manage the entire lifecycle of your database, from creating instances to exploring schemas and running queries. |
| 35 | +- **Code Generation:** Accelerate development by asking your agent to generate data classes and other code snippets based on your table schemas. |
23 | 36 |
|
24 | 37 | ## Prerequisites |
25 | 38 |
|
26 | 39 | Before you begin, ensure you have the following: |
27 | 40 |
|
28 | | -* [Gemini CLI](https://github.com/google-gemini/gemini-cli) installed with version **+v0.6.0**. |
29 | | -* Setup Gemini CLI [Authentication](https://github.com/google-gemini/gemini-cli/tree/main?tab=readme-ov-file#-authentication-options). |
30 | | -* A Google Cloud project with the **Cloud SQL Admin API** enabled. |
31 | | -* Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. |
32 | | -* IAM Permissions: |
33 | | - * Cloud SQL Client (`roles/cloudsql.client`) |
34 | | - * Cloud SQL Admin (`roles/cloudsql.admin`) |
| 41 | +- One of these AI agents installed |
| 42 | + - [Gemini CLI](https://github.com/google-gemini/gemini-cli) version **v0.6.0** or higher |
| 43 | + - [Claude Code](https://claude.com/product/claude-code) version **v2.1.94** or higher |
| 44 | + - [Codex](https://developers.openai.com/codex) **v0.117.0** or higher |
| 45 | +- A Google Cloud project with the **Cloud SQL Admin API** enabled. |
| 46 | +- Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. |
| 47 | +- IAM Permissions: |
| 48 | + - Cloud SQL Client (`roles/cloudsql.client`) |
| 49 | + - Cloud SQL Admin (`roles/cloudsql.admin`) |
| 50 | + |
35 | 51 | > [!NOTE] |
36 | | -> If you do not configure a specific `CLOUD_SQL_POSTGRES_USER` or `CLOUD_SQL_POSTGRES_PASSWORD`, this extension defaults to using the active local IAM user credentials. You must also add the IAM user to your Cloud SQL instance, see [Creating a database user](https://cloud.google.com/sql/docs/postgres/add-manage-iam-users#creating-a-database-user). |
| 52 | +> If you do not configure a specific `CLOUD_SQL_POSTGRES_USER` or `CLOUD_SQL_POSTGRES_PASSWORD`, these skills default to using the active local IAM user credentials. You must also add the IAM user to your Cloud SQL instance, see [Creating a database user](https://cloud.google.com/sql/docs/postgres/add-manage-iam-users#creating-a-database-user). |
37 | 53 |
|
38 | 54 | ## Getting Started |
39 | 55 |
|
40 | | -### Installation |
| 56 | +### Configuration |
41 | 57 |
|
42 | | -To install the extension, use the command: |
| 58 | +Please keep these env vars handy during the installation process: |
43 | 59 |
|
44 | | -```bash |
45 | | -gemini extensions install https://github.com/gemini-cli-extensions/cloud-sql-postgresql |
46 | | -``` |
| 60 | +- `CLOUD_SQL_POSTGRES_PROJECT`: The GCP project ID. |
| 61 | +- `CLOUD_SQL_POSTGRES_REGION`: The region of your Cloud SQL instance. |
| 62 | +- `CLOUD_SQL_POSTGRES_INSTANCE`: The ID of your Cloud SQL instance. |
| 63 | +- `CLOUD_SQL_POSTGRES_DATABASE`: The name of the database to connect to. |
| 64 | +- `CLOUD_SQL_POSTGRES_USER`: (Optional) The database username. Defaults to the active IAM user. |
| 65 | +- `CLOUD_SQL_POSTGRES_PASSWORD`: (Optional) The password for the database user. |
| 66 | +- `CLOUD_SQL_POSTGRES_IP_TYPE`: (Optional) Type of the IP address: `PUBLIC`, `PRIVATE`, or `PSC`. Defaults to `PUBLIC`. |
47 | 67 |
|
48 | | -### Configuration |
| 68 | +> [!NOTE] |
| 69 | +> |
| 70 | +> - Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. |
| 71 | +> - If your Cloud SQL for PostgreSQL instance uses private IPs, you must run your agent in the same Virtual Private Cloud (VPC) network. |
49 | 72 |
|
50 | | -You will be prompted to configure the following settings during installation. These settings are saved in an `.env` file within the extension's directory. |
| 73 | +### Installation & Usage |
51 | 74 |
|
52 | | -* `CLOUD_SQL_POSTGRES_PROJECT`: The GCP project ID. |
53 | | -* `CLOUD_SQL_POSTGRES_REGION`: The region of your Cloud SQL instance. |
54 | | -* `CLOUD_SQL_POSTGRES_INSTANCE`: The ID of your Cloud SQL instance. |
55 | | -* `CLOUD_SQL_POSTGRES_DATABASE`: The name of the database to connect to. |
56 | | -* `CLOUD_SQL_POSTGRES_USER`: (Optional) The database username. Defaults to the active IAM user. |
57 | | -* `CLOUD_SQL_POSTGRES_PASSWORD`: (Optional) The password for the database user. |
58 | | -* `CLOUD_SQL_POSTGRES_IP_TYPE`: (Optional) Type of the IP address: `PUBLIC`, `PRIVATE`, or `PSC`. Defaults to `PUBLIC`. |
| 75 | +To start interacting with your database, install the skills for your preferred AI agent, then launch the agent and use natural language to ask questions or perform tasks. |
59 | 76 |
|
60 | | -To view or update your configuration: |
| 77 | +For the latest version, check the [releases page][releases]. |
61 | 78 |
|
62 | | -**List Settings:** |
63 | | -* Terminal: `gemini extensions list` |
64 | | -* Gemini CLI: `/extensions list` |
| 79 | +[releases]: https://github.com/gemini-cli-extensions/cloud-sql-postgresql/releases |
65 | 80 |
|
66 | | -**Update Settings:** |
67 | | -* Terminal: `gemini extensions config cloud-sql-postgresql [setting name] [--scope <scope>]` |
68 | | - * `setting name`: (Optional) The single setting to configure. |
69 | | - * `scope`: (Optional) The scope of the setting in (`user` or `workspace`). Defaults to `user`. |
70 | | -* Currently, you must restart the Gemini CLI for changes to take effect. We recommend using `gemini --resume` to resume your session. |
| 81 | +<!-- {x-release-please-start-version} --> |
71 | 82 |
|
72 | | -> [!NOTE] |
73 | | -> * Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. |
74 | | -> * If your Cloud SQL for PostgreSQL instance uses private IPs, you must run Gemini CLI in the same Virtual Private Cloud (VPC) network. |
75 | | -> * See [Troubleshooting](#troubleshooting) for debugging your configuration. |
| 83 | +<details open> |
| 84 | +<summary id="gemini-cli">Gemini CLI</summary> |
| 85 | + |
| 86 | +**1. Install the extension:** |
| 87 | + |
| 88 | +```bash |
| 89 | +gemini extensions install https://github.com/gemini-cli-extensions/cloud-sql-postgresql --ref 0.3.0 |
| 90 | +``` |
76 | 91 |
|
77 | | -### Start Gemini CLI |
| 92 | +During the installation, enter your environment vars as described in the [configuration section](#configuration). |
78 | 93 |
|
79 | | -To start the Gemini CLI, use the following command: |
| 94 | +**2. (Optional) Manage Configuration:** |
| 95 | +To view or update your configuration in Gemini CLI: |
| 96 | + |
| 97 | +- Terminal: `gemini extensions config cloud-sql-postgresql [setting name] [--scope <scope>]` |
| 98 | +- Gemini CLI: `/extensions list` |
| 99 | + |
| 100 | +**3. Start the agent:** |
80 | 101 |
|
81 | 102 | ```bash |
82 | 103 | gemini |
83 | 104 | ``` |
84 | 105 |
|
| 106 | +_(Tip: Run `/extensions list` to verify your configuration and active extensions.)_ |
| 107 | + |
85 | 108 | > [!WARNING] |
86 | 109 | > **Changing Instance & Database Connections** |
87 | | -> Currently, the database connection must be configured before starting the Gemini CLI and can not be changed during a session. |
88 | | -> To save and resume conversation history use command: `/chat save <tag>` and `/chat resume <tag>`. |
| 110 | +> Currently, the database connection must be configured before starting the agent and can not be changed during a session. |
| 111 | +> To save and resume conversation history in Gemini CLI use command: `/chat save <tag>` and `/chat resume <tag>`. |
| 112 | +
|
| 113 | +</details> |
| 114 | + |
| 115 | +<details> |
| 116 | +<summary id="claude-code">Claude Code</summary> |
| 117 | + |
| 118 | +**1. Set env vars:** |
| 119 | +In your terminal, set your environment vars as described in the [configuration section](#configuration). |
| 120 | + |
| 121 | +**2. Start the agent:** |
| 122 | + |
| 123 | +```bash |
| 124 | +claude |
| 125 | +``` |
| 126 | + |
| 127 | +**3. Add the marketplace:** |
| 128 | + |
| 129 | +```bash |
| 130 | +/plugin marketplace add https://github.com/gemini-cli-extensions/cloud-sql-postgresql.git#0.3.0 |
| 131 | +``` |
| 132 | + |
| 133 | +**4. Install the plugin:** |
| 134 | + |
| 135 | +```bash |
| 136 | +/plugin install cloud-sql-postgresql@cloud-sql-postgresql-marketplace |
| 137 | +``` |
| 138 | + |
| 139 | +_(Tip: Run `/plugin list` inside Claude Code to verify the plugin is active, or `/reload-plugins` if you just installed it.)_ |
| 140 | + |
| 141 | +</details> |
| 142 | + |
| 143 | +<details> |
| 144 | +<summary id="codex">Codex</summary> |
| 145 | + |
| 146 | +**1. Clone the Repo:** |
| 147 | + |
| 148 | +```bash |
| 149 | +git clone --branch 0.3.0 git@github.com:gemini-cli-extensions/cloud-sql-postgresql.git |
| 150 | +``` |
| 151 | + |
| 152 | +**2. Install the plugin:** |
| 153 | + |
| 154 | +```bash |
| 155 | +mkdir -p ~/.codex/plugins |
| 156 | +cp -R /absolute/path/to/cloud-sql-postgresql ~/.codex/plugins/cloud-sql-postgresql |
| 157 | +``` |
| 158 | + |
| 159 | +**3. Set env vars:** |
| 160 | +Enter your environment vars as described in the [configuration section](#configuration). |
| 161 | + |
| 162 | +**4. Create or update marketplace.json:** |
| 163 | +`~/.agents/plugins/marketplace.json` |
| 164 | + |
| 165 | +```json |
| 166 | +{ |
| 167 | + "name": "my-data-cloud-google-marketplace", |
| 168 | + "interface": { |
| 169 | + "displayName": "Google Data Cloud Skills" |
| 170 | + }, |
| 171 | + "plugins": [ |
| 172 | + { |
| 173 | + "name": "cloud-sql-postgresql", |
| 174 | + "source": { |
| 175 | + "source": "local", |
| 176 | + "path": "./plugins/cloud-sql-postgresql" |
| 177 | + }, |
| 178 | + "policy": { |
| 179 | + "installation": "AVAILABLE", |
| 180 | + "authentication": "ON_INSTALL" |
| 181 | + }, |
| 182 | + "category": "Database" |
| 183 | + } |
| 184 | + ] |
| 185 | +} |
| 186 | +``` |
| 187 | + |
| 188 | +_(Tip: Run `codex plugin list` or use the `/plugins` interactive menu to verify your installed plugins.)_ |
| 189 | + |
| 190 | +</details> |
| 191 | + |
| 192 | +<!-- {x-release-please-end} --> |
89 | 193 |
|
90 | 194 | ## Usage Examples |
91 | 195 |
|
92 | 196 | Interact with Cloud SQL for PostgreSQL using natural language: |
93 | 197 |
|
94 | | -* **Provision Infrastructure:** |
95 | | - * "Create a new CLoud SQL for Postgres instance named 'e-commerce-prod' in the 'my-gcp-project' project." |
96 | | - * "Create a new user named 'analyst' with read access to all tables." |
97 | | -* **Explore Schemas and Data:** |
98 | | - * "Show me all tables in the 'orders' database." |
99 | | - * "What are the columns in the 'products' table?" |
100 | | - * "How many orders were placed in the last 30 days, and what were the top 5 most purchased items?" |
101 | | -* **Generate Code:** |
102 | | - * "Generate a Python dataclass to represent the 'customers' table." |
| 198 | +- **Provision Infrastructure:** |
| 199 | + - "Create a new Cloud SQL for Postgres instance named 'e-commerce-prod' in the 'my-gcp-project' project." |
| 200 | + - "Create a new user named 'analyst' with read access to all tables." |
| 201 | +- **Explore Schemas and Data:** |
| 202 | + - "Show me all tables in the 'orders' database." |
| 203 | + - "What are the columns in the 'products' table?" |
| 204 | + - "How many orders were placed in the last 30 days, and what were the top 5 most purchased items?" |
| 205 | +- **Generate Code:** |
| 206 | + - "Generate a Python dataclass to represent the 'customers' table." |
103 | 207 |
|
104 | 208 | ## Supported Skills |
105 | 209 |
|
106 | | -This extension provides the following skills: |
| 210 | +The following skills are available in this repository: |
| 211 | + |
| 212 | +- [Cloud SQL for PostgreSQL Admin](./skills/cloud-sql-postgres-admin/SKILL.md) - Use these skills when you need to provision new Cloud SQL instances, create databases and users, clone existing environments, and monitor the progress of long-running operations. |
| 213 | +- [Cloud SQL for PostgreSQL Data](./skills/cloud-sql-postgres-data/SKILL.md) - Use these skills when you need to explore the database structure, discover schema objects like views or stored procedures, and execute custom SQL queries to interact with your data. |
| 214 | +- [Cloud SQL for PostgreSQL Health](./skills/cloud-sql-postgres-health/SKILL.md) - Use these skills when you need to audit database health, identify storage bloat, find invalid indexes, analyze table statistics, and manage maintenance configurations like autovacuum. |
| 215 | +- [Cloud SQL for PostgreSQL Lifecycle](./skills/cloud-sql-postgres-lifecycle/SKILL.md) - Use these skills when you need to manage the lifecycle of your instances, including performing backups and restores, checking major version upgrade compatibility, and monitoring overall instance status. |
| 216 | +- [Cloud SQL for PostgreSQL Monitor](./skills/cloud-sql-postgres-monitor/SKILL.md) - Use these skills when you need to troubleshoot performance bottlenecks, analyze query execution plans, identify resource-heavy processes, and monitor system-level PromQL metrics. |
| 217 | +- [Cloud SQL for PostgreSQL Replication](./skills/cloud-sql-postgres-replication/SKILL.md) - Use these skills when you need to monitor replication health, manage sync states between nodes, and audit database roles and security settings to ensure environment integrity. |
| 218 | +- [Cloud SQL for PostgreSQL View Config](./skills/cloud-sql-postgres-view-config/SKILL.md) - Use these skills when you need to discover and manage PostgreSQL extensions or fine-tune engine-level settings such as memory allocation and server configuration parameters. |
107 | 219 |
|
108 | | -* [Cloud SQL for PostgreSQL Admin](./skills/cloud-sql-postgres-admin/SKILL.md) - Use these tools when you need to provision new Cloud SQL instances, create databases and users, clone existing environments, and monitor the progress of long-running operations. |
109 | | -* [Cloud SQL for PostgreSQL Data](./skills/cloud-sql-postgres-data/SKILL.md) - Use these tools when you need to explore the database structure, discover schema objects like views or stored procedures, and execute custom SQL queries to interact with your data. |
110 | | -* [Cloud SQL for PostgreSQL Health](./skills/cloud-sql-postgres-health/SKILL.md) - Use these tools when you need to audit database health, identify storage bloat, find invalid indexes, analyze table statistics, and manage maintenance configurations like autovacuum. |
111 | | -* [Cloud SQL for PostgreSQL Lifecycle](./skills/cloud-sql-postgres-lifecycle/SKILL.md) - Use these tools when you need to manage the lifecycle of your instances, including performing backups and restores, checking major version upgrade compatibility, and monitoring overall instance status. |
112 | | -* [Cloud SQL for PostgreSQL Monitor](./skills/cloud-sql-postgres-monitor/SKILL.md) - Use these tools when you need to troubleshoot performance bottlenecks, analyze query execution plans, identify resource-heavy processes, and monitor system-level PromQL metrics. |
113 | | -* [Cloud SQL for PostgreSQL Replication](./skills/cloud-sql-postgres-replication/SKILL.md) - Use these tools when you need to monitor replication health, manage sync states between nodes, and audit database roles and security settings to ensure environment integrity. |
114 | | -* [Cloud SQL for PostgreSQL View Config](./skills/cloud-sql-postgres-view-config/SKILL.md) - Use these tools when you need to discover and manage PostgreSQL extensions or fine-tune engine-level settings such as memory allocation and server configuration parameters. |
| 220 | +## Additional Agent Skills |
115 | 221 |
|
116 | | -## Additional Extensions |
| 222 | +Find additional skills to support your entire software development lifecycle at [github.com/gemini-cli-extensions](https://github.com/gemini-cli-extensions), including: |
117 | 223 |
|
118 | | -Find additional extensions to support your entire software development lifecycle at [github.com/gemini-cli-extensions](https://github.com/gemini-cli-extensions), including: |
119 | | -* [Generic PostgreSQL extension](https://github.com/gemini-cli-extensions/postgres) |
120 | | -* [Cloud SQL for PostgreSQL Observability extension](https://github.com/gemini-cli-extensions/cloud-sql-postgresql-observability) |
121 | | -* and more! |
| 224 | +- [Generic PostgreSQL skills](https://github.com/gemini-cli-extensions/postgres) |
| 225 | +- [Cloud SQL for PostgreSQL Observability skills](https://github.com/gemini-cli-extensions/cloud-sql-postgresql-observability) |
| 226 | +- and more! |
122 | 227 |
|
123 | 228 | ## Troubleshooting |
124 | 229 |
|
125 | | -Use `gemini --debug` to enable debugging. |
| 230 | +Use the debug mode of your agent (e.g., `gemini --debug`) to enable debugging. |
126 | 231 |
|
127 | 232 | Common issues: |
128 | 233 |
|
129 | | -* "failed to find default credentials: google: could not find default credentials.": Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. See [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/external/set-up-adc) for more information. |
130 | | -* "✖ Error during discovery for server: MCP error -32000: Connection closed": The database connection has not been established. Ensure your configuration is set via environment variables. |
131 | | -* "✖ MCP ERROR: Error: spawn /Users/USER/.gemini/extensions/cloud-sql-postgresql/toolbox ENOENT": The Toolbox binary did not download correctly. Ensure you are using Gemini CLI v0.6.0+. |
132 | | -* "cannot execute binary file": The Toolbox binary did not download correctly. Ensure the correct binary for your OS/Architecture has been downloaded. See [Installing the server](https://mcp-toolbox.dev/documentation/introduction/#install-toolbox) for more information. |
| 234 | +- "failed to find default credentials: google: could not find default credentials.": Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. See [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/external/set-up-adc) for more information. |
| 235 | +- "✖ Error during discovery for server: MCP error -32000: Connection closed": The database connection has not been established. Ensure your configuration is set via environment variables. |
| 236 | +- "✖ MCP ERROR: Error: spawn .../toolbox ENOENT": The Toolbox binary did not download correctly. Ensure you are using the latest version of your agent. |
| 237 | +- "cannot execute binary file": The Toolbox binary did not download correctly. Ensure the correct binary for your OS/Architecture has been downloaded. See [Installing the server](https://mcp-toolbox.dev/documentation/introduction/#install-toolbox) for more information. |
0 commit comments