Skip to content

Commit 5e43630

Browse files
nandinisaini-googleprernakakkar-googleaverikitsch
authored
feat(prebuilt/cloud-sql): Add clone instance tool for cloud sql (#1845)
## Description --- This pull request adds a new tool, cloud-sql-clone-instance, which enables cloning a Cloud SQL instance from the toolbox using the Cloud SQL Admin API. The tool supports both standard cloning and point-in-time recovery (PITR). It also supports specifying preferred zones for cloned instances via the preferredZone and preferredSecondaryZone fields. Key Features: Instance Cloning: The tool allows you to clone a Cloud SQL instance by specifying the source and destination instance names. Point-in-Time Recovery (PITR): By providing a pointInTime timestamp, you can create a clone of an instance as it existed at a specific moment. High Availability Configuration: The preferredZone and preferredSecondaryZone parameters allow you to configure the cloned instance for high availability. Tested: <img width="1182" height="446" alt="Screenshot 2025-11-11 at 12 21 47 PM" src="https://github.com/user-attachments/assets/7f39a5a3-3967-43d0-8041-f1d47b4fbcd9" /> ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #1915 Co-authored-by: prernakakkar-google <158031829+prernakakkar-google@users.noreply.github.com> Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 19c1b2f commit 5e43630

13 files changed

Lines changed: 615 additions & 3 deletions

File tree

‎cmd/root.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import (
8989
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries"
9090
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies"
9191
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudmonitoring"
92+
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlcloneinstance"
9293
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlcreatedatabase"
9394
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlcreateusers"
9495
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlgetinstances"

‎cmd/root_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ func TestPrebuiltTools(t *testing.T) {
14581458
wantToolset: server.ToolsetConfigs{
14591459
"cloud_sql_postgres_admin_tools": tools.ToolsetConfig{
14601460
Name: "cloud_sql_postgres_admin_tools",
1461-
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "postgres_upgrade_precheck"},
1461+
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "postgres_upgrade_precheck", "clone_instance"},
14621462
},
14631463
},
14641464
},
@@ -1468,7 +1468,7 @@ func TestPrebuiltTools(t *testing.T) {
14681468
wantToolset: server.ToolsetConfigs{
14691469
"cloud_sql_mysql_admin_tools": tools.ToolsetConfig{
14701470
Name: "cloud_sql_mysql_admin_tools",
1471-
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation"},
1471+
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance"},
14721472
},
14731473
},
14741474
},
@@ -1478,7 +1478,7 @@ func TestPrebuiltTools(t *testing.T) {
14781478
wantToolset: server.ToolsetConfigs{
14791479
"cloud_sql_mssql_admin_tools": tools.ToolsetConfig{
14801480
Name: "cloud_sql_mssql_admin_tools",
1481-
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation"},
1481+
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance"},
14821482
},
14831483
},
14841484
},

‎docs/en/how-to/connect-ide/cloud_sql_mssql_admin_mcp.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ instance, database and users:
5252
* All `editor` and `viewer` tools
5353
* `create_instance`
5454
* `create_user`
55+
* `clone_instance`
5556

5657
## Install MCP Toolbox
5758

@@ -297,6 +298,7 @@ instances and interacting with your database:
297298
* **list_databases**: Lists all databases for a Cloud SQL instance.
298299
* **create_user**: Creates a new user in a Cloud SQL instance.
299300
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
301+
* **clone_instance**: Creates a clone of an existing Cloud SQL for SQL Server instance.
300302
301303
{{< notice note >}}
302304
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs

‎docs/en/how-to/connect-ide/cloud_sql_mysql_admin_mcp.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ database and users:
5252
* All `editor` and `viewer` tools
5353
* `create_instance`
5454
* `create_user`
55+
* `clone_instance`
5556

5657
## Install MCP Toolbox
5758

@@ -297,6 +298,7 @@ instances and interacting with your database:
297298
* **list_databases**: Lists all databases for a Cloud SQL instance.
298299
* **create_user**: Creates a new user in a Cloud SQL instance.
299300
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
301+
* **clone_instance**: Creates a clone of an existing Cloud SQL for MySQL instance.
300302
301303
{{< notice note >}}
302304
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs

