prometheus_label_values
Retrieve all available values for a specific label in your Prometheus monitoring system to filter and analyze metrics effectively.
Instructions
Get all values for a specific Prometheus label
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| label | Yes | label name to get values for |
Implementation Reference
- src/prometheus/client.ts:218-221 (handler)Executes the tool logic by making an HTTP GET request to the Prometheus API endpoint `/api/v1/label/{label}/values` to retrieve all values for the specified label.async getLabelValues(label: string): Promise<LabelValues> { const endpoint = `/api/v1/label/${encodeURIComponent(label)}/values`; return this.request<LabelValues>(endpoint); }
- src/server/tools.ts:68-70 (schema)Zod schema defining the input parameters for the tool: a required 'label' string.const PrometheusLabelValuesSchema = z.object({ label: z.string().describe("label name to get values for"), });
- src/server/tools.ts:123-131 (registration)Registers the tool in the tools array with metadata, schema, and handler function that delegates to PrometheusClient.getLabelValues.defineTool<typeof PrometheusLabelValuesSchema, LabelValues>({ capability: "discovery", name: "prometheus_label_values", title: "Get Label Values", description: "Get all values for a specific Prometheus label", inputSchema: PrometheusLabelValuesSchema, type: "readonly", handle: async (client: PrometheusClient, args) => client.getLabelValues(args.label), }),
- src/server/server.ts:58-62 (registration)Registers filtered tools (including prometheus_label_values if discovery enabled) with the MCP server via _registerTool.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 that performs all HTTP requests to Prometheus API, handles responses, errors, 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; }