Skip to main content
Glama
comqx

Prometheus Alertmanager MCP Server

by comqx

get-alert-groups

Retrieve and filter alert groups from Prometheus Alertmanager based on active, silenced, or inhibited status to monitor system notifications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activeNoInclude active alerts (default: true)
silencedNoInclude silenced alerts
inhibitedNoInclude inhibited alerts

Implementation Reference

  • 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 }; } }
  • 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 }; } } );
  • 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; } }

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/comqx/alertmanager-mcp'

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