Skip to main content
Glama
awesimon

Elasticsearch MCP Server

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

Implementation Reference

  • 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); } );
  • Zod schema definition for the optional 'pattern' input parameter used in tool registration.
    .string() .optional() .describe("Optional regex pattern to filter indices by name"), },

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