get_alert_rule_by_uid
Retrieve the complete configuration and detailed status of a Grafana alert rule using its unique identifier to inspect rule settings and current state.
Instructions
Retrieves the full configuration and detailed status of a specific Grafana alert rule
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | The uid of the alert rule |
Implementation Reference
- src/tools/alerting.ts:64-77 (handler)The main tool handler implementation, which creates a GrafanaClient and calls getAlertRuleByUid on it with the provided UID.export const getAlertRuleByUid: ToolDefinition = { name: 'get_alert_rule_by_uid', description: 'Retrieves the full configuration and detailed status of a specific Grafana alert rule', inputSchema: GetAlertRuleByUidSchema, handler: async (params, context: ToolContext) => { try { const client = new GrafanaClient(context.config.grafanaConfig); const rule = await client.getAlertRuleByUid(params.uid); return createToolResult(rule); } catch (error: any) { return createErrorResult(error.message); } }, };
- src/tools/alerting.ts:18-20 (schema)Zod schema defining the input parameters for the tool (uid: string).const GetAlertRuleByUidSchema = z.object({ uid: z.string().describe('The uid of the alert rule'), });
- src/tools/alerting.ts:113-117 (registration)Function that registers the alerting tools, including get_alert_rule_by_uid, 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 retrieve the alert rule by UID.async getAlertRuleByUid(uid: string): Promise<AlertRule> { try { const response = await this.client.get(`/api/v1/provisioning/alert-rules/${uid}`); return response.data; } catch (error) { this.handleError(error); } }