Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_prometheus_label_names

Retrieve label names from Prometheus datasources with filtering by series selectors and time range to identify available metrics and dimensions for monitoring queries.

Instructions

List label names in a Prometheus datasource. Allows filtering by series selectors and time range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasourceUidYesThe UID of the datasource to query
endRfc3339NoThe end time of the time range
limitNoMaximum number of results
matchesNoLabel matchers to filter the results
startRfc3339NoThe start time of the time range

Implementation Reference

  • The asynchronous handler function that implements the core logic of the 'list_prometheus_label_names' tool. It creates a PrometheusClient, builds match selectors, queries for label names with optional time range and limit, and returns the result or error.
    handler: async (params, context: ToolContext) => {
      try {
        const client = new PrometheusClient(context.config.grafanaConfig, params.datasourceUid);
        
        const match = params.matches?.map((m: any) => buildSelector(m.filters)) || [];
        const labels = await client.getLabelNames(
          match.length > 0 ? match : undefined,
          params.startRfc3339,
          params.endRfc3339
        );
        
        const limited = params.limit ? labels.slice(0, params.limit) : labels;
        
        return createToolResult(limited);
      } catch (error: any) {
        return createErrorResult(error.message);
      }
    },
  • Zod schema defining the input parameters for the 'list_prometheus_label_names' tool, including datasource UID, optional match filters, time range, and limit.
    const ListPrometheusLabelNamesSchema = z.object({
      datasourceUid: z.string().describe('The UID of the datasource to query'),
      matches: z.array(z.object({
        filters: z.array(z.object({
          name: z.string().describe('The name of the label to match against'),
          value: z.string().describe('The value to match against'),
          type: z.enum(['=', '!=', '=~', '!~']).describe('The match operator'),
        })),
      })).optional().describe('Label matchers to filter the results'),
      startRfc3339: z.string().optional().describe('The start time of the time range'),
      endRfc3339: z.string().optional().describe('The end time of the time range'),
      limit: z.number().optional().describe('Maximum number of results'),
    });
  • Function that registers the 'list_prometheus_label_names' tool (and other Prometheus tools) with the MCP server.
    export function registerPrometheusTools(server: any) {
      server.registerTool(queryPrometheus);
      server.registerTool(listPrometheusMetricNames);
      server.registerTool(listPrometheusLabelNames);
      server.registerTool(listPrometheusLabelValues);
      server.registerTool(listPrometheusMetricMetadata);
    }
  • Utility function to construct Prometheus label matchers string from filter objects, used by the label names handler to build query selectors.
    function buildSelector(filters: any[]): string {
      if (!filters || filters.length === 0) return '{}';
      
      const parts = filters.map(f => {
        switch (f.type) {
          case '=': return `${f.name}="${f.value}"`;
          case '!=': return `${f.name}!="${f.value}"`;
          case '=~': return `${f.name}=~"${f.value}"`;
          case '!~': return `${f.name}!~"${f.value}"`;
          default: return '';
        }
      }).filter(p => p);
      
      return `{${parts.join(',')}}`;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the tool's filtering capabilities, it doesn't describe important behavioral aspects like whether this is a read-only operation, what permissions are required, whether results are paginated, potential rate limits, or what format the results take. For a query tool with 5 parameters and no annotations, this leaves significant gaps in understanding how the tool behaves.

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 perfectly concise at two sentences with zero wasted words. The first sentence establishes the core purpose, and the second sentence adds the key capability (filtering). Every word earns its place, and the information is front-loaded with the most important details first.

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?

Given the tool's moderate complexity (5 parameters, nested filtering logic), no annotations, and no output schema, the description is minimally adequate but incomplete. It covers the basic purpose and filtering capabilities but doesn't address important contextual information like what the output looks like, error conditions, performance characteristics, or how this tool fits into broader Prometheus query workflows. The 100% schema coverage helps, but for a query tool with no output schema, more guidance on results would be beneficial.

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?

The schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema by mentioning filtering by 'series selectors' (which corresponds to the 'matches' parameter) and 'time range' (which corresponds to 'startRfc3339' and 'endRfc3339'). However, it doesn't provide additional context about parameter interactions, default behaviors, or practical usage examples that would help an agent understand how to use these parameters effectively together.

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 action ('List label names') and resource ('in a Prometheus datasource'), making the purpose immediately understandable. It distinguishes from sibling tools like 'list_prometheus_label_values' and 'list_prometheus_metric_names' by focusing specifically on label names. However, it doesn't explicitly differentiate from 'list_loki_label_names' or 'list_pyroscope_label_names' which serve similar functions for different data sources.

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 mentioning filtering capabilities ('Allows filtering by series selectors and time range'), suggesting when this tool might be preferred over simpler listing tools. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'list_prometheus_label_values' or 'list_prometheus_metric_names', nor does it mention any prerequisites or exclusions for usage.

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