Skip to main content
Glama
rishab2404

Elasticsearch MCP Server

by rishab2404

list_indices

Lists Elasticsearch indices matching a specific pattern to help users discover and access available data collections for querying and analysis.

Instructions

List all available Elasticsearch indices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexPatternYesIndex pattern of Elasticsearch indices to list

Implementation Reference

  • The async handler function that executes the list_indices tool logic: fetches indices using esClient.cat.indices with the given indexPattern, maps to a simplified info object, and returns formatted text content. Handles errors gracefully.
    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) }`, }, ], }; } }
  • Zod input schema defining the 'indexPattern' parameter as a required trimmed string.
    .string() .trim() .min(1, "Index pattern is required") .describe("Index pattern of Elasticsearch indices to list"), },
  • index.ts:120-174 (registration)
    Registration of the 'list_indices' tool on the MCP server, including name, description, input schema, and handler function.
    "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) }`, }, ], }; } } );
Install Server

Other 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/rishab2404/mcp_es'

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