get-services
Retrieve active services using the standardized Model Context Protocol interface for Consul, enabling efficient access to service data and health checks.
Instructions
Get running services
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/consulTools.ts:278-286 (handler)The handler function that executes the tool logic: lists running services from Consul agent using consul.agent.service.list(), formats them with formatService, and returns formatted text.async () => { const data = await consul.agent.service.list(); if (!data) { return { content: [{ type: "text", text: "Failed to retrieve services list data" }] }; } const dataText = `List of services:\n\n${Object.values(data).map(formatService).join("\n")}`; return { content: [{ type: "text", text: dataText }] }; }
- src/tools/consulTools.ts:274-287 (registration)Registration of the 'get-services' tool on the MCP server within the registerServiceList function.server.tool( "get-services", "Get running services", {}, async () => { const data = await consul.agent.service.list(); if (!data) { return { content: [{ type: "text", text: "Failed to retrieve services list data" }] }; } const dataText = `List of services:\n\n${Object.values(data).map(formatService).join("\n")}`; return { content: [{ type: "text", text: dataText }] }; } );
- src/utils/formatter.ts:3-12 (helper)Helper function to format a single Consul service object into a multi-line string for display.export function formatService(feature: ServiceList): string { const props = feature; return [ `ID: ${props.ID || "Unknown"}`, `Port: ${props.Port || "Unknown"}`, `Service: ${props.Service || "Unknown"}`, `Tags: ${props.Tags || "Unknown"}`, "---", ].join("\n"); }
- src/types/consul.ts:1-6 (schema)TypeScript interface defining the structure of a Consul service list entry, used by the formatService helper.export interface ServiceList { ID: string; Service: string; Tags: string[]; Port: number; }
- src/server.ts:36-36 (registration)Top-level call to registerServiceList function, attaching the 'get-services' tool to the MCP server instance.registerServiceList(server, consul);