Skip to main content
Glama
rishab2404

Elasticsearch MCP Server

by rishab2404

list_indices

Retrieve all available Elasticsearch indices by specifying an index pattern using the MCP server. Simplify database queries and manage indices effectively.

Instructions

List all available Elasticsearch indices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexPatternYesIndex pattern of Elasticsearch indices to list

Implementation Reference

  • Handler function for the 'list_indices' tool. It queries Elasticsearch for indices matching the given pattern using cat.indices API, formats the response with health, status, and document count, and returns the results as text content. Includes error handling.
    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) }`, }, ], }; } }
  • Input schema for the 'list_indices' tool. Defines 'indexPattern' as a required trimmed string with a description.
    indexPattern: z .string() .trim() .min(1, "Index pattern is required") .describe("Index pattern of Elasticsearch indices to list"), },
  • index.ts:119-174 (registration)
    Registration of the 'list_indices' tool using server.tool(). Includes name, description, input schema, and handler function.
    server.tool( "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) }`, }, ], }; } } );

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

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