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
| Name | Required | Description | Default |
|---|---|---|---|
| service | No | Name of the service to get health checks for |
Implementation Reference
- src/tools/consulTools.ts:179-198 (handler)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}` }] }; } }
- src/tools/consulTools.ts:176-178 (schema)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"), },
- src/tools/consulTools.ts:173-199 (registration)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}` }] }; } } );
- src/utils/formatter.ts:14-27 (helper)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"); }