Skip to main content
Glama
kocierik
by kocierik

register-health-check

Defines and registers a health check with Consul, specifying name, service association, TTL, HTTP endpoint, interval, and timeout for monitoring service status and availability.

Instructions

Register a health check with Consul

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
httpNoHTTP endpoint to check
idNoID of the health check (defaults to name if not provided)
intervalNoInterval for the check (e.g., '10s', '1m')
nameNoName of the health check
notesNoNotes about the health check
serviceIdNoID of the service to associate the check with
timeoutNoTimeout for the check (e.g., '5s', '30s')
ttlNoTime to live for the check (e.g., '10s', '1m')

Implementation Reference

  • The handler function that performs the actual registration of the health check using Consul's agent.check.register method. It constructs the check definition from input parameters and handles success/error responses.
    async ({ name, id, serviceId, notes, ttl, http, interval, timeout }) => {
      try {
        const checkId = id || name;
        const checkDefinition: any = {
          name,
          id: checkId,
        };
        
        if (serviceId !== undefined) checkDefinition.serviceId = serviceId;
        if (notes !== undefined) checkDefinition.notes = notes;
        if (ttl !== undefined) checkDefinition.ttl = ttl;
        if (http !== undefined) {
          checkDefinition.http = http;
          // HTTP checks require an interval
          if (interval !== undefined) checkDefinition.interval = interval;
        }
        if (timeout !== undefined) checkDefinition.timeout = timeout;
        
        const success = await consul.agent.check.register(checkDefinition);
        if (!success) {
          return { content: [{ type: "text", text: `Failed to register health check: ${name}` }] };
        }
        
        return { content: [{ type: "text", text: `Successfully registered health check: ${name} with ID: ${checkId}` }] };
      } catch (error) {
        console.error("Error registering health check:", error);
        return { content: [{ type: "text", text: `Error registering health check: ${name}` }] };
      }
    }
  • Zod schema defining the input parameters for the register-health-check tool, including optional fields for check configuration.
    {
      name: z.string().default("").describe("Name of the health check"),
      id: z.string().default("").default("").optional().describe("ID of the health check (defaults to name if not provided)"),
      serviceId: z.string().default("").optional().describe("ID of the service to associate the check with"),
      notes: z.string().default("").optional().describe("Notes about the health check"),
      ttl: z.string().default("").optional().describe("Time to live for the check (e.g., '10s', '1m')"),
      http: z.string().default("").optional().describe("HTTP endpoint to check"),
      interval: z.string().default("").optional().describe("Interval for the check (e.g., '10s', '1m')"),
      timeout: z.string().default("").optional().describe("Timeout for the check (e.g., '5s', '30s')"),
    },
  • The server.tool call that registers the 'register-health-check' tool with the MCP server, including name, description, schema, and handler.
    server.tool(
      "register-health-check",
      "Register a health check with Consul",
      {
        name: z.string().default("").describe("Name of the health check"),
        id: z.string().default("").default("").optional().describe("ID of the health check (defaults to name if not provided)"),
        serviceId: z.string().default("").optional().describe("ID of the service to associate the check with"),
        notes: z.string().default("").optional().describe("Notes about the health check"),
        ttl: z.string().default("").optional().describe("Time to live for the check (e.g., '10s', '1m')"),
        http: z.string().default("").optional().describe("HTTP endpoint to check"),
        interval: z.string().default("").optional().describe("Interval for the check (e.g., '10s', '1m')"),
        timeout: z.string().default("").optional().describe("Timeout for the check (e.g., '5s', '30s')"),
      },
      async ({ name, id, serviceId, notes, ttl, http, interval, timeout }) => {
        try {
          const checkId = id || name;
          const checkDefinition: any = {
            name,
            id: checkId,
          };
          
          if (serviceId !== undefined) checkDefinition.serviceId = serviceId;
          if (notes !== undefined) checkDefinition.notes = notes;
          if (ttl !== undefined) checkDefinition.ttl = ttl;
          if (http !== undefined) {
            checkDefinition.http = http;
            // HTTP checks require an interval
            if (interval !== undefined) checkDefinition.interval = interval;
          }
          if (timeout !== undefined) checkDefinition.timeout = timeout;
          
          const success = await consul.agent.check.register(checkDefinition);
          if (!success) {
            return { content: [{ type: "text", text: `Failed to register health check: ${name}` }] };
          }
          
          return { content: [{ type: "text", text: `Successfully registered health check: ${name} with ID: ${checkId}` }] };
        } catch (error) {
          console.error("Error registering health check:", error);
          return { content: [{ type: "text", text: `Error registering health check: ${name}` }] };
        }
      }
    );
  • src/server.ts:37-37 (registration)
    Invocation of registerHealthChecks function which includes the registration of the 'register-health-check' tool among others.
    registerHealthChecks(server, consul);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.1/5.0
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It only states the action and system, omitting details like idempotency, side effects, permissions, or error handling for a mutation tool.

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 concise sentence that is front-loaded. It efficiently communicates the core purpose, though some additional context could be added without sacrificing conciseness.

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?

Given 8 parameters, no output schema, and no annotations, the description is too minimal. It does not explain parameter interactions, return values, or important usage constraints, making it incomplete for effective use.

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%, so baseline is 3. The description adds no additional parameter-level meaning beyond what the schema already provides.

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 verb 'Register' and the resource 'health check' with the system 'Consul'. It is specific and distinguishes from sibling tools like 'deregister-health-check' and 'get-health-checks'.

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?

The description provides no guidance on when to use this tool versus alternatives like 'register-service' or prerequisites. It lacks context for proper selection.

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