‎docs/en/how-to/connect-ide/cloud_sql_pg_admin_mcp.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ instance, database and users:
5252
* All `editor` and `viewer` tools
5353
* `create_instance`
5454
* `create_user`
55+
* `clone_instance`
5556

5657
## Install MCP Toolbox
5758

@@ -297,6 +298,7 @@ instances and interacting with your database:
297298
* **list_databases**: Lists all databases for a Cloud SQL instance.
298299
* **create_user**: Creates a new user in a Cloud SQL instance.
299300
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
301+
* **clone_instance**: Creates a clone of an existing Cloud SQL for PostgreSQL instance.
300302
301303
{{< notice note >}}
302304
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs

‎docs/en/reference/prebuilt-tools.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
178178
* All `editor` and `viewer` tools
179179
* `create_instance`
180180
* `create_user`
181+
* `clone_instance`
182+
181183
* **Tools:**
182184
* `create_instance`: Creates a new Cloud SQL for MySQL instance.
183185
* `get_instance`: Gets information about a Cloud SQL instance.
@@ -186,6 +188,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
186188
* `list_databases`: Lists all databases for a Cloud SQL instance.
187189
* `create_user`: Creates a new user in a Cloud SQL instance.
188190
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
191+
* `clone_instance`: Creates a clone for an existing Cloud SQL for MySQL instance.
189192

190193
## Cloud SQL for PostgreSQL
191194

@@ -257,6 +260,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
257260
* All `editor` and `viewer` tools
258261
* `create_instance`
259262
* `create_user`
263+
* `clone_instance`
260264
* **Tools:**
261265
* `create_instance`: Creates a new Cloud SQL for PostgreSQL instance.
262266
* `get_instance`: Gets information about a Cloud SQL instance.
@@ -265,6 +269,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
265269
* `list_databases`: Lists all databases for a Cloud SQL instance.
266270
* `create_user`: Creates a new user in a Cloud SQL instance.
267271
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
272+
* `clone_instance`: Creates a clone for an existing Cloud SQL for PostgreSQL instance.
268273

269274
## Cloud SQL for SQL Server
270275

@@ -316,6 +321,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
316321
* All `editor` and `viewer` tools
317322
* `create_instance`
318323
* `create_user`
324+
* `clone_instance`
319325
* **Tools:**
320326
* `create_instance`: Creates a new Cloud SQL for SQL Server instance.
321327
* `get_instance`: Gets information about a Cloud SQL instance.
@@ -324,6 +330,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
324330
* `list_databases`: Lists all databases for a Cloud SQL instance.
325331
* `create_user`: Creates a new user in a Cloud SQL instance.
326332
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
333+
* `clone_instance`: Creates a clone for an existing Cloud SQL for SQL Server instance.
327334

