Skip to main content
Glama
sajithrw

MCP MySQL Server

by sajithrw

mysql_show_indexes

Display index information for a MySQL table to analyze query performance and optimize database structure.

Instructions

Show indexes for a specific table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name to show indexes for
databaseNoDatabase name (uses current database if not specified)

Implementation Reference

  • The handler function that executes the SHOW INDEX query to retrieve indexes for the specified table on the connected MySQL database.
    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)}`);
      }
    }
  • Input schema definition specifying the parameters for the mysql_show_indexes tool: required 'table' and optional 'database'.
    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:196-213 (registration)
    Tool registration entry in the ListTools response, including 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)
    Switch case in CallToolRequest handler that dispatches to the mysql_show_indexes handler function.
    case "mysql_show_indexes":
      return await this.handleShowIndexes(args);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sajithrw/mcp-mysql'

If you have feedback or need assistance with the MCP directory API, please join our Discord server