prometheus_list_labels
Retrieve all available Prometheus labels for metric analysis and monitoring. Enables efficient querying and organization of metrics within the Prometheus ecosystem.
Instructions
List all available Prometheus labels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/prometheus/client.ts:200-203 (handler)Core implementation of the prometheus_list_labels tool logic. The PrometheusClient.listLabels() method makes an HTTP GET request to the Prometheus /api/v1/labels endpoint to retrieve all label names.async listLabels(): Promise<Labels> { const endpoint = "/api/v1/labels"; return this.request<Labels>(endpoint); }
- src/server/tools.ts:114-122 (registration)Registers the prometheus_list_labels tool in the tools array. Specifies schema (EmptySchema, no input params), capability, and thin handler delegating to PrometheusClient.listLabels().defineTool<typeof EmptySchema, Labels>({ capability: "discovery", name: "prometheus_list_labels", title: "List Prometheus Labels", description: "List all available Prometheus labels", inputSchema: EmptySchema, type: "readonly", handle: async (client: PrometheusClient) => client.listLabels(), }),
- src/server/tools.ts:76-76 (schema)Zod input schema for prometheus_list_labels tool (and other parameterless tools), defining no required input parameters.const EmptySchema = z.object({});
- src/server/server.ts:57-62 (registration)Filters tools by capability and registers prometheus_list_labels (if discovery enabled) to the MCP server using _registerTool, which calls registerTool with schema and execution handler.// Filter tools based on enabled capabilities const prometheusTools: ToolAny[] = tools.filter( (tool) => validatedConfig[capabilityMap[tool.capability]] ?? false, ); prometheusTools.forEach((tool) => this._registerTool(tool)); }
- src/prometheus/client.ts:52-92 (helper)Private helper method used by listLabels() to perform the HTTP request to Prometheus API, including error handling and logging.private async request<T>( endpoint: string, params?: Record<string, string>, ): Promise<T> { const url = new URL(endpoint, this.baseUrl); const queryParams = new URLSearchParams(params); if (queryParams) { url.search = queryParams.toString(); } logger.debug("making prometheus request", { endpoint, url }); try { const response = await fetch(url.toString(), { method: "GET", headers: this.headers, }); if (!response.ok) { const error = `http ${response.status}: ${response.statusText}`; logger.error(error, { endpoint, status: response.status }); throw new Error(error); } const result: Response<T> = await response.json(); if (result.status !== "success") { const errorMsg = result.error || "unknown error"; const error = `prometheus api error: ${errorMsg}`; logger.error(error, { endpoint, status: result.status }); throw new Error(error); } logger.debug("prometheus request successful", { endpoint }); return result.data; } catch (error) { logger.error("prometheus request failed", { endpoint, error: error instanceof Error ? error.message : String(error), }); throw error; }