list_indices
Lists Elasticsearch indices matching a specific pattern to help users discover and access available data collections for querying and analysis.
Instructions
List all available Elasticsearch indices
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexPattern | Yes | Index pattern of Elasticsearch indices to list |
Implementation Reference
- index.ts:130-173 (handler)The async handler function that executes the list_indices tool logic: fetches indices using esClient.cat.indices with the given indexPattern, maps to a simplified info object, and returns formatted text content. Handles errors gracefully.console.error("[DEBUG] list_indices tool called", indexPattern); try { const response = await esClient.cat.indices({ index: indexPattern, format: "json" }); const indicesInfo = response.map((index) => ({ index: index.index, health: index.health, status: index.status, docsCount: index.docsCount, })); return { content: [ { type: "text" as const, text: `Found ${indicesInfo.length} indices`, }, { type: "text" as const, text: JSON.stringify(indicesInfo, null, 2), }, ], }; } catch (error) { console.error( `Failed to list indices: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- index.ts:124-128 (schema)Zod input schema defining the 'indexPattern' parameter as a required trimmed string..string() .trim() .min(1, "Index pattern is required") .describe("Index pattern of Elasticsearch indices to list"), },
- index.ts:120-174 (registration)Registration of the 'list_indices' tool on the MCP server, including name, description, input schema, and handler function."list_indices", "List all available Elasticsearch indices", { indexPattern: z .string() .trim() .min(1, "Index pattern is required") .describe("Index pattern of Elasticsearch indices to list"), }, async ({ indexPattern }) => { console.error("[DEBUG] list_indices tool called", indexPattern); try { const response = await esClient.cat.indices({ index: indexPattern, format: "json" }); const indicesInfo = response.map((index) => ({ index: index.index, health: index.health, status: index.status, docsCount: index.docsCount, })); return { content: [ { type: "text" as const, text: `Found ${indicesInfo.length} indices`, }, { type: "text" as const, text: JSON.stringify(indicesInfo, null, 2), }, ], }; } catch (error) { console.error( `Failed to list indices: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );