mysql_list_tables
Retrieve a list of all database tables to understand database structure and available data for querying in MySQL databases.
Instructions
List all tables in the database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, defaults to configured database) |
Input Schema (JSON Schema)
{
"properties": {
"database": {
"description": "Database name (optional, defaults to configured database)",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/mysql-connection.ts:83-97 (handler)Core handler function that executes the 'SHOW TABLES' query to list tables in the specified or default database, extracts table names from the result.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)Tool dispatch handler case that extracts arguments, calls the MySQL connection's listTables method, and formats the 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 (registration)Registers the mysql_list_tables tool in the ListTools response, including its description and input schema.{ 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)', }, }, }, },
- src/index.ts:46-58 (schema)Defines the input schema for the mysql_list_tables tool.{ 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)', }, }, }, },