get_table_indexes
Retrieve index metadata for a specific database table by providing its name. Returns details on existing indexes to aid in database analysis and optimization.
Instructions
Get index information for a specific table.
Args: table_name (str): Table name to inspect
Returns: str: Index metadata for the table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- tools/sql_tools.py:120-142 (handler)The main handler function for the 'get_table_indexes' tool. It takes a table_name, connects to the MySQL database via the get_connection() context manager, executes 'SHOW INDEX FROM `{table_name}`', and returns formatted index metadata (Key_name, Column_name, Seq_in_index, Unique, Index_type).
def get_table_indexes(self, table_name: str) -> str: """Get index information for a specific table. Args: table_name (str): Table name to inspect Returns: str: Index metadata for the table """ with self.get_connection() as conn: cursor = conn.cursor(dictionary=True, buffered=True) cursor.execute(f"SHOW INDEX FROM `{table_name}`") indexes = cursor.fetchall() if not indexes: return f"No indexes found for table '{table_name}'" output = [f"Indexes for table '{table_name}':"] for index in indexes: output.append( f"Key: {index['Key_name']}, Column: {index['Column_name']}, Seq: {index['Seq_in_index']}, Unique: {not bool(index['Non_unique'])}, Type: {index['Index_type']}" ) return "\n".join(output) - server.py:17-17 (registration)The tool is registered via mcp.tool()(sql_tools.get_table_indexes) on line 17 of server.py.
mcp.tool()(sql_tools.get_table_indexes)