mysql_list_tables
Retrieve a list of all tables in a MySQL database to inspect schema structure and available data sources.
Instructions
List all tables in the current or specified database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (uses current database if not specified) |
Input Schema (JSON Schema)
{
"properties": {
"database": {
"description": "Database name (uses current database if not specified)",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:366-391 (handler)The handleListTables method implements the core logic for the mysql_list_tables tool. It checks for an active connection, constructs a SHOW TABLES query (optionally specifying a database), executes it via the MySQL pool, and returns the results as a formatted text response.private async handleListTables(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { database } = args; let query = "SHOW TABLES"; if (database) { query = `SHOW TABLES FROM \`${database}\``; } try { const [results] = await this.pool.execute(query); return { content: [ { type: "text", text: `Tables${database ? ` in database '${database}'` : ""}:\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to list tables: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:165-177 (registration)Registers the mysql_list_tables tool in the ListTools response, providing the tool name, description, and inputSchema for database parameter.{ name: "mysql_list_tables", description: "List all tables in the current or specified database", inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (uses current database if not specified)", }, }, }, },
- src/index.ts:255-256 (handler)Dispatches calls to the mysql_list_tables tool by invoking handleListTables in the central CallToolRequest switch statement.case "mysql_list_tables": return await this.handleListTables(args);