get-all-tables
Retrieve a complete list of all tables in your PostgreSQL database. This tool executes SQL queries to display every table, enabling database exploration and schema analysis.
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)Handler function that executes a fixed SQL query to retrieve all table names from the public schema in the Postgres database, formats the results as JSON, and handles errors.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:137-140 (schema)Metadata schema for the tool including title and description. No input schema as the tool takes no parameters.{ title: "Get All Tables Query", description: "Execute SQL queries to get all tables in the database", },
- src/server.ts:135-162 (registration)Registers the 'get-all-tables' tool with the MCP server, providing name, schema/metadata, and 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:49-54 (helper)Helper function to initialize and lazily create the Postgres database connection, called within the tool handler.const initDb = () => { if(!dbConnection) { dbConnection = getDb(); } return dbConnection; };