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

TableJSON 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

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);
    }
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 of behavioral disclosure. It states the tool lists label names but doesn't describe output format (e.g., array of strings), pagination, rate limits, authentication requirements, or error conditions. For a read-only query tool with no annotation coverage, this leaves significant gaps in understanding how the tool behaves beyond its basic purpose.

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, well-structured sentence that efficiently conveys the tool's purpose without redundancy. It front-loads the key action ('Lists all available label names') and includes essential qualifiers ('found in logs within a specified Loki datasource and time range'), making it easy to parse quickly with zero wasted words.

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

Completeness3/5

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

For a read-only query tool with three parameters and no output schema, the description is adequate but incomplete. It covers the purpose and parameters indirectly, but lacks details on behavioral aspects like output format, error handling, or performance considerations. Given the absence of annotations and output schema, the description should do more to compensate, but it meets minimum viability for basic 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%, with all three parameters clearly documented in the input schema. The description adds minimal value beyond the schema by mentioning 'Loki datasource and time range,' which aligns with the parameters but doesn't provide additional syntax, format details, or usage context. This meets the baseline score of 3 when the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the action ('Lists all available label names') and the resource ('found in logs within a specified Loki datasource and time range'), using specific terminology. It distinguishes itself from sibling tools like 'list_loki_label_values' by focusing on label names rather than values, and from 'query_loki_logs' by returning metadata rather than log content.

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 for exploring label metadata in Loki logs within a time range, but provides no explicit guidance on when to use this tool versus alternatives like 'list_prometheus_label_names' or 'list_pyroscope_label_names' for other data sources. It also doesn't mention prerequisites or exclusions, leaving the agent to infer context from the tool name and description alone.

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