Skip to main content
Glama
Octodet

octodet-elasticsearch-mcp

list_indices

Retrieve detailed information on all Elasticsearch indices matching a specified pattern, facilitating efficient data discovery and management.

Instructions

List all available Elasticsearch indices with detailed information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexPatternYesPattern of Elasticsearch indices to list (e.g., "logs-*")

Implementation Reference

  • The handler function for the 'list_indices' tool. It takes an indexPattern, calls the Elasticsearch service to list matching indices, formats the response as MCP content with summary and JSON, or returns an error message.
    try { const indicesInfo = await esService.listIndices(indexPattern); return { content: [ { type: "text", text: `Found ${indicesInfo.length} indices matching pattern '${indexPattern}'`, }, { type: "text", 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", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Zod input schema for the 'list_indices' tool defining the indexPattern parameter.
    indexPattern: z .string() .trim() .min(1, "Index pattern is required") .describe('Pattern of Elasticsearch indices to list (e.g., "logs-*")'), }, async ({ indexPattern }) => {
  • src/index.ts:98-141 (registration)
    Registration of the 'list_indices' MCP tool on the server, including name, description, input schema, and handler reference.
    "list_indices", "List all available Elasticsearch indices with detailed information", { indexPattern: z .string() .trim() .min(1, "Index pattern is required") .describe('Pattern of Elasticsearch indices to list (e.g., "logs-*")'), }, async ({ indexPattern }) => { try { const indicesInfo = await esService.listIndices(indexPattern); return { content: [ { type: "text", text: `Found ${indicesInfo.length} indices matching pattern '${indexPattern}'`, }, { type: "text", 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", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
  • Core helper function in ElasticsearchService that queries ES cat.indices API to retrieve and parse index information matching the pattern.
    async listIndices(indexPattern: string): Promise<IndexInfo[]> { const response = await this.client.cat.indices({ index: indexPattern, format: "json", h: "index,health,status,docs.count,store.size,pri,rep", }); return response.map((index: any) => ({ index: index.index, health: index.health, status: index.status, docsCount: parseInt(index["docs.count"] || "0", 10), storeSize: index["store.size"] || "0", primaryShards: parseInt(index.pri || "0", 10), replicaShards: parseInt(index.rep || "0", 10), })); }
  • TypeScript interface defining the structure of IndexInfo returned by listIndices.
    export interface IndexInfo { index: string; health: string; status: string; docsCount: number; storeSize: string; primaryShards: number; replicaShards: number; }

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/Octodet/elasticsearch-mcp'

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