Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_alert_rules

Retrieve and filter Grafana alert rules by labels to monitor their current state, UID, title, and labels for effective alert management.

Instructions

Lists Grafana alert rules, returning a summary including UID, title, current state, and labels

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
label_selectorsNoLabel matchers to filter alert rules
limitNoMaximum number of results to return
pageNoPage number to return

Implementation Reference

  • The main handler function for the 'list_alert_rules' tool. It constructs filters from input params, calls GrafanaClient.listAlertRules, formats the rules into a summary (uid, title, state, labels, folder), and returns the result or error.
    handler: async (params, context: ToolContext) => {
      try {
        const client = new GrafanaClient(context.config.grafanaConfig);
        
        // Build filters object for API
        const filters: any = {};
        if (params.label_selectors) {
          // Convert label selectors to query params
          // Note: Real implementation would need proper label selector formatting
          filters.labels = params.label_selectors;
        }
        if (params.limit) filters.limit = params.limit;
        if (params.page) filters.page = params.page;
        
        const rules = await client.listAlertRules(filters);
        
        // Format the response
        const formatted = rules.map((rule: any) => ({
          uid: rule.uid,
          title: rule.title,
          state: rule.state || 'inactive',
          labels: rule.labels || {},
          folder: rule.folderUID,
        }));
        
        return createToolResult(formatted);
      } catch (error: any) {
        return createErrorResult(error.message);
      }
  • Zod schema defining the input parameters for the list_alert_rules tool: optional label_selectors, limit, and page.
    const ListAlertRulesSchema = z.object({
      label_selectors: 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 alert rules'),
      limit: z.number().optional().describe('Maximum number of results to return'),
      page: z.number().optional().describe('Page number to return'),
    });
  • Registration function that registers the list_alert_rules tool (along with related tools) to the MCP server.
    export function registerAlertingTools(server: any) {
      server.registerTool(listAlertRules);
      server.registerTool(getAlertRuleByUid);
      server.registerTool(listContactPoints);
    }
  • Helper method in GrafanaClient that performs the actual API call to list alert rules from Grafana's provisioning endpoint, used by the tool handler.
    async listAlertRules(filters?: any): Promise<AlertRule[]> {
      try {
        const response = await this.client.get('/api/v1/provisioning/alert-rules', {
          params: filters,
        });
        return response.data;
      } catch (error) {
        this.handleError(error);
      }
    }
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. It states the tool returns a summary with specific fields (UID, title, current state, labels), which is helpful, but doesn't cover critical aspects like pagination behavior (implied by 'limit' and 'page' parameters but not explained), rate limits, authentication requirements, error conditions, or whether it's read-only (though 'Lists' implies it).

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 includes key return details. Every word earns its place with no redundancy or wasted verbiage, making it easy to parse quickly.

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 list tool with no annotations and no output schema, the description is minimally adequate. It specifies the resource and return fields, but lacks details on pagination, filtering behavior, or error handling. Given the 3 parameters and absence of structured behavioral hints, it should provide more context to be fully helpful.

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 description adds no parameter-specific information beyond what's in the schema, which has 100% coverage with clear descriptions for 'label_selectors', 'limit', and 'page'. The baseline is 3 since the schema does the heavy lifting, but the description doesn't compensate with additional context like example usage or parameter interactions.

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: 'Lists Grafana alert rules' with a specific verb ('Lists') and resource ('Grafana alert rules'). It distinguishes from some siblings like 'get_alert_rule_by_uid' by indicating it returns multiple rules, but doesn't explicitly differentiate from other list tools like 'list_incidents' or 'list_contact_points' beyond the resource type.

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 sibling tools like 'get_alert_rule_by_uid' for retrieving a single rule, or other list tools for different resources. There's no context about prerequisites, typical use cases, 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