Skip to main content
Glama
DrDroidLab

Grafana MCP Server

grafana_fetch_label_values

Retrieve available label values for dashboard variables from Prometheus data sources. Use this tool to fetch values for specific labels like 'instance' or 'job' to populate dynamic dashboard filters.

Instructions

Fetches label values for dashboard variables from Prometheus datasource. Retrieves available values for specific labels (e.g., 'instance', 'job').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasource_uidYesPrometheus datasource UID
label_nameYesLabel name to fetch values for (e.g., 'instance', 'job')
metric_match_filterNoOptional metric name filter (e.g., 'up', 'node_cpu_seconds_total')

Implementation Reference

  • The handler function grafana_fetch_label_values that orchestrates fetching label values using the grafana_processor.
    def grafana_fetch_label_values(datasource_uid, label_name, metric_match_filter=None):
        """Fetch label values for dashboard variables from Prometheus datasource"""
        try:
            grafana_processor = current_app.config.get("grafana_processor")
            if not grafana_processor:
                return {
                    "status": "error",
                    "message": "Grafana processor not initialized. Check configuration.",
                }
    
            result = grafana_processor.grafana_fetch_dashboard_variable_label_values(datasource_uid, label_name, metric_match_filter)
            return result
        except Exception as e:
            logger.error(f"Error fetching label values: {e!s}")
            return {"status": "error", "message": f"Failed to fetch label values: {e!s}"}
  • Registration of the grafana_fetch_label_values tool in the MCP server definition.
    "name": "grafana_fetch_label_values",
    "description": "Fetches label values for dashboard variables from Prometheus datasource. "
    "Retrieves available values for specific labels (e.g., 'instance', 'job').",
    "inputSchema": {
        "type": "object",
        "properties": {
            "datasource_uid": {
                "type": "string",
                "description": "Prometheus datasource UID",
            },
            "label_name": {
                "type": "string",
                "description": "Label name to fetch values for (e.g., 'instance', 'job')",
            },
            "metric_match_filter": {
                "type": "string",
                "description": "Optional metric name filter (e.g., 'up', 'node_cpu_seconds_total')",
            },
        },
        "required": ["datasource_uid", "label_name"],

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/DrDroidLab/grafana-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server