list_indexes
List all indexes on a table, returning one row per index and column combination.
Instructions
List indexes on a table, one row per (index, column).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | Yes | ||
| table | Yes |
Implementation Reference
- src/db.ts:146-172 (handler)The actual implementation of listIndexes. Runs a SQL query against sys.indexes, sys.index_columns, sys.columns, sys.tables, and sys.schemas to return index_name, type_desc, is_unique, is_primary_key, column_name, key_ordinal, and is_included_column for each (index, column) pair on the given table.
async listIndexes(schema: string, table: string) { const r = await (await this.getPool()) .request() .input('schema', sql.NVarChar, schema) .input('table', sql.NVarChar, table).query(` SELECT i.name AS index_name, i.type_desc, i.is_unique, i.is_primary_key, c.name AS column_name, ic.key_ordinal, ic.is_included_column FROM sys.indexes i INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id INNER JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id INNER JOIN sys.tables t ON i.object_id = t.object_id INNER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = @schema AND t.name = @table AND i.type > 0 ORDER BY i.is_primary_key DESC, i.name, ic.key_ordinal `); return r.recordset; } - src/index.ts:93-96 (schema)Zod schema for the 'list_indexes' tool input: two required string fields (schema, table).
{ schema: z.string(), table: z.string(), }, - src/index.ts:90-98 (registration)Registration of the 'list_indexes' tool on the MCP server with its description, schema, and handler.
server.tool( 'list_indexes', 'List indexes on a table, one row per (index, column).', { schema: z.string(), table: z.string(), }, async ({ schema, table }) => runTool(() => db.listIndexes(schema, table)) );