Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_loki_label_values

Retrieve all unique values for a specific label within a Loki datasource and time range to analyze log data patterns and filter queries effectively.

Instructions

Retrieves all unique values associated with a specific labelName within a Loki datasource and time range

Input Schema

NameRequiredDescriptionDefault
datasourceUidYesThe UID of the datasource to query
endRfc3339NoThe end time of the query in RFC3339 format
labelNameYesThe name of the label to retrieve values for
startRfc3339NoThe start time of the query in RFC3339 format

Input Schema (JSON Schema)

{ "properties": { "datasourceUid": { "description": "The UID of the datasource to query", "type": "string" }, "endRfc3339": { "description": "The end time of the query in RFC3339 format", "type": "string" }, "labelName": { "description": "The name of the label to retrieve values for", "type": "string" }, "startRfc3339": { "description": "The start time of the query in RFC3339 format", "type": "string" } }, "required": [ "datasourceUid", "labelName" ], "type": "object" }

Implementation Reference

  • The async handler function for the list_loki_label_values tool. Instantiates LokiClient and calls getLabelValues with the provided parameters and time range.
    handler: async (params, context: ToolContext) => { try { const client = new LokiClient(context.config.grafanaConfig, params.datasourceUid); const timeRange: TimeRange = params.startRfc3339 || params.endRfc3339 ? { start: '', end: '' } : getDefaultTimeRange(); const values = await client.getLabelValues( params.labelName, params.startRfc3339 || timeRange.start, params.endRfc3339 || timeRange.end ); return createToolResult(values); } catch (error: any) { return createErrorResult(error.message); } },
  • Zod input schema defining parameters for datasourceUid, labelName, and optional start/end times.
    const ListLokiLabelValuesSchema = z.object({ datasourceUid: z.string().describe('The UID of the datasource to query'), labelName: z.string().describe('The name of the label to retrieve values for'), startRfc3339: z.string().optional().describe('The start time of the query in RFC3339 format'), endRfc3339: z.string().optional().describe('The end time of the query in RFC3339 format'), });
  • Function to register all Loki tools, including listLokiLabelValues, with the MCP server.
    export function registerLokiTools(server: any) { server.registerTool(listLokiLabelNames); server.registerTool(listLokiLabelValues); server.registerTool(queryLokiLogs); server.registerTool(queryLokiStats); server.registerTool(findErrorPatternLogs); }
  • LokiClient.getLabelValues method that queries the Loki API endpoint /loki/api/v1/label/{label}/values to retrieve unique values for the specified label.
    async getLabelValues(label: string, start?: string, end?: string): Promise<string[]> { try { const params: any = {}; if (start) params.start = start; if (end) params.end = end; const response = await this.client.get(`/loki/api/v1/label/${label}/values`, { params }); if (response.data.status !== 'success') { throw new Error(`Failed to get label values: ${response.data.error || 'Unknown error'}`); } return response.data.data || []; } catch (error) { this.handleError(error); } }
  • src/cli.ts:111-111 (registration)
    Call to registerLokiTools in the CLI entry point, which registers the list_loki_label_values tool.
    registerLokiTools(server);

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