Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_prometheus_label_values

Retrieve available values for a specific Prometheus label, with options to filter by series selectors and time range for precise monitoring data analysis.

Instructions

Get the values for a specific label name in Prometheus. Allows filtering by series selectors and time range.

Input Schema

NameRequiredDescriptionDefault
datasourceUidYesThe UID of the datasource to query
endRfc3339NoThe end time of the query
labelNameYesThe name of the label to query
limitNoMaximum number of results
matchesNoSelectors to filter the results
startRfc3339NoThe start time of the query

Input Schema (JSON Schema)

{ "properties": { "datasourceUid": { "description": "The UID of the datasource to query", "type": "string" }, "endRfc3339": { "description": "The end time of the query", "type": "string" }, "labelName": { "description": "The name of the label to query", "type": "string" }, "limit": { "description": "Maximum number of results", "type": "number" }, "matches": { "description": "Selectors to filter the results", "items": { "additionalProperties": false, "properties": { "filters": { "items": { "additionalProperties": false, "properties": { "name": { "description": "The name of the label to match against", "type": "string" }, "type": { "description": "The match operator", "enum": [ "=", "!=", "=~", "!~" ], "type": "string" }, "value": { "description": "The value to match against", "type": "string" } }, "required": [ "name", "value", "type" ], "type": "object" }, "type": "array" } }, "required": [ "filters" ], "type": "object" }, "type": "array" }, "startRfc3339": { "description": "The start time of the query", "type": "string" } }, "required": [ "datasourceUid", "labelName" ], "type": "object" }

Implementation Reference

  • The ToolDefinition object including the handler function that executes the logic for listing Prometheus label values using the PrometheusClient.
    export const listPrometheusLabelValues: ToolDefinition = { name: 'list_prometheus_label_values', description: 'Get the values for a specific label name in Prometheus. Allows filtering by series selectors and time range.', inputSchema: ListPrometheusLabelValuesSchema, handler: async (params, context: ToolContext) => { try { const client = new PrometheusClient(context.config.grafanaConfig, params.datasourceUid); const match = params.matches?.map((m: any) => buildSelector(m.filters)) || []; const values = await client.getLabelValues( params.labelName, match.length > 0 ? match : undefined, params.startRfc3339, params.endRfc3339 ); const limited = params.limit ? values.slice(0, params.limit) : values; return createToolResult(limited); } catch (error: any) { return createErrorResult(error.message); } }, };
  • Zod schema defining the input parameters for the list_prometheus_label_values tool.
    const ListPrometheusLabelValuesSchema = z.object({ datasourceUid: z.string().describe('The UID of the datasource to query'), labelName: z.string().describe('The name of the label to query'), matches: z.array(z.object({ filters: z.array(z.object({ name: z.string().describe('The name of the label to match against'), value: z.string().describe('The value to match against'), type: z.enum(['=', '!=', '=~', '!~']).describe('The match operator'), })), })).optional().describe('Selectors to filter the results'), startRfc3339: z.string().optional().describe('The start time of the query'), endRfc3339: z.string().optional().describe('The end time of the query'), limit: z.number().optional().describe('Maximum number of results'), });
  • Registration function for Prometheus tools, including the registration of listPrometheusLabelValues tool.
    export function registerPrometheusTools(server: any) { server.registerTool(queryPrometheus); server.registerTool(listPrometheusMetricNames); server.registerTool(listPrometheusLabelNames); server.registerTool(listPrometheusLabelValues); server.registerTool(listPrometheusMetricMetadata); }
  • Helper function used in the handler to build Prometheus label matchers/selectors from input filters.
    function buildSelector(filters: any[]): string { if (!filters || filters.length === 0) return '{}'; const parts = filters.map(f => { switch (f.type) { case '=': return `${f.name}="${f.value}"`; case '!=': return `${f.name}!="${f.value}"`; case '=~': return `${f.name}=~"${f.value}"`; case '!~': return `${f.name}!~"${f.value}"`; default: return ''; } }).filter(p => p); return `{${parts.join(',')}}`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xteamhq/mcp-grafana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server