mysql_list_tables
Retrieve a list of all tables in a MySQL database to explore its structure and available data.
Instructions
List all tables in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, defaults to configured database) |
Implementation Reference
- src/mysql-connection.ts:83-97 (handler)Core handler logic for the mysql_list_tables tool: executes SHOW TABLES query and extracts table names.async listTables(database?: string): Promise<string[]> { const dbName = database || this.config.database; if (!dbName) { throw new Error('No database specified'); } const query = `SHOW TABLES FROM \`${dbName}\``; const result = await this.executeQuery(query); // Extract table names from result return result.rows.map((row: any) => { const key = Object.keys(row)[0]; // Get the first column name return row[key]; }); }
- src/index.ts:129-140 (handler)MCP tool dispatcher case for mysql_list_tables: parses args, calls listTables, and returns JSON response.case 'mysql_list_tables': { const { database } = args as { database?: string }; const result = await mysqlConnection.listTables(database); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:46-58 (schema)Tool schema and registration: defines name, description, and input schema for mysql_list_tables.{ name: 'mysql_list_tables', description: 'List all tables in the database', inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional, defaults to configured database)', }, }, }, },