Skip to main content
Glama
DrDroidLab

Grafana MCP Server

grafana_fetch_dashboard_variables

Retrieve dashboard template variables and their current values from Grafana to enable dynamic data filtering and visualization.

Instructions

Fetches all variables and their values from a Grafana dashboard. Retrieves dashboard template variables and their current values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dashboard_uidYesDashboard UID

Implementation Reference

  • The actual logic that calls the Grafana API to fetch dashboard variables.
    def grafana_fetch_dashboard_variables(self, dashboard_uid: str) -> dict[str, Any]:
        """
        Fetches all variables and their values from a Grafana dashboard.
    
        Args:
            dashboard_uid: Dashboard UID
    
        Returns:
            Dict containing dashboard variables and their values
        """
        try:
            url = f"{self.__host}/api/dashboards/uid/{dashboard_uid}"
            logger.info(f"Fetching dashboard variables for UID: {dashboard_uid}")
    
            response = requests.get(url, headers=self.headers, verify=self.__ssl_verify, timeout=20)
    
            if response.status_code == 200:
                dashboard_data = response.json()
                dashboard = dashboard_data.get("dashboard", {})
                templating = dashboard.get("templating", {})
                variables = templating.get("list", [])
    
                # Extract variable information
                variable_details = []
                for var in variables:
                    variable_details.append(
                        {
                            "name": var.get("name"),
                            "type": var.get("type"),
                            "current_value": var.get("current", {}).get("value"),
                            "options": var.get("options", []),
                            "query": var.get("query"),
                            "definition": var.get("definition"),
                        }
                    )
    
                return {
                    "status": "success",
                    "dashboard_uid": dashboard_uid,
                    "variables": variable_details,
                }
  • The wrapper function in the MCP server that invokes the Grafana processor.
    def grafana_fetch_dashboard_variables(dashboard_uid):
        """Fetch all variables and their values from a Grafana dashboard"""
        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_variables(dashboard_uid)
            return result
        except Exception as e:
            logger.error(f"Error fetching dashboard variables: {e!s}")
            return {
                "status": "error",
                "message": f"Failed to fetch dashboard variables: {e!s}",
            }
  • Registration of the tool in the server's function mapping.
    "grafana_fetch_dashboard_variables": grafana_fetch_dashboard_variables,
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behavioral aspects: whether this requires authentication, what format the variables are returned in, if there are rate limits, whether it's a read-only operation, or how errors are handled. The description is minimal and lacks operational context.

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 extremely concise with two sentences that directly state the tool's purpose. Every word serves a clear function - the first sentence establishes the core functionality, and the second clarifies the type of variables retrieved. There's no wasted language or unnecessary elaboration.

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?

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the return value looks like (structure of variables/values), authentication requirements, error conditions, or practical use cases. The agent would need to guess about the output format and operational constraints, which is problematic for a tool that presumably returns structured data.

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 the single parameter 'dashboard_uid' documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema - it doesn't explain what a dashboard UID is, where to find it, or provide examples. However, with complete schema coverage, the baseline is 3 even without additional param details in the description.

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 verb 'fetches' and the resource 'variables and their values from a Grafana dashboard', with additional clarification about 'template variables and their current values'. It distinguishes itself from siblings like grafana_fetch_all_dashboards or grafana_query_dashboard_panels by focusing specifically on dashboard variables. However, it doesn't explicitly contrast with grafana_get_dashboard_config, which might also retrieve variable information.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when you'd fetch variables versus fetching the entire dashboard configuration (grafana_get_dashboard_config) or querying panels (grafana_query_dashboard_panels). There's no context about prerequisites, timing, or use cases for accessing variables separately.

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

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