list_tables
Query and retrieve a list of tables along with their basic details from a PostgreSQL database schema, aiding in database exploration and structure analysis.
Instructions
List all tables in the database with basic information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: public) | public |
Implementation Reference
- src/index.js:176-207 (handler)The handler function that executes the list_tables tool. It connects to the PostgreSQL database, queries information_schema.tables for the specified schema, formats the table list, and returns it as MCP content.async listTables(schema = 'public') { const client = await this.connectToDatabase(); try { const query = ` SELECT table_name, table_type, is_insertable_into, is_typed FROM information_schema.tables WHERE table_schema = $1 ORDER BY table_name; `; const result = await client.query(query, [schema]); return { content: [ { type: 'text', text: `Tables in schema "${schema}":\n\n` + result.rows.map(row => `• ${row.table_name} (${row.table_type})` ).join('\n'), }, ], }; } finally { await client.end(); } }
- src/index.js:60-69 (schema)Input schema for the list_tables tool, defining an optional 'schema' parameter with default 'public'.inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, },
- src/index.js:58-70 (registration)Registration of the list_tables tool in the ListToolsRequestHandler response, including name, description, and input schema.name: 'list_tables', description: 'List all tables in the database with basic information', inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, }, },
- src/index.js:145-146 (registration)Dispatch/registration in the CallToolRequestHandler switch statement that routes 'list_tables' calls to the listTables method.case 'list_tables': return await this.listTables(args?.schema || 'public');