list_tables
Retrieve all tables from a specified database connection using DBeaver, with options to filter by schema and include views.
Instructions
List all tables in a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | The ID or name of the DBeaver connection | |
| includeViews | No | Include views in the results | |
| schema | No | Specific schema to list tables from (optional) |
Implementation Reference
- src/index.ts:936-960 (handler)MCP tool handler for list_tables: validates connectionId, fetches connection, delegates to DBeaverClient.listTables, formats response as JSON.private async handleListTables(args: { connectionId: string; schema?: string; includeViews?: boolean }) { const connectionId = sanitizeConnectionId(args.connectionId); const connection = await this.configParser.getConnection(connectionId); if (!connection) { throw new McpError(ErrorCode.InvalidParams, `Connection not found: ${connectionId}`); } const tables = await this.dbeaverClient.listTables( connection, args.schema, args.includeViews || false ); return { content: [{ type: 'text' as const, text: JSON.stringify(tables, null, 2), }], }; }
- src/index.ts:406-427 (schema)Input schema definition and tool metadata registration for the list_tables tool in ListToolsRequestSchema response.name: 'list_tables', description: 'List all tables in a database', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'The ID or name of the DBeaver connection', }, schema: { type: 'string', description: 'Specific schema to list tables from (optional)', }, includeViews: { type: 'boolean', description: 'Include views in the results', default: false } }, required: ['connectionId'], }, },
- src/dbeaver-client.ts:418-438 (handler)Core listTables method in DBeaverClient: builds driver-specific query, executes it, parses results into table objects. Called by MCP handler.async listTables(connection: DBeaverConnection, schema?: string, includeViews: boolean = false): Promise<any[]> { try { const query = buildListTablesQuery(connection.driver, schema, includeViews); const result = await this.executeQuery(connection, query); // Convert result to table objects return result.rows.map(row => { const tableObj: any = {}; result.columns.forEach((col, idx) => { tableObj[col] = row[idx]; }); return tableObj; }); } catch (error) { if (this.debug) { console.error(`Failed to list tables: ${error}`); } // Return empty array instead of crashing return []; } }
- src/utils.ts:253-362 (helper)Helper function to generate database-driver-specific SQL queries for listing tables and views, used by DBeaverClient.listTables.export function buildListTablesQuery(driver: string, schema?: string, includeViews: boolean = false): string { const driverLower = driver.toLowerCase(); if (driverLower.includes('postgresql') || driverLower.includes('postgres')) { let query = ` SELECT table_name, table_type, table_schema FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') `; if (schema) { query += ` AND table_schema = '${schema}'`; } if (!includeViews) { query += ` AND table_type = 'BASE TABLE'`; } query += ` ORDER BY table_schema, table_name;`; return query; } else if (driverLower.includes('mysql')) { let query = ` SELECT TABLE_NAME as table_name, TABLE_TYPE as table_type, TABLE_SCHEMA as table_schema FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') `; if (schema) { query += ` AND TABLE_SCHEMA = '${schema}'`; } if (!includeViews) { query += ` AND TABLE_TYPE = 'BASE TABLE'`; } query += ` ORDER BY TABLE_SCHEMA, TABLE_NAME;`; return query; } else if (driverLower.includes('sqlite')) { let query = ` SELECT name as table_name, type as table_type FROM sqlite_master WHERE type IN ('table'${includeViews ? ", 'view'" : ''}) AND name NOT LIKE 'sqlite_%' ORDER BY name; `; return query; } else if (driverLower.includes('oracle')) { let query = ` SELECT table_name, 'TABLE' as table_type, owner as table_schema FROM all_tables `; if (schema) { query += ` WHERE owner = UPPER('${schema}')`; } if (includeViews) { query += ` UNION ALL SELECT view_name as table_name, 'VIEW' as table_type, owner as table_schema FROM all_views `; if (schema) { query += ` WHERE owner = UPPER('${schema}')`; } } query += ` ORDER BY table_name;`; return query; } else { // Generic fallback let query = ` SELECT table_name, table_type, table_schema FROM information_schema.tables `; if (schema) { query += ` WHERE table_schema = '${schema}'`; } if (!includeViews) { query += `${schema ? ' AND' : ' WHERE'} table_type = 'BASE TABLE'`; } query += ` ORDER BY table_schema, table_name;`; return query; } }