list_tables
Retrieve all tables within a specified schema on a PostgreSQL database using the Model Context Protocol (MCP) for secure and efficient database exploration.
Instructions
List all tables in a schema
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No |
Implementation Reference
- index.ts:218-248 (handler)The handler function that lists all tables in the public schema by querying information_schema.tables and returns a JSON array of table names.async () => { try { debugLog("Listing database tables"); return await executeDbQuery(async (client) => { const result = await withTimeout( client.query( "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" ), API_TIMEOUT_MS, "Listing database tables" ) as pg.QueryResult; debugLog(`Found ${result.rows.length} tables`); const tableList = result.rows.map((row: { table_name: string }) => row.table_name); return { content: [ { type: "text", text: JSON.stringify(tableList, null, 2), }, ], }; }, "Failed to list database tables"); } catch (error) { handleError(error, "Failed to list database tables"); throw error; } }
- index.ts:215-249 (registration)Registration of the postgres_list_tables tool on the MCP server, including empty input schema and inline handler.server.tool( "postgres_list_tables", {}, async () => { try { debugLog("Listing database tables"); return await executeDbQuery(async (client) => { const result = await withTimeout( client.query( "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" ), API_TIMEOUT_MS, "Listing database tables" ) as pg.QueryResult; debugLog(`Found ${result.rows.length} tables`); const tableList = result.rows.map((row: { table_name: string }) => row.table_name); return { content: [ { type: "text", text: JSON.stringify(tableList, null, 2), }, ], }; }, "Failed to list database tables"); } catch (error) { handleError(error, "Failed to list database tables"); throw error; } } );
- index.ts:140-142 (schema)Input/output schema declaration for the tool in the MCP server capabilities. No parameters required.postgres_list_tables: { description: "List all tables in the PostgreSQL database", parameters: {},