Skip to content

Commit 9a5f601

Browse files
srividyareddy786rahulpinto19
authored andcommitted
feat(tools/postgres-list-tablespaces): add new postgres-list-tablespaces tool (#1934)
## Description Adds a postgresql custom list_tablespaces tool, that returns the details of tablespaces present in database. <img width="1719" height="698" alt="Screenshot 2025-11-12 at 9 11 13 AM" src="https://github.com/user-attachments/assets/03964a1b-27e0-4da8-85a2-57db905163ed" /> <img width="1077" height="141" alt="Screenshot 2025-11-12 at 9 12 42 AM" src="https://github.com/user-attachments/assets/f93f5692-eb62-4f30-8192-40c8873d4d00" /> > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution Lists all tablespaces in the database. Returns the tablespace name, owner name, size in bytes, internal object ID, the access control list regarding permissions, and any specific tablespace options. ## 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 #1738
1 parent 9bd2c75 commit 9a5f601

File tree

17 files changed

+433
-8
lines changed

17 files changed

+433
-8
lines changed

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ import (
192192
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistschemas"
193193
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistsequences"
194194
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttables"
195+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttablespaces"
195196
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttriggers"
196197
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistviews"
197198
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslongrunningtransactions"

cmd/root_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ func TestPrebuiltTools(t *testing.T) {
14881488
wantToolset: server.ToolsetConfigs{
14891489
"alloydb_postgres_database_tools": tools.ToolsetConfig{
14901490
Name: "alloydb_postgres_database_tools",
1491-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables"},
1491+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables", "list_tablespaces"},
14921492
},
14931493
},
14941494
},
@@ -1518,7 +1518,7 @@ func TestPrebuiltTools(t *testing.T) {
15181518
wantToolset: server.ToolsetConfigs{
15191519
"cloud_sql_postgres_database_tools": tools.ToolsetConfig{
15201520
Name: "cloud_sql_postgres_database_tools",
1521-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables"},
1521+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables", "list_tablespaces"},
15221522
},
15231523
},
15241524
},
@@ -1618,7 +1618,7 @@ func TestPrebuiltTools(t *testing.T) {
16181618
wantToolset: server.ToolsetConfigs{
16191619
"postgres_database_tools": tools.ToolsetConfig{
16201620
Name: "postgres_database_tools",
1621-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables"},
1621+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables", "list_tablespaces"},
16221622
},
16231623
},
16241624
},

docs/en/reference/prebuilt-tools.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
5151
* `list_indexes`: List available user indexes in a PostgreSQL database.
5252
* `list_sequences`: List sequences in a PostgreSQL database.
5353
* `list_publication_tables`: List publication tables in a PostgreSQL database.
54+
* `list_tablespaces`: Lists tablespaces in the database.
5455

5556
## AlloyDB Postgres Admin
5657

@@ -229,6 +230,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
229230
* `list_indexes`: List available user indexes in a PostgreSQL database.
230231
* `list_sequences`: List sequences in a PostgreSQL database.
231232
* `list_publication_tables`: List publication tables in a PostgreSQL database.
233+
* `list_tablespaces`: Lists tablespaces in the database.
232234

233235
## Cloud SQL for PostgreSQL Observability
234236

@@ -535,6 +537,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
535537
* `list_indexes`: List available user indexes in a PostgreSQL database.
536538
* `list_sequences`: List sequences in a PostgreSQL database.
537539
* `list_publication_tables`: List publication tables in a PostgreSQL database.
540+
* `list_tablespaces`: Lists tablespaces in the database.
538541

539542
## Google Cloud Serverless for Apache Spark
540543

docs/en/resources/sources/alloydb-pg.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ cluster][alloydb-free-trial].
8080
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
8181
List publication tables in a PostgreSQL database.
8282

83+
- [`postgres-list-tablespaces`](../tools/postgres/postgres-list-tablespaces.md)
84+
List tablespaces in an AlloyDB for PostgreSQL database.
85+
8386
### Pre-built Configurations
8487

8588
- [AlloyDB using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/alloydb_pg_mcp/)

docs/en/resources/sources/cloud-sql-pg.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ to a database by following these instructions][csql-pg-quickstart].
7676
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
7777
List publication tables in a PostgreSQL database.
7878

79+
- [`postgres-list-tablespaces`](../tools/postgres/postgres-list-tablespaces.md)
80+
List tablespaces in a PostgreSQL database.
81+
7982
### Pre-built Configurations
8083