328335
## Dataplex
329336

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: cloud-sql-clone-instance
3+
type: docs
4+
weight: 10
5+
description: "Clone a Cloud SQL instance."
6+
---
7+
8+
The `cloud-sql-clone-instance` tool clones a Cloud SQL instance using the Cloud SQL Admin API.
9+
10+
{{< notice info dd>}}
11+
This tool uses a `source` of kind `cloud-sql-admin`.
12+
{{< /notice >}}
13+
14+
## Examples
15+
16+
Basic clone (current state)
17+
18+
```yaml
19+
tools:
20+
clone-instance-basic:
21+
kind: cloud-sql-clone-instance
22+
source: cloud-sql-admin-source
23+
description: "Creates an exact copy of a Cloud SQL instance. Supports configuring instance zones and high-availability setup through zone preferences."
24+
```
25+
26+
Point-in-time recovery (PITR) clone
27+
28+
```yaml
29+
tools:
30+
clone-instance-pitr:
31+
kind: cloud-sql-clone-instance
32+
source: cloud-sql-admin-source
33+
description: "Creates an exact copy of a Cloud SQL instance at a specific point in time (PITR). Supports configuring instance zones and high-availability setup through zone preferences"
34+
```
35+
36+
## Reference
37+
38+
### Tool Configuration
39+
40+
| **field** | **type** | **required** | **description** |
41+
| -------------- | :------: | :----------: | ------------------------------------------------------------- |
42+
| kind | string | true | Must be "cloud-sql-clone-instance". |
43+
| source | string | true | The name of the `cloud-sql-admin` source to use. |
44+
| description | string | false | A description of the tool. |
45+
46+
### Tool Inputs
47+
48+
| **parameter** | **type** | **required** | **description** |
49+
| -------------------------- | :------: | :----------: | ------------------------------------------------------------------------------- |
50+
| project | string | true | The project ID. |
51+
| sourceInstanceName | string | true | The name of the source instance to clone. |
52+
| destinationInstanceName | string | true | The name of the new (cloned) instance. |
53+
| pointInTime | string | false | (Optional) The point in time for a PITR (Point-In-Time Recovery) clone. |
54+
| preferredZone | string | false | (Optional) The preferred zone for the cloned instance. If not specified, defaults to the source instance's zone. |
55+
| preferredSecondaryZone | string | false | (Optional) The preferred secondary zone for the cloned instance (for HA). |
56+
57+
## Usage Notes
58+
59+
- The tool supports both basic clone and point-in-time recovery (PITR) clone operations.
60+
- For PITR, specify the `pointInTime` parameter in RFC3339 format (e.g., `2024-01-01T00:00:00Z`).
61+
- The source must be a valid Cloud SQL Admin API source.
62+
- You can optionally specify the `zone` parameter to set the zone for the cloned instance. If omitted, the zone of the source instance will be used.
63+
- You can optionally specify the `preferredZone` and `preferredSecondaryZone` (only in REGIONAL instances) to set the preferred zones for the cloned instance. These are useful for high availability (HA) configurations. If omitted, defaults will be used based on the source instance.
64+
65+
## See Also
66+
- [Cloud SQL Admin API documentation](https://cloud.google.com/sql/docs/mysql/admin-api)
67+
- [Toolbox Cloud SQL tools documentation](../cloudsql)
68+
- [Cloud SQL Clone API documentation](https://cloud.google.com/sql/docs/mysql/clone-instance)

‎internal/prebuiltconfigs/tools/cloud-sql-mssql-admin.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ tools:
3939
wait_for_operation:
4040
kind: cloud-sql-wait-for-operation
4141
source: cloud-sql-admin-source
42+
multiplier: 4
43+
clone_instance:
44+
kind: cloud-sql-clone-instance
45+
source: cloud-sql-admin-source
4246

4347
toolsets:
4448
cloud_sql_mssql_admin_tools:
@@ -49,3 +53,4 @@ toolsets:
4953
- list_databases
5054
- create_user
5155
- wait_for_operation
56+
- clone_instance

‎internal/prebuiltconfigs/tools/cloud-sql-mysql-admin.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ tools:
3939
wait_for_operation:
4040
kind: cloud-sql-wait-for-operation
4141
source: cloud-sql-admin-source
42+
multiplier: 4
43+
clone_instance:
44+
kind: cloud-sql-clone-instance
45+
source: cloud-sql-admin-source
4246

4347
toolsets:
4448
cloud_sql_mysql_admin_tools:
@@ -49,3 +53,4 @@ toolsets:
4953
- list_databases
5054
- create_user
5155
- wait_for_operation
56+
- clone_instance

‎internal/prebuiltconfigs/tools/cloud-sql-postgres-admin.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ tools:
3939
wait_for_operation:
4040
kind: cloud-sql-wait-for-operation
4141
source: cloud-sql-admin-source
42+
multiplier: 4
43+
clone_instance:
44+
kind: cloud-sql-clone-instance
45+
source: cloud-sql-admin-source
4246
postgres_upgrade_precheck:
4347
kind: postgres-upgrade-precheck
4448
source: cloud-sql-admin-source
@@ -53,3 +57,4 @@ toolsets:
5357
- create_user
5458
- wait_for_operation
5559
- postgres_upgrade_precheck
60+
- clone_instance

0 commit comments

Comments
 (0)