get-alert-groups
Retrieve and filter alert groups from Prometheus Alertmanager based on active, silenced, or inhibited status to monitor system notifications.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-alert-groups"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | Include active alerts (default: true) | |
| silenced | No | Include silenced alerts | |
| inhibited | No | Include inhibited alerts |
Implementation Reference
- src/index.ts:357-386 (handler)The handler function that executes the get-alert-groups tool. It constructs query parameters based on input options (active, silenced, inhibited), fetches alert groups from the Alertmanager API endpoint `/api/v2/alerts/groups`, formats the response as JSON text, and handles errors appropriately.
async ({ active = true, silenced = false, inhibited = false }) => { try { // Build query parameters const params = new URLSearchParams(); if (!active) params.append("active", "false"); if (silenced) params.append("silenced", "true"); if (inhibited) params.append("inhibited", "true"); // Fetch alert groups const queryString = params.toString(); const path = `alerts/groups${queryString ? '?' + queryString : ''}`; const groups = await fetchFromAlertmanager(path); return { content: [{ type: "text", text: JSON.stringify(groups, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error fetching alert groups: ${errorMessage}` }], isError: true }; } } - src/index.ts:352-356 (schema)Zod schema defining the input parameters for the get-alert-groups tool: optional booleans for filtering active, silenced, and inhibited alerts.
{ active: z.boolean().optional().describe("Include active alerts (default: true)"), silenced: z.boolean().optional().describe("Include silenced alerts"), inhibited: z.boolean().optional().describe("Include inhibited alerts"), }, - src/index.ts:350-387 (registration)The registration of the get-alert-groups tool using McpServer's tool() method, specifying the name, input schema, and handler function.
server.tool( "get-alert-groups", { active: z.boolean().optional().describe("Include active alerts (default: true)"), silenced: z.boolean().optional().describe("Include silenced alerts"), inhibited: z.boolean().optional().describe("Include inhibited alerts"), }, async ({ active = true, silenced = false, inhibited = false }) => { try { // Build query parameters const params = new URLSearchParams(); if (!active) params.append("active", "false"); if (silenced) params.append("silenced", "true"); if (inhibited) params.append("inhibited", "true"); // Fetch alert groups const queryString = params.toString(); const path = `alerts/groups${queryString ? '?' + queryString : ''}`; const groups = await fetchFromAlertmanager(path); return { content: [{ type: "text", text: JSON.stringify(groups, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error fetching alert groups: ${errorMessage}` }], isError: true }; } } ); - src/index.ts:16-41 (helper)Shared helper function used by get-alert-groups (and other tools) to make HTTP requests to the Alertmanager API with timeout handling, error management, and JSON response parsing.
async function fetchFromAlertmanager(path: string, options: RequestInit = {}): Promise<any> { const baseUrl = process.env.ALERTMANAGER_URL || DEFAULT_ALERTMANAGER_URL; const url = `${baseUrl}/api/v2/${path}`; try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT); const response = await fetch(url, { ...options, signal: controller.signal }); clearTimeout(timeoutId); if (!response.ok) { throw new Error(`Alertmanager API error: ${response.status} ${response.statusText}`); } return await response.json(); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error fetching from Alertmanager: ${errorMessage}`); throw error; } }