list_indices
Retrieve all available Elasticsearch indices by specifying an index pattern using the MCP server. Simplify database queries and manage indices effectively.
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:129-173 (handler)Handler function for the 'list_indices' tool. It queries Elasticsearch for indices matching the given pattern using cat.indices API, formats the response with health, status, and document count, and returns the results as text content. Includes error handling.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) }`, }, ], }; } }
- index.ts:123-128 (schema)Input schema for the 'list_indices' tool. Defines 'indexPattern' as a required trimmed string with a description.indexPattern: z .string() .trim() .min(1, "Index pattern is required") .describe("Index pattern of Elasticsearch indices to list"), },
- index.ts:119-174 (registration)Registration of the 'list_indices' tool using server.tool(). Includes name, description, input schema, and handler function.server.tool( "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) }`, }, ], }; } } );