mysql_show_indexes
Display indexes for a MySQL table to analyze database performance and optimize query execution by identifying existing index structures.
Instructions
Show indexes for a specific table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name to show indexes for | |
| 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"
},
"table": {
"description": "Table name to show indexes for",
"type": "string"
}
},
"required": [
"table"
],
"type": "object"
}
Implementation Reference
- src/index.ts:421-447 (handler)The main execution logic for the 'mysql_show_indexes' tool. It checks for an active connection, validates the table argument, constructs the fully qualified table name if a database is specified, executes 'SHOW INDEX FROM table', and formats the results as a text response with JSON-stringified index data.private async handleShowIndexes(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { table, database } = args; if (!table) { throw new Error("Table name is required"); } const fullTableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; try { const [results] = await this.pool.execute(`SHOW INDEX FROM ${fullTableName}`); return { content: [ { type: "text", text: `Indexes for table '${table}':\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to show indexes: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:199-212 (schema)The input schema defining the parameters for the tool: required 'table' string and optional 'database' string.inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to show indexes for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], },
- src/index.ts:196-213 (registration)The tool registration in the ListTools response, specifying name, description, and input schema.{ name: "mysql_show_indexes", description: "Show indexes for a specific table", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to show indexes for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, },
- src/index.ts:259-260 (registration)The dispatch case in the CallToolRequest handler that routes to the specific handler function.case "mysql_show_indexes": return await this.handleShowIndexes(args);