get-catalog-service
Retrieve detailed information about a specific service from the catalog using Consul MCP Server, enabling efficient service discovery and management.
Instructions
Get information about a specific service from the catalog
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service | No | Name of the service to get information for |
Implementation Reference
- src/tools/consulTools.ts:228-248 (handler)Full tool registration and handler implementation for 'get-catalog-service'. Includes input schema using Zod, fetches service nodes from Consul catalog, handles errors, and formats output with formatCatalogNode.server.tool( "get-catalog-service", "Get information about a specific service from the catalog", { service: z.string().default("").describe("Name of the service to get information for"), }, async ({ service }) => { try { const data = await consul.catalog.service.nodes(service); if (!data || data.length === 0) { return { content: [{ type: "text", text: `No information found for service: ${service}` }] }; } const serviceText = `Service information for ${service}:\n\n${data.map(formatCatalogNode).join("\n")}`; return { content: [{ type: "text", text: serviceText }] }; } catch (error) { console.error("Error getting service information:", error); return { content: [{ type: "text", text: `Error getting information for service: ${service}` }] }; } } );
- src/tools/consulTools.ts:231-233 (schema)Input schema for the get-catalog-service tool defining the 'service' parameter as a string.{ service: z.string().default("").describe("Name of the service to get information for"), },
- src/server.ts:39-39 (registration)Invocation of registerCatalogServices function which registers the get-catalog-service tool among others.registerCatalogServices(server, consul);
- src/utils/formatter.ts:29-39 (helper)Utility function to format individual CatalogNode objects into readable strings, used in the tool's output formatting.export function formatCatalogNode(node: CatalogNode): string { return [ `Node: ${node.Node || "Unknown"}`, `Address: ${node.Address || "Unknown"}`, `ServiceID: ${node.ServiceID || "Unknown"}`, `ServiceName: ${node.ServiceName || "Unknown"}`, `ServicePort: ${node.ServicePort || "Unknown"}`, `ServiceTags: ${node.ServiceTags?.join(", ") || "None"}`, "---", ].join("\n"); }