list_indices
Retrieve all Elasticsearch indices or filter them using regex patterns to manage and explore your data structure efficiently.
Instructions
List all available Elasticsearch indices, support regex
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | No | Optional regex pattern to filter indices by name |
Implementation Reference
- src/tools/listIndices.ts:9-50 (handler)Main handler function that lists Elasticsearch indices matching the optional pattern, returns formatted list with health, status, and document count, handles errors.export async function listIndices(esClient: Client, pattern?: string) { try { const response = await esClient.cat.indices({ format: "json", index: pattern || "*" // if pattern is undefined, use "*" as default }); 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) }`, }, ], }; } }
- src/server.ts:42-53 (registration)Registers the 'list_indices' tool on the MCP server, defines input schema, description, and thin wrapper handler that delegates to the main listIndices function."list_indices", "List all available Elasticsearch indices, support regex", { pattern: z .string() .optional() .describe("Optional regex pattern to filter indices by name"), }, async ({ pattern }) => { return await listIndices(esClient, pattern); } );
- src/server.ts:46-49 (schema)Zod schema definition for the optional 'pattern' input parameter used in tool registration..string() .optional() .describe("Optional regex pattern to filter indices by name"), },