get-all-tables
Retrieve a complete list of all database tables to explore PostgreSQL schema structure and available data sources.
Instructions
Execute SQL queries to get all tables in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:141-161 (handler)The handler function for the 'get-all-tables' tool. It executes a fixed SQL query to retrieve all table names from the 'public' schema in the Postgres database using initDb().unsafe(sql), formats the results as JSON text content, and handles errors by returning an error message.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:135-162 (registration)Registration of the 'get-all-tables' tool using server.registerTool, including title, description, and the inline handler function.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:48-54 (helper)Helper function to lazily initialize and return the shared database connection (postgres.Sql), which is used by the get-all-tables handler.// Helper to initialize the database connection const initDb = () => { if(!dbConnection) { dbConnection = getDb(); } return dbConnection; };