Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

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

NameRequiredDescriptionDefault
datasourceUidYesThe UID of the datasource to query
endRfc3339NoThe end time of the query in RFC3339 format
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" }, "startRfc3339": { "description": "The start time of the query in RFC3339 format", "type": "string" } }, "required": [ "datasourceUid" ], "type": "object" }

Implementation Reference

  • Full ToolDefinition including the handler function that instantiates LokiClient and calls getLabelNames with time range handling
    export 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); } }, };
  • Zod input schema for the list_loki_label_names tool
    const 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'), });
  • LokiClient method that performs the actual API call to retrieve label names from Loki
    async 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); } }
  • Function that registers all Loki tools including listLokiLabelNames
    export 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 enabled
    if (enabledTools.has('loki')) { 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