prometheus_list_labels
Discover all available Prometheus labels to identify and filter metrics for monitoring queries and analysis.
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)Implements the core logic of the prometheus_list_labels tool by making an HTTP GET request to the Prometheus /api/v1/labels endpoint via the private request method, returning a list of label names.async listLabels(): Promise<Labels> { const endpoint = "/api/v1/labels"; return this.request<Labels>(endpoint); }
- src/server/tools.ts:115-122 (registration)Registers the 'prometheus_list_labels' tool in the tools array, defining its metadata, empty input schema, and handler that delegates to PrometheusClient.listLabels().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)Defines the empty input schema (no parameters required) used by the prometheus_list_labels tool.const EmptySchema = z.object({});
- src/prometheus/client.ts:52-92 (helper)Private helper method in PrometheusClient that handles all HTTP requests to Prometheus API, used by listLabels() including URL construction, fetch, status checks, JSON parsing, and comprehensive error handling/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; }