diff --git a/modules/postgres/module.json b/modules/postgres/module.json index 9a0a5cc..4ec69d9 100644 --- a/modules/postgres/module.json +++ b/modules/postgres/module.json @@ -133,5 +133,11 @@ "from": "Dockerfile" } ] - } + }, + "tools": [ + "databases", + "query", + "postgres_list_databases", + "postgres_query" + ] } diff --git a/modules/postgres/tools/index.ts b/modules/postgres/tools/index.ts index 51185be..d340f8b 100644 --- a/modules/postgres/tools/index.ts +++ b/modules/postgres/tools/index.ts @@ -8,6 +8,32 @@ import { PostgresClient } from "../client.js"; export function getPostgresTools(postgres: PostgresClient): ToolDefinition[] { return [ + // The store seat's verbs (novox/hq ADR 0159), served by this module wherever it holds the seat: + // named as the seat names them, so the runtime finds them by name, and answering with the same + // calls as this module's own tools below. A holder that is not the store serves nothing here; + // the bus admits the seat's subjects only to the holder. + { + name: "databases", + description: "The store seat's verb: every database the store holds, with its on-disk size.", + input: {}, + run: async () => ({ databases: await postgres.listDatabases() }), + }, + { + name: "query", + description: "The store seat's verb: one read-only statement against one database the store holds.", + input: { + database: { type: "string", description: "the database to query" }, + sql: { type: "string", description: "the SELECT (or other read-only) statement" }, + }, + run: async (args) => { + const database = String(args.database ?? ""); + const sql = String(args.sql ?? ""); + if (!database) throw new Error("query: database is required"); + if (!sql) throw new Error("query: sql is required"); + const result = await postgres.readOnlyQuery(database, sql); + return { database, command: result.command, rows: result.rows }; + }, + }, { name: "postgres_list_databases", description: "List the databases on the postgres server, with their on-disk size.",