Skip to main content
Glama

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

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')

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "http": { "default": "", "description": "HTTP endpoint to check", "type": "string" }, "id": { "default": "", "description": "ID of the health check (defaults to name if not provided)", "type": "string" }, "interval": { "default": "", "description": "Interval for the check (e.g., '10s', '1m')", "type": "string" }, "name": { "default": "", "description": "Name of the health check", "type": "string" }, "notes": { "default": "", "description": "Notes about the health check", "type": "string" }, "serviceId": { "default": "", "description": "ID of the service to associate the check with", "type": "string" }, "timeout": { "default": "", "description": "Timeout for the check (e.g., '5s', '30s')", "type": "string" }, "ttl": { "default": "", "description": "Time to live for the check (e.g., '10s', '1m')", "type": "string" } }, "type": "object" }

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

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