Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_prometheus_label_values

Retrieve available values for a specific Prometheus label, with options to filter by series selectors and time range for precise monitoring data analysis.

Instructions

Get the values for a specific label name in Prometheus. 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 query
labelNameYesThe name of the label to query
limitNoMaximum number of results
matchesNoSelectors to filter the results
startRfc3339NoThe start time of the query

Implementation Reference

  • The ToolDefinition object including the handler function that executes the logic for listing Prometheus label values using the PrometheusClient.
    export const listPrometheusLabelValues: ToolDefinition = {
      name: 'list_prometheus_label_values',
      description: 'Get the values for a specific label name in Prometheus. Allows filtering by series selectors and time range.',
      inputSchema: ListPrometheusLabelValuesSchema,
      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 values = await client.getLabelValues(
            params.labelName,
            match.length > 0 ? match : undefined,
            params.startRfc3339,
            params.endRfc3339
          );
          
          const limited = params.limit ? values.slice(0, params.limit) : values;
          
          return createToolResult(limited);
        } catch (error: any) {
          return createErrorResult(error.message);
        }
      },
    };
  • Zod schema defining the input parameters for the list_prometheus_label_values tool.
    const ListPrometheusLabelValuesSchema = z.object({
      datasourceUid: z.string().describe('The UID of the datasource to query'),
      labelName: z.string().describe('The name of the label 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('Selectors to filter the results'),
      startRfc3339: z.string().optional().describe('The start time of the query'),
      endRfc3339: z.string().optional().describe('The end time of the query'),
      limit: z.number().optional().describe('Maximum number of results'),
    });
  • Registration function for Prometheus tools, including the registration of listPrometheusLabelValues tool.
    export function registerPrometheusTools(server: any) {
      server.registerTool(queryPrometheus);
      server.registerTool(listPrometheusMetricNames);
      server.registerTool(listPrometheusLabelNames);
      server.registerTool(listPrometheusLabelValues);
      server.registerTool(listPrometheusMetricMetadata);
    }
  • Helper function used in the handler to build Prometheus label matchers/selectors from input filters.
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions filtering and time range capabilities, which adds some context beyond basic purpose. However, it lacks critical details such as whether this is a read-only operation, potential rate limits, authentication requirements, error handling, or the format of returned values. For a tool with 6 parameters and no annotations, this is a significant gap.

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 purpose and adds filtering context. There is no wasted verbiage or redundancy, making it easy to parse quickly. Every word earns its place by contributing to understanding the tool's functionality.

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 the complexity (6 parameters, nested objects in 'matches', no output schema, and no annotations), the description is insufficient. It doesn't explain the return format, error conditions, or behavioral nuances like pagination (implied by 'limit' parameter) or how filtering works in practice. For a tool with this level of complexity and no structured support, the description should provide more operational context.

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%, meaning all parameters are documented in the schema itself. The description adds marginal value by mentioning 'filtering by series selectors and time range,' which loosely corresponds to the 'matches', 'startRfc3339', and 'endRfc3339' parameters. However, it doesn't provide additional syntax, examples, or constraints beyond what the schema already specifies, so it meets the baseline for high schema coverage.

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: 'Get the values for a specific label name in Prometheus.' It specifies the verb ('Get'), resource ('values for a specific label name'), and domain ('Prometheus'). However, it doesn't explicitly differentiate from its sibling 'list_prometheus_label_names' or other Prometheus query tools, which prevents a perfect score.

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'), which suggests when this tool might be preferred over simpler queries. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'list_prometheus_label_names' or 'query_prometheus', nor does it mention prerequisites or exclusions.

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