Skip to content

Commit 9bd2c75

Browse files
srividyareddy786averikitschduwenxin99
authored andcommitted
feat(tools/postgres-list-publication-tables): add new postgres-list-publication-tables tool (#1919)
## Description Adds a postgresql custom list_publication_tables tool, that returns the details of publication tables present in database. Test Output: <img width="845" height="239" alt="Screenshot 2025-11-11 at 12 50 59 AM" src="https://github.com/user-attachments/assets/b7606e44-c5f6-4fc7-865e-7efadd112eff" /> <img width="1529" height="648" alt="Screenshot 2025-11-11 at 1 15 18 AM" src="https://github.com/user-attachments/assets/6192b772-f0bc-4fb4-8032-ca487434d77c" /> > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## 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 Co-authored-by: Averi Kitsch <[email protected]> Co-authored-by: Wenxin Du <[email protected]>
1 parent db3642c commit 9bd2c75

File tree

17 files changed

+567
-4
lines changed

17 files changed

+567
-4
lines changed

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ import (
187187
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistindexes"
188188
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistinstalledextensions"
189189
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistlocks"
190+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistpublicationtables"
190191
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistquerystats"
191192
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistschemas"
192193
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistsequences"

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"},
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"},
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"},
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"},
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"},
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"},
16221622
},
16231623
},
16241624
},

docs/en/reference/prebuilt-tools.md

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

5455
## AlloyDB Postgres Admin
5556

@@ -227,6 +228,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
227228
* `list_triggers`: Lists triggers in the database.
228229
* `list_indexes`: List available user indexes in a PostgreSQL database.
229230
* `list_sequences`: List sequences in a PostgreSQL database.
231+
* `list_publication_tables`: List publication tables in a PostgreSQL database.
230232

231233
## Cloud SQL for PostgreSQL Observability
232234

@@ -532,6 +534,7 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
532534
* `list_triggers`: Lists triggers in the database.
533535
* `list_indexes`: List available user indexes in a PostgreSQL database.
534536
* `list_sequences`: List sequences in a PostgreSQL database.
537+
* `list_publication_tables`: List publication tables in a PostgreSQL database.
535538

536539
## Google Cloud Serverless for Apache Spark
537540

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ cluster][alloydb-free-trial].
7777
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
7878
List cardinality of columns in a table in a PostgreSQL database.
7979

80+
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
81+
List publication tables in a PostgreSQL database.
82+
8083
### Pre-built Configurations
8184

8285
- [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
@@ -73,6 +73,9 @@ to a database by following these instructions][csql-pg-quickstart].
7373
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
7474
List cardinality of columns in a table in a PostgreSQL database.
7575

76+
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
77+
List publication tables in a PostgreSQL database.
78+
7679
### Pre-built Configurations
7780

7881
- [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
@@ -68,6 +68,9 @@ reputation for reliability, feature robustness, and performance.
6868
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
6969
List cardinality of columns in a table in a PostgreSQL database.
7070

71+
- [`postgres-list-publication-tables`](../tools/postgres/postgres-list-publication-tables.md)
72+
List publication tables in a PostgreSQL database.
73+
7174
### Pre-built Configurations
7275

7376
- [PostgreSQL using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/postgres_mcp/)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "postgres-list-publication-tables"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-list-publication-tables" tool lists publication tables in a Postgres database.
7+
aliases:
8+
- /resources/tools/postgres-list-publication-tables
9+
---
10+
11+
## About
12+
13+
The `postgres-list-publication-tables` tool lists all publication tables 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-publication-tables` lists detailed information as JSON for publication tables. A publication table in PostgreSQL is a
20+
table that is explicitly included as a source for replication within a publication (a set of changes generated from a table or group
21+
of tables) as part of the logical replication feature. The tool takes the following input parameters:
22+
23+
- `table_names` (optional): Filters by a comma-separated list of table names. Default: `""`
24+
- `publication_names` (optional): Filters by a comma-separated list of publication names. Default: `""`
25+
- `schema_names` (optional): Filters by a comma-separated list of schema names. Default: `""`
26+
- `limit` (optional): The maximum number of rows to return. Default: `50`
27+
28+
## Example
29+
30+
```yaml
31+
tools:
32+
list_indexes:
33+
kind: postgres-list-publication-tables
34+
source: postgres-source
35+
description: |
36+
Lists all tables that are explicitly part of a publication in the database.
37+
Tables that are part of a publication via 'FOR ALL TABLES' are not included,
38+
unless they are also explicitly added to the publication.
39+
Returns the publication name, schema name, and table name, along with
40+
definition details indicating if it publishes all tables, whether it
41+
replicates inserts, updates, deletes, or truncates, and the publication
42+
owner.
43+
```
44+
45+
The response is a JSON array with the following elements:
46+
```json
47+
{
48+
"publication_name": "Name of the publication",
49+
"schema_name": "Name of the schema the table belongs to",
50+
"table_name": "Name of the table",
51+
"publishes_all_tables": "boolean indicating if the publication was created with FOR ALL TABLES",
52+
"publishes_inserts": "boolean indicating if INSERT operations are replicated",
53+
"publishes_updates": "boolean indicating if UPDATE operations are replicated",
54+
"publishes_deletes": "boolean indicating if DELETE operations are replicated",
55+
"publishes_truncates": "boolean indicating if TRUNCATE operations are replicated",
56+
"publication_owner": "Username of the database role that owns the publication"
57+
}
58+
```
59+
60+
## Reference
61+
62+
| **field** | **type** | **required** | **description** |
63+
|-------------|:--------:|:------------:|------------------------------------------------------|
64+
| kind | string | true | Must be "postgres-list-publication-tables". |
65+
| source | string | true | Name of the source the SQL should execute on. |
66+
| description | string | false | Description of the tool that is passed to the agent. |

internal/prebuiltconfigs/tools/alloydb-postgres.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ tools:
200200
kind: postgres-get-column-cardinality
201201
source: alloydb-pg-source
202202

203+
list_publication_tables:
204+
kind: postgres-list-publication-tables
205+
source: alloydb-pg-source
206+
203207
toolsets:
204208
alloydb_postgres_database_tools:
205209
- execute_sql
@@ -224,3 +228,4 @@ toolsets:
224228
- replication_stats
225229
- list_query_stats
226230
- get_column_cardinality
231+
- list_publication_tables

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ tools:
202202
kind: postgres-get-column-cardinality
203203
source: cloudsql-pg-source
204204

205+
list_publication_tables:
206+
kind: postgres-list-publication-tables
207+
source: cloudsql-pg-source
208+
205209
toolsets:
206210
cloud_sql_postgres_database_tools:
207211
- execute_sql
@@ -226,3 +230,4 @@ toolsets:
226230
- replication_stats
227231
- list_query_stats
228232
- get_column_cardinality
233+
- list_publication_tables

internal/prebuiltconfigs/tools/postgres.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ tools:
201201
kind: postgres-get-column-cardinality
202202
source: postgresql-source
203203

204+
list_publication_tables:
205+
kind: postgres-list-publication-tables
206+
source: postgresql-source
207+
204208
toolsets:
205209
postgres_database_tools:
206210
- execute_sql
@@ -225,4 +229,4 @@ toolsets:
225229
- replication_stats
226230
- list_query_stats
227231
- get_column_cardinality
228-
232+
- list_publication_tables

0 commit comments

Comments
 (0)