8184
- [Cloud SQL for Postgres using

docs/en/resources/sources/postgres.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ reputation for reliability, feature robustness, and performance.
7171
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
7272
List publication tables in a PostgreSQL database.
7373

74+
- [`postgres-list-tablespaces`](../tools/postgres/postgres-list-tablespaces.md)
75+
List tablespaces in a PostgreSQL database.
76+
7477
### Pre-built Configurations
7578

7679
- [PostgreSQL using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/postgres_mcp/)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "postgres-list-tablespaces"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-list-tablespaces" tool lists tablespaces in a Postgres database.
7+
aliases:
8+
- /resources/tools/postgres-list-tablespaces
9+
---
10+
11+
## About
12+
13+
The `postgres-list-tablespaces` tool lists available tablespaces in the database. It's compatible with any of the following sources:
14+
15+
- [alloydb-postgres](../../sources/alloydb-pg.md)
16+
- [cloud-sql-postgres](../../sources/cloud-sql-pg.md)
17+
- [postgres](../../sources/postgres.md)
18+
19+
`postgres-list-tablespaces` lists detailed information as JSON for tablespaces. The tool takes the following input parameters:
20+
21+
- `tablespace_name` (optional): A text to filter results by tablespace name. Default: `""`
22+
- `limit` (optional): The maximum number of tablespaces to return. Default: `50`
23+
24+
## Example
25+
26+
```yaml
27+
tools:
28+
list_tablespaces:
29+
kind: postgres-list-tablespaces
30+
source: postgres-source
31+
description: |
32+
Lists all tablespaces in the database. Returns the tablespace name,
33+
owner name, size in bytes(if the current user has CREATE privileges on
34+
the tablespace, otherwise NULL), internal object ID, the access control
35+
list regarding permissions, and any specific tablespace options.
36+
```
37+
The response is a json array with the following elements:
38+
39+
```json
40+
{
41+
"tablespace_name": "name of the tablespace",
42+
"owner_username": "owner of the tablespace",
43+
"size_in_bytes": "size in bytes if the current user has CREATE privileges on the tablespace, otherwise NULL",
44+
"oid": "Object ID of the tablespace",
45+
"spcacl": "Access privileges",
46+
"spcoptions": "Tablespace-level options (e.g., seq_page_cost, random_page_cost)"
47+
}
48+
```
49+
50+
## Reference
51+
52+
| **field** | **type** | **required** | **description** |
53+
|-------------|:--------:|:-------------:|------------------------------------------------------|
54+
| kind | string | true | Must be "postgres-list-tablespaces". |
55+
| source | string | true | Name of the source the SQL should execute on. |
56+
| description | string | false | Description of the tool that is passed to the agent. |

internal/prebuiltconfigs/tools/alloydb-postgres.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ tools:
175175
list_schemas:
176176
kind: postgres-list-schemas
177177
source: alloydb-pg-source
178-
178+
179179
list_indexes:
180180
kind: postgres-list-indexes
181181
source: alloydb-pg-source
@@ -204,6 +204,10 @@ tools:
204204
kind: postgres-list-publication-tables
205205
source: alloydb-pg-source
206206

207+
list_tablespaces:
208+
kind: postgres-list-tablespaces
209+
source: alloydb-pg-source
210+
207211
toolsets:
208212
alloydb_postgres_database_tools:
209213
- execute_sql
@@ -229,3 +233,4 @@ toolsets:
229233
- list_query_stats
230234
- get_column_cardinality
231235
- list_publication_tables
236+
- list_tablespaces

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ tools:
177177
list_schemas:
178178
kind: postgres-list-schemas
179179
source: cloudsql-pg-source
180-
180+
181181
database_overview:
182182
kind: postgres-database-overview
183183
source: cloudsql-pg-source
@@ -206,6 +206,10 @@ tools:
206206
kind: postgres-list-publication-tables
207207
source: cloudsql-pg-source
208208

209+
list_tablespaces:
210+
kind: postgres-list-tablespaces
211+
source: cloudsql-pg-source
212+
209213
toolsets:
210214
cloud_sql_postgres_database_tools:
211215
- execute_sql
@@ -231,3 +235,4 @@ toolsets:
231235
- list_query_stats
232236
- get_column_cardinality
233237
- list_publication_tables
238+
- list_tablespaces

internal/prebuiltconfigs/tools/postgres.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ tools:
176176
list_schemas:
177177
kind: postgres-list-schemas
178178
source: postgresql-source
179-
179+
180180
database_overview:
181181
kind: postgres-database-overview
182182
source: postgresql-source
@@ -205,6 +205,10 @@ tools:
205205
kind: postgres-list-publication-tables
206206
source: postgresql-source
207207

208+
list_tablespaces:
209+
kind: postgres-list-tablespaces
210+
source: postgresql-source
211+
208212
toolsets:
209213
postgres_database_tools:
210214
- execute_sql
@@ -230,3 +234,4 @@ toolsets:
230234
- list_query_stats
231235
- get_column_cardinality
232236
- list_publication_tables
237+
- list_tablespaces

0 commit comments

Comments
 (0)