Skip to main content
Glama
awesimon

Elasticsearch MCP Server

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
NameRequiredDescriptionDefault
patternNoOptional regex pattern to filter indices by name

Implementation Reference

  • 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); } );
  • 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"),

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/awesimon/elasticsearch-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server