Skip to main content
Glama
awesimon

Elasticsearch MCP Server

list_indices

List all Elasticsearch indices to view available data sources; optionally filter by regex pattern for precise index discovery.

Instructions

List all available Elasticsearch indices, support regex

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternNoOptional regex pattern to filter indices by name

Implementation Reference

  • The core handler function for the 'list_indices' tool. Calls esClient.cat.indices() to fetch all Elasticsearch indices (optionally filtered by a pattern), maps results to a simplified format (index, health, status, docsCount), and returns a text response with the count and JSON details.
    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)
                }`,
            },
          ],
        };
      }
    } 
  • Zod schema (input validation) for the 'list_indices' tool. Defines an optional 'pattern' string parameter to filter indices by name.
    {
      pattern: z
        .string()
        .optional()
        .describe("Optional regex pattern to filter indices by name"),
    },
  • src/server.ts:41-53 (registration)
    Registration of the 'list_indices' tool on the MCP server using server.tool(), with the name 'list_indices', a description, the zod schema, and a handler that calls the listIndices function.
    server.tool(
      "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);
      }
    );
  • Helper function createClientOptions() used in server.ts to build the Elasticsearch Client options from configuration. This is indirectly related as it sets up the esClient passed to listIndices.
    export function createClientOptions(config: ElasticsearchConfig): ClientOptions {
      const validatedConfig = ConfigSchema.parse(config);
      const { urls, apiKey, username, password, caCert } = validatedConfig;
    
      const clientOptions: ClientOptions = {
        nodes: urls,
      };
    
      // 设置认证
      if (apiKey) {
        clientOptions.auth = { apiKey };
      } else if (username && password) {
        clientOptions.auth = { username, password };
      }
    
      // 如果提供了证书,设置 SSL/TLS
      if (caCert) {
        try {
          const ca = fs.readFileSync(caCert);
          clientOptions.tls = { ca };
        } catch (error) {
          console.error(
            `Failed to read certificate file: ${
              error instanceof Error ? error.message : String(error)
            }`
          );
        }
      }
    
      return clientOptions;
    }
Behavior3/5

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

Description lists indices but does not disclose pagination, performance, or side effects; no annotations to rely on, so the description carries full burden but is minimal.

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?

Single sentence, front-loaded, no wasted words.

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

Completeness3/5

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

No output schema, and description does not explain return format (e.g., what properties each index entry has), leaving gaps for the agent.

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

Parameters4/5

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

The description mentions regex support, adding context beyond the schema description for the pattern parameter, which already has 100% coverage.

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

Purpose5/5

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

The description clearly states it lists all Elasticsearch indices with regex support, distinguishing it from sibling tools like search or create_index.

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

Usage Guidelines3/5

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

No explicit guidance on when to use this tool vs alternatives; usage is implied but not elaborated.

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

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