Skip to main content
Glama

get-health-checks

Retrieve health checks for specified services using the Consul MCP Server, enabling monitoring and management of service status through standardized queries.

Instructions

Get health checks for a service

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serviceNoName of the service to get health checks for

Implementation Reference

  • The async handler function that retrieves health checks for the specified service using Consul's health.service API, processes the data, formats it using formatHealthCheck, and returns the formatted text.
    async ({ service }) => {
      try {
        const data = await consul.health.service({ service });
        if (!data || data.length === 0) {
          return { content: [{ type: "text", text: `No health checks found for service: ${service}` }] };
        }
        
        // Extract health checks from the response
        const checks = data.flatMap(entry => entry.Checks || []);
        if (checks.length === 0) {
          return { content: [{ type: "text", text: `No health checks found for service: ${service}` }] };
        }
        
        const checksText = `Health checks for service ${service}:\n\n${checks.map(formatHealthCheck).join("\n")}`;
        return { content: [{ type: "text", text: checksText }] };
      } catch (error) {
        console.error("Error getting health checks:", error);
        return { content: [{ type: "text", text: `Error getting health checks for service: ${service}` }] };
      }
    }
  • Zod schema defining the input parameter 'service' (string, name of the service).
    {
      service: z.string().default("").describe("Name of the service to get health checks for"),
    },
  • Registration of the 'get-health-checks' tool using server.tool(), including name, description, schema, and inline handler.
    server.tool(
      "get-health-checks",
      "Get health checks for a service",
      {
        service: z.string().default("").describe("Name of the service to get health checks for"),
      },
      async ({ service }) => {
        try {
          const data = await consul.health.service({ service });
          if (!data || data.length === 0) {
            return { content: [{ type: "text", text: `No health checks found for service: ${service}` }] };
          }
          
          // Extract health checks from the response
          const checks = data.flatMap(entry => entry.Checks || []);
          if (checks.length === 0) {
            return { content: [{ type: "text", text: `No health checks found for service: ${service}` }] };
          }
          
          const checksText = `Health checks for service ${service}:\n\n${checks.map(formatHealthCheck).join("\n")}`;
          return { content: [{ type: "text", text: checksText }] };
        } catch (error) {
          console.error("Error getting health checks:", error);
          return { content: [{ type: "text", text: `Error getting health checks for service: ${service}` }] };
        }
      }
    );
  • formatHealthCheck function used by the handler to format individual health check objects into multi-line strings for output.
    export function formatHealthCheck(check: HealthCheck): string {
      return [
        `Node: ${check.Node || "Unknown"}`,
        `CheckID: ${check.CheckID || "Unknown"}`,
        `Name: ${check.Name || "Unknown"}`,
        `Status: ${check.Status || "Unknown"}`,
        `ServiceName: ${check.ServiceName || "Unknown"}`,
        `ServiceID: ${check.ServiceID || "Unknown"}`, 
        `ServiceTags: ${check.ServiceTags?.join(", ") || "None"}`,
        `ServiceName: ${check.ServiceName || "Unknown"}`,
        `Output: ${check.Output || "No output"}`,
        "---",
      ].join("\n");
    }

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/kocierik/consul-mcp-server'

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