list_tables
Retrieve all table names from your connected database to inspect schema structure and identify available data sources.
Instructions
List all tables in the connected database
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_tables"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:391-449 (handler)The primary handler function for the 'list_tables' tool. It checks for an active database connection and executes database-specific queries to retrieve and return a list of tables in JSON format for both PostgreSQL and MySQL.
async listTables() { if (!this.currentConfig) { throw new Error('Not connected to any database. Call connect_database first.'); } if (this.currentConfig.type === 'postgresql') { if (!this.postgresPool) { throw new Error('PostgreSQL connection not initialized'); } const query = ` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name; `; const result = await this.postgresPool.query(query); return { content: [ { type: 'text', text: JSON.stringify( { tables: result.rows.map((row) => row.table_name), }, null, 2 ), }, ], }; } else if (this.currentConfig.type === 'mysql') { if (!this.mysqlConnection) { throw new Error('MySQL connection not initialized'); } const [rows] = await this.mysqlConnection.query( `SHOW TABLES FROM ${this.currentConfig.database}` ); const tableKey = `Tables_in_${this.currentConfig.database}`; const tables = rows.map((row) => row[tableKey]); return { content: [ { type: 'text', text: JSON.stringify( { tables: tables, }, null, 2 ), }, ], }; } else { throw new Error(`Unsupported database type: ${this.currentConfig.type}`); } } - index.js:175-182 (registration)Tool registration in the ListToolsRequestSchema handler, defining the name, description, and empty input schema for the 'list_tables' tool.
{ name: 'list_tables', description: 'List all tables in the connected database', inputSchema: { type: 'object', properties: {}, }, }, - index.js:178-181 (schema)Input schema definition for the 'list_tables' tool, which requires no parameters.
inputSchema: { type: 'object', properties: {}, }, - index.js:219-220 (handler)Dispatch case in the CallToolRequestSchema handler that invokes the listTables method for the 'list_tables' tool.
case 'list_tables': return await this.listTables();