list_tables
Retrieve all tables in a PostgreSQL database with basic information like schema details. Use this tool to explore database structure and understand table relationships.
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 core handler function for the 'list_tables' tool. It connects to the PostgreSQL database, executes a query against information_schema.tables to list tables in the specified schema, formats the results as a text list, and returns the MCP-formatted response.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 definition 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:57-70 (registration)Registration of the 'list_tables' tool in the ListToolsRequestSchema handler, 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 (handler)Dispatch handler in the CallToolRequestSchema switch statement that routes 'list_tables' calls to the listTables method, passing the schema argument.case 'list_tables': return await this.listTables(args?.schema || 'public');