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

TableJSON 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

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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool retrieves data, implying a read-only operation, but doesn't disclose behavioral traits such as rate limits, authentication needs, error handling, or the format of returned values. The description is minimal and lacks context about what 'unique values' entails (e.g., sorted, paginated).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Retrieves all unique values') and specifies key constraints ('associated with a specific labelName within a Loki datasource and time range'). There is no wasted language, and it's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool with four parameters. It doesn't explain what the tool returns (e.g., format of values, potential errors), behavioral aspects like performance or limits, or how it differs from similar sibling tools. For a read operation with temporal parameters, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters (datasourceUid, endRfc3339, labelName, startRfc3339) with clear descriptions. The description adds minimal value beyond the schema by mentioning 'time range' (implied by startRfc3339 and endRfc3339) and 'Loki datasource' (implied by datasourceUid). Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Retrieves') and resource ('all unique values associated with a specific labelName within a Loki datasource and time range'). It distinguishes from sibling tools like 'list_loki_label_names' by focusing on values rather than names, but doesn't explicitly differentiate from 'list_prometheus_label_values' or 'list_pyroscope_label_values' which have similar patterns for different datasources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'within a Loki datasource and time range,' suggesting when to use it (for Loki label values with temporal constraints). However, it doesn't provide explicit guidance on when to choose this over alternatives like 'list_prometheus_label_values' or 'list_pyroscope_label_values,' nor does it mention prerequisites or exclusions beyond the required parameters.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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