list_tables
Retrieve a list of database tables to inspect schema structure and identify available data sources for PostgreSQL operations.
Instructions
List tables in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: public) |
Implementation Reference
- src/index.ts:418-445 (handler)The handler function for list_tables tool. Ensures database connection, queries information_schema.tables for tables in the given schema (default 'public'), returns table names as JSON, handles errors.private async handleListTables(args: any = {}) { await this.ensureConnection(); const schema = args.schema || 'public'; try { const result = await this.client!.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = $1 ORDER BY table_name `, [schema]); return { content: [ { type: 'text', text: JSON.stringify(result.rows, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to list tables: ${getErrorMessage(error)}` ); } }
- src/index.ts:223-232 (schema)Input schema for list_tables tool, defining an optional 'schema' string parameter.inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', }, }, required: [], },
- src/index.ts:220-233 (registration)Registration of the list_tables tool in the ListToolsRequestSchema response, including name, description, and input schema.{ name: 'list_tables', description: 'List tables in the database', inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', }, }, required: [], }, },
- src/index.ts:265-266 (registration)Routing logic in the CallToolRequestSchema handler that dispatches list_tables calls to the handleListTables method.case 'list_tables': return await this.handleListTables(request.params.arguments);