Skip to content

Commit 43fe0e6

Browse files
srividyareddy786rahulpinto19
authored andcommitted
feat(tools/postgres): add list_triggers, database_overview tools for postgres (#1912)
## Description Adds the following tools for Postgres: (1) list_triggers: Lists triggers in the database. . (2) database_overview: Fetches the current state of the PostgreSQL server. list_triggers: <img width="1712" height="703" alt="Screenshot 2025-11-09 at 8 16 53 PM" src="https://github.com/user-attachments/assets/1974e303-b559-4efc-b129-444ba97c7715" /> <img width="874" height="513" alt="Screenshot 2025-11-09 at 8 19 43 PM" src="https://github.com/user-attachments/assets/59ddcd15-224b-4e9a-906d-ec2645835873" /> database_overview: <img width="1521" height="683" alt="Screenshot 2025-11-09 at 8 53 03 PM" src="https://github.com/user-attachments/assets/4ae86e74-aa78-410c-a9cc-f33ae3268fb6" /> <img width="850" height="241" alt="Screenshot 2025-11-09 at 8 49 53 PM" src="https://github.com/user-attachments/assets/abae2c7a-5f3e-4433-86de-3606e3298ec5" /> > 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
1 parent c8ea70b commit 43fe0e6

File tree

20 files changed

+1019
-3
lines changed

20 files changed

+1019
-3
lines changed

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ import (
176176
_ "github.com/googleapis/genai-toolbox/internal/tools/oceanbase/oceanbasesql"
177177
_ "github.com/googleapis/genai-toolbox/internal/tools/oracle/oracleexecutesql"
178178
_ "github.com/googleapis/genai-toolbox/internal/tools/oracle/oraclesql"
179+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgresdatabaseoverview"
179180
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgresexecutesql"
180181
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistactivequeries"
181182
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistavailableextensions"
182183
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistinstalledextensions"
183184
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistschemas"
184185
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttables"
186+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttriggers"
185187
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistviews"
186188
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgressql"
187189
_ "github.com/googleapis/genai-toolbox/internal/tools/redis"

cmd/root_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ func TestPrebuiltTools(t *testing.T) {
14771477
wantToolset: server.ToolsetConfigs{
14781478
"alloydb_postgres_database_tools": tools.ToolsetConfig{
14791479
Name: "alloydb_postgres_database_tools",
1480-
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"},
1480+
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"},
14811481
},
14821482
},
14831483
},
@@ -1507,7 +1507,7 @@ func TestPrebuiltTools(t *testing.T) {
15071507
wantToolset: server.ToolsetConfigs{
15081508
"cloud_sql_postgres_database_tools": tools.ToolsetConfig{
15091509
Name: "cloud_sql_postgres_database_tools",
1510-
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"},
1510+
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"},
15111511
},
15121512
},
15131513
},
@@ -1607,7 +1607,7 @@ func TestPrebuiltTools(t *testing.T) {
16071607
wantToolset: server.ToolsetConfigs{
16081608
"postgres_database_tools": tools.ToolsetConfig{
16091609
Name: "postgres_database_tools",
1610-
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"},
1610+
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"},
16111611
},
16121612
},
16131613
},

docs/en/reference/prebuilt-tools.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
4646
* `list_views`: Lists views in the database from pg_views with a default
4747
limit of 50 rows. Returns schemaname, viewname and the ownername.
4848
* `list_schemas`: Lists schemas in the database.
49+
* `database_overview`: Fetches the current state of the PostgreSQL server.
50+
* `list_triggers`: Lists triggers in the database.
4951

5052
## AlloyDB Postgres Admin
5153

@@ -216,6 +218,8 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
216218
* `list_views`: Lists views in the database from pg_views with a default
217219
limit of 50 rows. Returns schemaname, viewname and the ownername.
218220
* `list_schemas`: Lists schemas in the database.
221+
* `database_overview`: Fetches the current state of the PostgreSQL server.
222+
* `list_triggers`: Lists triggers in the database.
219223

220224
## Cloud SQL for PostgreSQL Observability
221225

@@ -513,6 +517,8 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
513517
* `list_views`: Lists views in the database from pg_views with a default
514518
limit of 50 rows. Returns schemaname, viewname and the ownername.
515519
* `list_schemas`: Lists schemas in the database.
520+
* `database_overview`: Fetches the current state of the PostgreSQL server.
521+
* `list_triggers`: Lists triggers in the database.
516522

517523
## Google Cloud Serverless for Apache Spark
518524

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ cluster][alloydb-free-trial].
5151
- [`postgres-list-schemas`](../tools/postgres/postgres-list-schemas.md)
5252
List schemas in an AlloyDB for PostgreSQL database.
5353

54+
- [`postgres-database-overview`](../tools/postgres/postgres-database-overview.md)
55+
Fetches the current state of the PostgreSQL server.
56+
57+
- [`postgres-list-triggers`](../tools/postgres/postgres-list-triggers.md)
58+
List triggers in an AlloyDB for PostgreSQL database.
59+
5460
### Pre-built Configurations
5561

5662
- [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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ to a database by following these instructions][csql-pg-quickstart].
4747
- [`postgres-list-schemas`](../tools/postgres/postgres-list-schemas.md)
4848
List schemas in a PostgreSQL database.
4949

50+
- [`postgres-database-overview`](../tools/postgres/postgres-database-overview.md)
51+
Fetches the current state of the PostgreSQL server.
52+
53+
- [`postgres-list-triggers`](../tools/postgres/postgres-list-triggers.md)
54+
List triggers in a PostgreSQL database.
55+
5056
### Pre-built Configurations
5157

5258
- [Cloud SQL for Postgres using

docs/en/resources/sources/postgres.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ reputation for reliability, feature robustness, and performance.
4141
- [`postgres-list-schemas`](../tools/postgres/postgres-list-views.md)
4242
List schemas in a PostgreSQL database.
4343

44+
- [`postgres-database-overview`](../tools/postgres/postgres-database-overview.md)
45+
Fetches the current state of the PostgreSQL server.
46+
47+
- [`postgres-list-triggers`](../tools/postgres/postgres-list-triggers.md)
48+
List triggers in a PostgreSQL database.
49+
4450
### Pre-built Configurations
4551

4652
- [PostgreSQL using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/postgres_mcp/)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "postgres-database-overview"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-database-overview" fetches the current state of the PostgreSQL server.
7+
aliases:
8+
- /resources/tools/postgres-database-overview
9+
---
10+
11+
## About
12+
13+
The `postgres-database-overview` fetches the current state of the PostgreSQL server. 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-database-overview` fetches the current state of the PostgreSQL server This tool does not take any input parameters.
20+
21+
## Example
22+
23+
```yaml
24+
tools:
25+
database_overview:
26+
kind: postgres-database-overview
27+
source: cloudsql-pg-source
28+
description: |
29+
fetches the current state of the PostgreSQL server. It returns the postgres version, whether it's a replica, uptime duration, maximum connection limit, number of current connections, number of active connections and the percentage of connections in use.
30+
```
31+
32+
The response is a JSON object with the following elements:
33+
```json
34+
{
35+
"pg_version": "PostgreSQL server version string",
36+
"is_replica": "boolean indicating if the instance is in recovery mode",
37+
"uptime": "interval string representing the total server uptime",
38+
"max_connections": "integer maximum number of allowed connections",
39+
"current_connections": "integer number of current connections",
40+
"active_connections": "integer number of currently active connections",
41+
"pct_connections_used": "float percentage of max_connections currently in use"
42+
}
43+
```
44+
45+
## Reference
46+
47+
| **field** | **type** | **required** | **description** |
48+
|-------------|:--------:|:-------------:|------------------------------------------------------|
49+
| kind | string | true | Must be "postgres-database-overview". |
50+
| source | string | true | Name of the source the SQL should execute on. |
51+
| description | string | false | Description of the tool that is passed to the agent. |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: "postgres-list-triggers"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-list-triggers" tool lists triggers in a Postgres database.
7+
aliases:
8+
- /resources/tools/postgres-list-triggers
9+
---
10+
11+
## About
12+
13+
The `postgres-list-triggers` tool lists available non-internal triggers 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-triggers` lists detailed information as JSON for triggers. The tool takes the following input parameters:
20+
21+
- `trigger_name` (optional): A text to filter results by trigger name. The input is used within a LIKE clause. Default: `""`
22+
- `schema_name` (optional): A text to filter results by schema name. The input is used within a LIKE clause. Default: `""`
23+
- `table_name` (optional): A text to filter results by table name. The input is used within a LIKE clause. Default: `""`
24+
- `limit` (optional): The maximum number of triggers to return. Default: `50`
25+
26+
27+
## Example
28+
29+
```yaml
30+
```yaml
31+
tools:
32+
list_triggers:
33+
kind: postgres-list-triggers
34+
source: postgres-source
35+
description: |
36+
Lists all non-internal triggers in a database. Returns trigger name, schema name, table name, wether its enabled or disabled, timing (e.g BEFORE/AFTER of the event), the events that cause the trigger to fire such as INSERT, UPDATE, or DELETE, whether the trigger activates per ROW or per STATEMENT, the handler function executed by the trigger and full definition.
37+
```
38+
39+
The response is a json array with the following elements:
40+
```json
41+
{
42+
"trigger_name": "trigger name",
43+
"schema_name": "schema name",
44+
"table_name": "table name",
45+
"status": "Whether the trigger is currently active (ENABLED, DISABLED, REPLICA, ALWAYS).",
46+
"timing": "When it runs relative to the event (BEFORE, AFTER, INSTEAD OF).",
47+
"events": "The specific operations that fire it (INSERT, UPDATE, DELETE, TRUNCATE)",
48+
"activation_level": "Granularity of execution (ROW vs STATEMENT).",
49+
"function_name": "The function it executes",
50+
"definition": "Full SQL definition of the trigger"
51+
}
52+
```
53+
54+
## Reference
55+
56+
| **field** | **type** | **required** | **description** |
57+
|-------------|:--------:|:-------------:|------------------------------------------------------|
58+
| kind | string | true | Must be "postgres-list-triggers". |
59+
| source | string | true | Name of the source the SQL should execute on. |
60+
| description | string | false | Description of the tool that is passed to the agent. |

internal/prebuiltconfigs/tools/alloydb-postgres.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ tools:
164164
kind: postgres-list-schemas
165165
source: alloydb-pg-source
166166

167+
database_overview:
168+
kind: postgres-database-overview
169+
source: alloydb-pg-source
170+
171+
list_triggers:
172+
kind: postgres-list-triggers
173+
source: alloydb-pg-source
174+
167175
toolsets:
168176
alloydb_postgres_database_tools:
169177
- execute_sql
@@ -179,3 +187,5 @@ toolsets:
179187
- get_query_plan
180188
- list_views
181189
- list_schemas
190+
- database_overview
191+
- list_triggers

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ tools:
163163
kind: postgres-list-schemas
164164
source: cloudsql-pg-source
165165

166+
database_overview:
167+
kind: postgres-database-overview
168+
source: cloudsql-pg-source
169+
170+
list_triggers:
171+
kind: postgres-list-triggers
172+
source: cloudsql-pg-source
173+
166174
toolsets:
167175
cloud_sql_postgres_database_tools:
168176
- execute_sql
@@ -178,3 +186,5 @@ toolsets:
178186
- get_query_plan
179187
- list_views
180188
- list_schemas
189+
- database_overview
190+
- list_triggers

0 commit comments

Comments
 (0)