Skip to main content
Glama
comqx

Prometheus Alertmanager MCP Server

by comqx

get-alert-groups

Retrieve and filter alert groups from Prometheus Alertmanager to monitor active, silenced, and inhibited alerts for system monitoring and incident management.

Input Schema

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

Implementation Reference

  • The main handler function for the 'get-alert-groups' tool. It constructs query parameters based on input options, fetches alert groups from the Alertmanager API endpoint '/api/v2/alerts/groups', and returns the JSON-formatted response or an error message.
    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 input schema defining optional boolean parameters for filtering alert groups by active, silenced, and inhibited status.
    { 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)
    Registration of the 'get-alert-groups' tool using server.tool(), including the tool 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 }; } } );
  • Helper function used by the tool to make HTTP requests to the Alertmanager API with timeout handling and error management.
    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