Skip to main content
Glama
awesimon

Elasticsearch MCP Server

elasticsearch_health

Retrieve the health status of an Elasticsearch cluster. Optionally include index-level details to identify specific issues.

Instructions

Get the health status of the Elasticsearch cluster, optionally include index-level details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeIndicesNoWhether to include index-level details

Implementation Reference

  • The getClusterHealth function executes the tool logic: calls esClient.cluster.health() with optional index-level detail, formats and returns cluster health status as text content.
    export async function getClusterHealth(
      esClient: Client,
      includeIndices: boolean = false
    ) {
      try {
        const response = await esClient.cluster.health({
          level: includeIndices ? "indices" : "cluster"
        });
    
        const content: { type: "text"; text: string }[] = [];
    
        // 添加集群状态概述
        content.push({
          type: "text" as const,
          text: `Cluster Name: ${response.cluster_name}\nStatus: ${response.status}\nNodes: ${response.number_of_nodes}\nData Nodes: ${response.number_of_data_nodes}\nActive Shards: ${response.active_shards}\nActive Primary Shards: ${response.active_primary_shards}\nRelocating Shards: ${response.relocating_shards}\nInitializing Shards: ${response.initializing_shards}\nUnassigned Shards: ${response.unassigned_shards}\nPending Tasks: ${response.number_of_pending_tasks}\n`
        });
    
        // 如果请求了索引级别的健康状态
        if (includeIndices && response.indices) {
          const indicesHealth: string[] = [];
          
          for (const [indexName, indexHealth] of Object.entries(response.indices)) {
            indicesHealth.push(`Index: ${indexName}\n  Status: ${indexHealth.status}\n  Primary Shards: ${indexHealth.number_of_shards}\n  Replicas: ${indexHealth.number_of_replicas}\n  Active Shards: ${indexHealth.active_shards}\n  Active Primary Shards: ${indexHealth.active_primary_shards}\n  Unassigned Shards: ${indexHealth.unassigned_shards}`);
          }
    
          if (indicesHealth.length > 0) {
            content.push({
              type: "text" as const,
              text: `\nIndices Health Status:\n${indicesHealth.join('\n\n')}`
            });
          }
        }
    
        return {
          content
        };
      } catch (error) {
        console.error(`获取集群健康状态失败: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [
            {
              type: "text" as const,
              text: `错误: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        };
      }
    }
  • src/server.ts:106-120 (registration)
    The tool registration on the MCP server: defines the name "elasticsearch_health", its description, the Zod schema for the includeIndices parameter, and the handler callback that delegates to getClusterHealth.
    // Get the health status of the Elasticsearch cluster, optionally include index-level details
    server.tool(
      "elasticsearch_health",
      "Get the health status of the Elasticsearch cluster, optionally include index-level details",
      {
        includeIndices: z
          .boolean()
          .optional()
          .default(false)
          .describe("Whether to include index-level details"),
      },
      async ({ includeIndices }) => {
        return await getClusterHealth(esClient, includeIndices);
      }
    );
  • The input schema for the tool: a single optional boolean field 'includeIndices' with a default of false, validated using Zod.
    {
      includeIndices: z
        .boolean()
        .optional()
        .default(false)
        .describe("Whether to include index-level details"),
    },
  • The import of the Elasticsearch Client dependency used by the handler.
    import { Client } from "@elastic/elasticsearch";
Behavior2/5

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

No annotations exist, and the description only states the action. It does not disclose that the operation is read-only, has no side effects, or any authentication or rate limit requirements. For a health check, this minimal disclosure is inadequate.

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 concise sentence of 12 words, front-loaded with the verb and resource. Every word earns its place with no redundancy or fluff.

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?

The description adequately conveys the tool's purpose and parameter, but lacks details on the output (e.g., health status values like green/yellow/red). Given the tool's simplicity and no output schema, a bit more context would be helpful.

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% for the lone parameter 'includeIndices', which already explains its purpose. The tool description adds minor context by saying 'optionally include index-level details', but does not significantly extend understanding beyond the schema.

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 the tool retrieves the health status of an Elasticsearch cluster, optionally including index-level details. It uses a specific verb 'get' and a distinct resource, differentiating it from sibling tools like search or bulk.

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?

No guidance is provided on when to use this tool versus alternatives, such as when to include index details or what the response indicates. There is no mention of prerequisites or exclusions.

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