list_loki_label_names
Retrieve all available label names from Loki log data within a specified time range to identify and filter log entries effectively.
Instructions
Lists all available label names (keys) found in logs within a specified Loki datasource and time range
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datasourceUid | Yes | The UID of the datasource to query | |
| endRfc3339 | No | The end time of the query in RFC3339 format | |
| startRfc3339 | No | The 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"
},
"startRfc3339": {
"description": "The start time of the query in RFC3339 format",
"type": "string"
}
},
"required": [
"datasourceUid"
],
"type": "object"
}
Implementation Reference
- src/tools/loki.ts:58-79 (handler)Full ToolDefinition including the handler function that instantiates LokiClient and calls getLabelNames with time range handlingexport const listLokiLabelNames: ToolDefinition = { name: 'list_loki_label_names', description: 'Lists all available label names (keys) found in logs within a specified Loki datasource and time range', inputSchema: ListLokiLabelNamesSchema, 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 labels = await client.getLabelNames( params.startRfc3339 || timeRange.start, params.endRfc3339 || timeRange.end ); return createToolResult(labels); } catch (error: any) { return createErrorResult(error.message); } }, };
- src/tools/loki.ts:21-25 (schema)Zod input schema for the list_loki_label_names toolconst ListLokiLabelNamesSchema = z.object({ datasourceUid: z.string().describe('The UID of the datasource to query'), 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'), });
- src/clients/loki-client.ts:80-96 (helper)LokiClient method that performs the actual API call to retrieve label names from Lokiasync getLabelNames(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/labels', { params }); if (response.data.status !== 'success') { throw new Error(`Failed to get label names: ${response.data.error || 'Unknown error'}`); } return response.data.data || []; } catch (error) { this.handleError(error); } }
- src/tools/loki.ts:174-180 (registration)Function that registers all Loki tools including listLokiLabelNamesexport function registerLokiTools(server: any) { server.registerTool(listLokiLabelNames); server.registerTool(listLokiLabelValues); server.registerTool(queryLokiLogs); server.registerTool(queryLokiStats); server.registerTool(findErrorPatternLogs); }
- src/cli.ts:110-112 (registration)Top-level call to register Loki tools if 'loki' category is enabledif (enabledTools.has('loki')) { registerLokiTools(server); }