Get All Tables Query
get-all-tablesRetrieve a list of all tables in the connected PostgreSQL database for schema exploration and analysis.
Instructions
Execute SQL queries to get all tables in the database
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-all-tables"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:134-162 (handler)Registers and implements the 'get-all-tables' tool. The handler function queries information_schema.tables for all tables in the 'public' schema using postgres unsafe() method, returning results as JSON.
// Tool to get all tables in the database server.registerTool( "get-all-tables", { title: "Get All Tables Query", description: "Execute SQL queries to get all tables in the database", }, async () => { const sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; try { const results = await initDb().unsafe(sql); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (err: unknown) { const error = err as Error; return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } } ); - src/server.ts:134-162 (registration)The tool is registered via server.registerTool('get-all-tables', ...) with title and description metadata. No inputSchema is defined (no parameters).
// Tool to get all tables in the database server.registerTool( "get-all-tables", { title: "Get All Tables Query", description: "Execute SQL queries to get all tables in the database", }, async () => { const sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; try { const results = await initDb().unsafe(sql); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (err: unknown) { const error = err as Error; return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } } ); - src/server.ts:49-54 (helper)Helper function initDb() that lazily initializes and returns a postgres database connection using getDb(). Used by the tool to execute the query.
const initDb = () => { if(!dbConnection) { dbConnection = getDb(); } return dbConnection; };