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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'detailed information' but doesn't specify what that includes (e.g., index names, settings, stats) or behavioral traits like pagination, rate limits, or permissions required. This leaves significant gaps for a tool that interacts with a database system.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'detailed information' entails in the return values, nor does it cover behavioral aspects like error handling or system interactions, which are crucial for a tool querying Elasticsearch indices.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema fully documents the single parameter 'indexPattern'. The description adds no additional parameter semantics beyond what the schema provides, such as examples of patterns or usage context, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('Elasticsearch indices'), specifying that it provides 'detailed information'. However, it doesn't explicitly differentiate from sibling tools like 'get_aliases' or 'get_mappings', which also retrieve index-related information, so it misses the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_aliases' or 'get_mappings', nor does it mention prerequisites or exclusions. It's a basic statement of function without contextual usage advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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