Skip to main content
Glama
kocierik
by kocierik

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");
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations, the description carries full burden. It only says 'Get', implying read-only, but does not state idempotency, side effects (or lack thereof), permissions, or rate limits.

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

Conciseness4/5

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

The description is a single sentence with no extraneous text. It is concise and front-loads the core purpose.

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?

Without an output schema or annotations, the description lacks context about what health checks are returned, the format, pagination, or any operational details. It is not complete enough for an agent to fully understand usage.

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 single parameter 'service', and the schema already provides a clear description. The tool description merely echoes 'for a service' without adding new meaning.

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 uses specific verb 'Get' and resource 'health checks' with qualifier 'for a service'. It clearly indicates the action and resource, though it does not explicitly differentiate from siblings like 'register-health-check' or 'deregister-health-check'.

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. The description does not mention any preconditions, disclaimers, or comparisons to sibling tools, which are abundant.

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