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
| Name | Required | Description | Default |
|---|---|---|---|
| http | No | HTTP endpoint to check | |
| id | No | ID of the health check (defaults to name if not provided) | |
| interval | No | Interval for the check (e.g., '10s', '1m') | |
| name | No | Name of the health check | |
| notes | No | Notes about the health check | |
| serviceId | No | ID of the service to associate the check with | |
| timeout | No | Timeout for the check (e.g., '5s', '30s') | |
| ttl | No | Time 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
- src/tools/consulTools.ts:121-149 (handler)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}` }] }; } }
- src/tools/consulTools.ts:111-120 (schema)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')"), },
- src/tools/consulTools.ts:108-150 (registration)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);