Skip to content

Commit 7a6d849

Browse files
pavankrishna13gemini-code-assist[bot]duwenxin99
authored
feat(tools/cloudsqlpg): Add vector assist tools for Cloud SQL Postgres (#2909)
## Description Adds 4 new mcp tools for Cloud SQL Postgres source related to the vector assist postgres extension. These tools enable the customers to set up and optimize production-ready vector workloads by simply expressing your intent and performance requirements. | Tool Set | Description | |:---------------------------------|:------------------------------------------------------------------------ | | `vectorassist` | Use these skills to set up and optimize production-ready vector workloads | | | by simply expressing your intent and performance requirements | | Tool Name | Description | |:---------------------------------|:---------------------------------------------------------------| | `define_spec` | Defines a new vector specification for search workloads. | | `modify_spec` | Modifies an existing vector specification. | | `apply_spec` | Executes SQL recommendations for a vector specification. | | `generate_query` | Generates optimized SQL queries for vector searches. | ## Manual testing Workflows covered by these tools ### 1. Setup vector search in the database Prompt : Set up the table 'cymbal_products' for vector workloads where I want to perform a similarity search on the embeddings generated for the column 'product_description'. Expected tools to be used in the CUJ : define-spec -> apply-spec <img width="1282" height="639" alt="Screenshot 2026-04-09 at 2 50 02 PM" src="https://github.com/user-attachments/assets/0c05fb23-88df-4c26-9dd3-59678ed6cc90" /> <img width="1289" height="717" alt="Screenshot 2026-04-09 at 2 52 34 PM" src="https://github.com/user-attachments/assets/e1a2e4ea-cadc-4692-b0f5-dc4c914710a6" /> <img width="1270" height="683" alt="Screenshot 2026-04-09 at 3 04 17 PM" src="https://github.com/user-attachments/assets/a2ac1349-5815-45c1-abc6-fd8210a5570f" /> <img width="1281" height="462" alt="Screenshot 2026-04-09 at 3 06 12 PM" src="https://github.com/user-attachments/assets/bce60906-2723-4a64-aaa0-9095fc83466b" /> ### 2. Modify & apply spec Prompt : Modify the vector specification 'cymbal_products' table to generate embeddings on the column 'product_description' using the embedding model 'text-embedding-004' Expected tools to be used in the CUJ : define-spec -> modify-spec -> apply-spec <img width="1180" height="798" alt="Screenshot 2026-04-09 at 9 45 03 PM" src="https://github.com/user-attachments/assets/d8566527-a04d-4209-b78f-693ffb8e9298" /> <img width="1171" height="373" alt="Screenshot 2026-04-09 at 9 35 27 PM" src="https://github.com/user-attachments/assets/b6c894c3-1c6f-4d4b-85d1-59832d097b4f" /> <img width="1175" height="598" alt="Screenshot 2026-04-09 at 9 37 11 PM" src="https://github.com/user-attachments/assets/45c79bb5-5509-4196-84c9-0e091fd1168f" /> <img width="1176" height="622" alt="Screenshot 2026-04-09 at 9 39 12 PM" src="https://github.com/user-attachments/assets/5eaffd4c-5315-482f-8616-a3c4503a65ef" /> ### 3. Find top-k similarity items Prompt : find the top 10 products from cymbal_products table which have description similar to this query "What kind of fruit trees grow well here?" Expected tools to be used in the CUJ : generate-query -> execute-sql <img width="1273" height="259" alt="Screenshot 2026-04-09 at 3 25 48 PM" src="https://github.com/user-attachments/assets/79d71a31-a9ce-4948-aa75-d35dc33f4420" /> <img width="1275" height="483" alt="Screenshot 2026-04-09 at 3 26 12 PM" src="https://github.com/user-attachments/assets/2d54327d-c048-457e-9e44-4c710e1523d3" /> <img width="1246" height="619" alt="Screenshot 2026-04-09 at 3 27 12 PM" src="https://github.com/user-attachments/assets/d2a1a021-f179-4d86-9050-50a2dbefac64" /> ## 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) - [x] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com>
1 parent 39c02e6 commit 7a6d849

17 files changed

Lines changed: 1660 additions & 0 deletions

cmd/internal/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,10 @@ func TestPrebuiltTools(t *testing.T) {
17471747
Name: "replication",
17481748
ToolNames: []string{"replication_stats", "list_replication_slots", "list_publication_tables", "list_roles", "list_pg_settings", "database_overview"},
17491749
},
1750+
"vectorassist": {
1751+
Name: "vectorassist",
1752+
ToolNames: []string{"execute_sql", "define_spec", "modify_spec", "apply_spec", "generate_query"},
1753+
},
17501754
},
17511755
},
17521756
{

cmd/internal/imports.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ import (
7979
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance"
8080
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances"
8181
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck"
82+
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/vectorassistapplyspec"
83+
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/vectorassistdefinespec"
84+
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/vectorassistgeneratequery"
85+
_ "github.com/googleapis/mcp-toolbox/internal/tools/cloudsqlpg/vectorassistmodifyspec"
8286
_ "github.com/googleapis/mcp-toolbox/internal/tools/cockroachdb/cockroachdbexecutesql"
8387
_ "github.com/googleapis/mcp-toolbox/internal/tools/cockroachdb/cockroachdblistschemas"
8488
_ "github.com/googleapis/mcp-toolbox/internal/tools/cockroachdb/cockroachdblisttables"

docs/CLOUDSQLPG_README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ The Cloud SQL for PostgreSQL MCP server provides the following tools:
7272
| `list_triggers` | Lists all non-internal triggers in a database. |
7373
| `list_indexes` | Lists available user indexes in the database. |
7474
| `list_sequences` | Lists sequences in the database. |
75+
| `define_spec` | Defines a new vector specification for search workloads. |
76+
| `modify_spec` | Modifies an existing vector specification. |
77+
| `apply_spec` | Executes SQL recommendations for a vector specification. |
78+
| `generate_query` | Generates optimized SQL queries for vector searches. |
7579

7680

7781
## Custom MCP Server Configuration
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "vector-assist-apply-spec"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "vector-assist-apply-spec" tool automatically executes all SQL recommendations
7+
associated with a specific vector specification or table to finalize the
8+
vector search setup.
9+
---
10+
11+
## About
12+
13+
The `vector-assist-apply-spec` tool automatically executes all the SQL recommendations associated with a specific vector specification (spec_id) or table. It runs the necessary commands in the correct sequence to provision the workload, marking each step as applied once successful.
14+
15+
Use this tool when the user has reviewed the generated recommendations from a defined (or modified) spec and is ready to apply the changes directly to their database instance to finalize the vector search setup. Under the hood, this tool connects to the target database and executes the `vector_assist.apply_spec` function.
16+
17+
## Compatible Sources
18+
19+
{{< compatible-sources >}}
20+
21+
## Requirements
22+
23+
{{< notice tip >}}
24+
Ensure that your target PostgreSQL database has the required `vector_assist` extension installed, in order for this tool to execute successfully.
25+
{{< /notice >}}
26+
27+
## Parameters
28+
29+
The tool takes the following input parameters:
30+
31+
| Parameter | Type | Description | Required |
32+
| :------------ | :----- | :-------------------------------------------------------------------- | :------- |
33+
| `spec_id` | string | Unique ID of the vector specification to apply. | No |
34+
| `table_name` | string | Target table name for applying the vector specification. | No |
35+
| `column_name` | string | Text or vector column name to uniquely identify the specification. | No |
36+
| `schema_name` | string | Schema name for the target table. | No |
37+
38+
> Note
39+
> Parameters are marked as required or optional based on the vector assist function definitions.
40+
> The function may perform further validation on optional parameters to ensure all necessary
41+
> data is available before returning a response.
42+
43+
## Example
44+
45+
```yaml
46+
kind: tool
47+
name: apply_spec
48+
type: vector-assist-apply-spec
49+
source: my-database-source
50+
description: "This tool automatically executes all the SQL recommendations associated with a specific vector specification (spec_id) or table. It runs the necessary commands in the correct sequence to provision the workload, marking each step as applied once successful. Use this tool when the user has reviewed the generated recommendations from a defined (or modified) spec and is ready to apply the changes directly to their database instance to finalize the vector search setup."
51+
```
52+
53+
## Reference
54+
55+
| **field** | **type** | **required** | **description** |
56+
|-------------|:--------:|:------------:|------------------------------------------------------|
57+
| type | string | true | Must be "vector-assist-apply-spec". |
58+
| source | string | true | Name of the source the SQL should execute on. |
59+
| description | string | false | Description of the tool that is passed to the agent. |
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "vector-assist-define-spec"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "vector-assist-define-spec" tool defines a new vector specification by
7+
capturing the user's intent and requirements for a vector search workload,
8+
generating SQL recommendations for setting up database, embeddings, and
9+
vector indexes.
10+
---
11+
12+
## About
13+
14+
The `vector-assist-define-spec` tool defines a new vector specification by capturing the user's intent and requirements for a vector search workload. It generates a complete, ordered set of SQL recommendations required to set up the database, embeddings, and vector indexes.
15+
16+
Use this tool at the very beginning of the vector setup process when an agent or user first wants to configure a table for vector search, generate embeddings, or create a new vector index. Under the hood, this tool connects to the target database and executes the `vector_assist.define_spec` function to generate the necessary specifications.
17+
18+
## Compatible Sources
19+
20+
{{< compatible-sources >}}
21+
22+
## Requirements
23+
24+
{{< notice tip >}}
25+
Ensure that your target PostgreSQL database has the required `vector_assist` extension installed, in order for this tool to execute successfully.
26+
{{< /notice >}}
27+
28+
## Parameters
29+
30+
The tool takes the following input parameters:
31+
32+
| Parameter | Type | Description | Required |
33+
| :----------------------- | :------ | :--------------------------------------------------------------------- | :------- |
34+
| `table_name` | string | Target table name for setting up the vector workload. | Yes |
35+
| `schema_name` | string | Name of the schema containing the target table. | No |
36+
| `spec_id` | string | Unique ID for the vector specification; auto-generated if omitted. | No |
37+
| `vector_column_name` | string | Name of the column containing the vector embeddings. | No |
38+
| `text_column_name` | string | Name of the text column for setting up vector search. | No |
39+
| `vector_index_type` | string | Type of vector index ('hnsw', 'ivfflat', or 'scann'). | No |
40+
| `embeddings_available` | boolean | Indicates if vector embeddings already exist in the table. | No |
41+
| `num_vectors` | integer | Expected total number of vectors in the dataset. | No |
42+
| `dimensionality` | integer | Dimension of existing vectors or the chosen embedding model. | No |
43+
| `embedding_model` | string | Model to be used for generating vector embeddings. | No |
44+
| `prefilter_column_names` | array | List of columns to use for prefiltering vector queries. | No |
45+
| `distance_func` | string | Distance function for comparing vectors ('cosine', 'ip', 'l2', 'l1'). | No |
46+
| `quantization` | string | Quantization method for vector indexes ('none', 'halfvec', 'bit'). | No |
47+
| `memory_budget_kb` | integer | Maximum memory (in KB) the index can use during build. | No |
48+
| `target_recall` | float | Target recall rate for standard vector queries using this index. | No |
49+
| `target_top_k` | integer | Number of top results (top-K) to retrieve per query. | No |
50+
| `tune_vector_index` | boolean | Indicates whether automatic tuning is required for the index. | No |
51+
52+
> Note
53+
> Parameters are marked as required or optional based on the vector assist function definitions.
54+
> The function may perform further validation on optional parameters to ensure all necessary
55+
> data is available before returning a response.
56+
57+
## Example
58+
59+
```yaml
60+
kind: tool
61+
name: define_spec
62+
type: vector-assist-define-spec
63+
source: my-database-source
64+
description: "This tool defines a new vector specification by capturing the user's intent and requirements for a vector search workload. This generates a complete, ordered set of SQL recommendations required to set up the database, embeddings, and vector indexes. Use this tool at the very beginning of the vector setup process when a user first wants to configure a table for vector search, generate embeddings, or create a new vector index."
65+
```
66+
67+
## Reference
68+
69+
| **field** | **type** | **required** | **description** |
70+
|-------------|:--------:|:------------:|------------------------------------------------------|
71+
| type | string | true | Must be "vector-assist-define-spec". |
72+
| source | string | true | Name of the source the SQL should execute on. |
73+
| description | string | false | Description of the tool that is passed to the agent. |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "vector-assist-generate-query"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "vector-assist-generate-query" tool produces optimized SQL queries for
7+
vector search, leveraging metadata and specifications to enable semantic
8+
and similarity searches.
9+
---
10+
11+
## About
12+
13+
The `vector-assist-generate-query` tool generates optimized SQL queries for vector search by leveraging the metadata and vector specifications defined in a specific spec_id. It serves as the primary actionable tool for generating the executable SQL required to retrieve relevant results based on vector similarity.
14+
15+
The tool contextually understands requirements such as distance functions, quantization, and filtering to ensure the resulting query is compatible with the corresponding vector index. Additionally, it can automatically handle iterative index scans for filtered queries and calculate the necessary search parameters (like ef_search) to meet a target recall.
16+
## Compatible Sources
17+
18+
{{< compatible-sources >}}
19+
20+
## Requirements
21+
22+
{{< notice tip >}}
23+
Ensure that your target PostgreSQL database has the required `vector_assist` extension installed, in order for this tool to execute successfully.
24+
{{< /notice >}}
25+
26+
## Parameters
27+
28+
The tool takes the following input parameters:
29+
30+
| Parameter | Type | Description | Required |
31+
| :----------------------- | :------ | :------------------------------------------------------------------ | :------- |
32+
| `spec_id` | string | Unique ID of the vector spec for query generation. | No |
33+
| `table_name` | string | Target table name for generating the vector query. | No |
34+
| `schema_name` | string | Schema name for the query's target table. | No |
35+
| `column_name` | string | Text or vector column name identifying the specific spec. | No |
36+
| `search_text` | string | Text string to search for; embeddings are auto-generated. | No |
37+
| `search_vector` | string | Vector to search for; use instead of search_text. | No |
38+
| `output_column_names` | array | List of columns to retrieve in the search results. | No |
39+
| `top_k` | integer | Number of nearest neighbors to return (defaults to 10). | No |
40+
| `filter_expressions` | array | List of filter expressions applied to the vector query. | No |
41+
| `target_recall` | float | Target recall rate, overriding the spec-level default. | No |
42+
| `iterative_index_search` | boolean | Enables iterative search for filtered queries to guarantee results. | No |
43+
44+
> Note
45+
> Parameters are marked as required or optional based on the vector assist function definitions.
46+
> The function may perform further validation on optional parameters to ensure all necessary
47+
> data is available before returning a response.
48+
49+
## Example
50+
51+
```yaml
52+
kind: tool
53+
name: generate_query
54+
type: vector-assist-generate-query
55+
source: my-database-source
56+
description: "This tool generates optimized SQL queries for vector search by leveraging the metadata and vector specifications defined in a specific spec_id. It may return a single query or a sequence of multiple SQL queries that can be executed sequentially. Use this tool when a user wants to perform semantic or similarity searches on their data. It serves as the primary actionable tool to invoke for generating the executable SQL required to retrieve relevant results based on vector similarity."
57+
```
58+
59+
## Reference
60+
61+
| **field** | **type** | **required** | **description** |
62+
|-------------|:--------:|:------------:|------------------------------------------------------|
63+
| type | string | true | Must be "vector-assist-generate-query". |
64+
| source | string | true | Name of the source the SQL should execute on. |
65+
| description | string | false | Description of the tool that is passed to the agent. |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "vector-assist-modify-spec"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "vector-assist-modify-spec" tool modifies an existing vector specification
7+
with new parameters or overrides, recalculating the generated SQL
8+
recommendations to match the updated requirements.
9+
---
10+
11+
## About
12+
13+
The `vector-assist-modify-spec` tool modifies an existing vector specification (identified by a required `spec_id`) with new parameters or overrides. Upon modification, it automatically recalculates and refreshes the list of generated recommendations by `vector_assist.define-spec` to match the updated spec requirements.
14+
15+
Use this tool when a user or agent wants to adjust or fine-tune the configuration of an already defined vector spec (such as changing the target recall, embedding model, or quantization) before actually executing the setup commands. Under the hood, this tool connects to the target database and executes the `vector_assist.modify_spec` function to generate the updated specifications.
16+
17+
## Compatible Sources
18+
19+
{{< compatible-sources >}}
20+
21+
## Requirements
22+
23+
{{< notice tip >}}
24+
Ensure that your target PostgreSQL database has the required `vector_assist` extension installed, and that the `vector_assist.modify_spec` function is available in order for this tool to execute successfully.
25+
{{< /notice >}}
26+
27+
## Parameters
28+
29+
The tool takes the following input parameters:
30+
31+
| Parameter | Type | Description | Required |
32+
| :----------------------- | :------ | :--------------------------------------------------------------------- | :------- |
33+
| `spec_id` | string | Unique ID of the vector specification to modify. | Yes |
34+
| `table_name` | string | New table name for the vector workload setup. | No |
35+
| `schema_name` | string | New schema name containing the target table. | No |
36+
| `vector_column_name` | string | New name for the column containing vector embeddings. | No |
37+
| `text_column_name` | string | New name for the text column for vector search. | No |
38+
| `vector_index_type` | string | New vector index type ('hnsw', 'ivfflat', or 'scann'). | No |
39+
| `embeddings_available` | boolean | Update if vector embeddings already exist in the table. | No |
40+
| `num_vectors` | integer | Update the expected total number of vectors. | No |
41+
| `dimensionality` | integer | Update the dimension of vectors or the embedding model. | No |
42+
| `embedding_model` | string | Update the model used for generating vector embeddings. | No |
43+
| `prefilter_column_names` | array | Update the columns used for prefiltering vector queries. | No |
44+
| `distance_func` | string | Update the distance function ('cosine', 'ip', 'l2', 'l1'). | No |
45+
| `quantization` | string | Update the quantization method ('none', 'halfvec', 'bit'). | No |
46+
| `memory_budget_kb` | integer | Update maximum memory (in KB) for index building. | No |
47+
| `target_recall` | float | Update the target recall rate for the index. | No |
48+
| `target_top_k` | integer | Update the number of top results (top-K) to retrieve. | No |
49+
| `tune_vector_index` | boolean | Update whether automatic tuning is required for the index. | No |
50+
51+
> Note
52+
> Parameters are marked as required or optional based on the vector assist function definitions.
53+
> The function may perform further validation on optional parameters to ensure all necessary
54+
> data is available before returning a response.
55+
56+
## Example
57+
58+
```yaml
59+
kind: tool
60+
name: modify_spec
61+
type: vector-assist-modify-spec
62+
source: my-database-source
63+
description: "This tool modifies an existing vector specification (identified by a required spec_id) with new parameters or overrides. Upon modification, it automatically recalculates and refreshes the list of generated SQL recommendations to match the updated requirements. Use this tool when a user wants to adjust or fine-tune the configuration of an already defined vector spec (such as changing the target recall, embedding model, or quantization) before actually executing the setup commands."
64+
```
65+
66+
## Reference
67+
68+
| **field** | **type** | **required** | **description** |
69+
|-------------|:--------:|:------------:|------------------------------------------------------|
70+
| type | string | true | Must be "vector-assist-modify-spec". |
71+
| source | string | true | Name of the source the SQL should execute on. |
72+
| description | string | false | Description of the tool that is passed to the agent. |

0 commit comments

Comments
 (0)