list_indices
Retrieve all Elasticsearch indices or filter them using a regex pattern with the list_indices tool. Easily manage and access your data by discovering relevant indices for querying or analysis within the Elasticsearch MCP Server.
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)Core handler function that executes the list_indices tool logic: fetches indices from Elasticsearch using cat.indices API, optionally filters by pattern, formats output with health/status/docs count, and 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:41-53 (registration)MCP server registration of the 'list_indices' tool, including name, description, input schema (pattern: optional string), and wrapper handler calling the core listIndices function.server.tool( "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:45-48 (schema)Zod input schema for the list_indices tool: optional 'pattern' string parameter for filtering indices.pattern: z .string() .optional() .describe("Optional regex pattern to filter indices by name"),