Skip to main content
Glama
awesimon

Elasticsearch MCP Server

elasticsearch_health

Check Elasticsearch cluster health status and optionally retrieve index-level details to monitor system performance and identify 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 handler function that executes the tool logic: fetches Elasticsearch cluster health using esClient.cluster.health(), optionally with index details, formats cluster stats and index health into MCP content array, handles errors.
    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:107-120 (registration)
    Registers the 'elasticsearch_health' tool on the MCP server, including input schema (includeIndices boolean) and handler that calls getClusterHealth.
    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);
      }
    );
  • Zod input schema for the tool: optional boolean includeIndices with default false.
      includeIndices: z
        .boolean()
        .optional()
        .default(false)
        .describe("Whether to include index-level details"),
    },

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