Skip to main content
Glama
comqx

Prometheus Alertmanager MCP Server

by comqx

get-alerts

Retrieve active, silenced, or inhibited alerts from Prometheus Alertmanager using customizable filters to monitor system notifications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNoFiltering query (e.g. alertname=~'.*CPU.*')
silencedNoInclude silenced alerts
inhibitedNoInclude inhibited alerts
activeNoInclude active alerts (default: true)

Implementation Reference

  • The handler function that executes the 'get-alerts' tool: builds query params based on inputs, fetches alerts from Alertmanager, formats them into a structured response, and handles errors.
    async ({ filter, silenced = false, inhibited = false, active = true }) => {
      try {
        // Build query parameters
        const params = new URLSearchParams();
        if (filter) params.append("filter", filter);
        if (silenced) params.append("silenced", "true");
        if (inhibited) params.append("inhibited", "true");
        if (!active) params.append("active", "false");
        
        // Fetch alerts
        const queryString = params.toString();
        const path = `alerts${queryString ? '?' + queryString : ''}`;
        const alerts = await fetchFromAlertmanager(path) as Alert[];
        
        // Format alerts
        const formattedAlerts = alerts.map((alert: Alert): FormattedAlert => ({
          fingerprint: alert.fingerprint,
          alertname: alert.labels.alertname,
          severity: alert.labels.severity || 'unknown',
          summary: alert.annotations.summary || 'No summary provided',
          description: alert.annotations.description || 'No description provided',
          startsAt: alert.startsAt,
          status: {
            state: alert.status.state,
            silenced: alert.status.silencedBy.length > 0,
            inhibited: alert.status.inhibitedBy.length > 0,
          },
          labels: alert.labels,
        }));
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(formattedAlerts, null, 2)
          }]
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [{
            type: "text",
            text: `Error fetching alerts: ${errorMessage}`
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining optional parameters for filtering and including different types of alerts.
    {
      filter: z.string().optional().describe("Filtering query (e.g. alertname=~'.*CPU.*')"),
      silenced: z.boolean().optional().describe("Include silenced alerts"),
      inhibited: z.boolean().optional().describe("Include inhibited alerts"),
      active: z.boolean().optional().describe("Include active alerts (default: true)"),
    },
  • src/index.ts:100-155 (registration)
    Registration of the 'get-alerts' tool on the MCP server using server.tool(), specifying name, input schema, and handler function.
    server.tool(
      "get-alerts",
      {
        filter: z.string().optional().describe("Filtering query (e.g. alertname=~'.*CPU.*')"),
        silenced: z.boolean().optional().describe("Include silenced alerts"),
        inhibited: z.boolean().optional().describe("Include inhibited alerts"),
        active: z.boolean().optional().describe("Include active alerts (default: true)"),
      },
      async ({ filter, silenced = false, inhibited = false, active = true }) => {
        try {
          // Build query parameters
          const params = new URLSearchParams();
          if (filter) params.append("filter", filter);
          if (silenced) params.append("silenced", "true");
          if (inhibited) params.append("inhibited", "true");
          if (!active) params.append("active", "false");
          
          // Fetch alerts
          const queryString = params.toString();
          const path = `alerts${queryString ? '?' + queryString : ''}`;
          const alerts = await fetchFromAlertmanager(path) as Alert[];
          
          // Format alerts
          const formattedAlerts = alerts.map((alert: Alert): FormattedAlert => ({
            fingerprint: alert.fingerprint,
            alertname: alert.labels.alertname,
            severity: alert.labels.severity || 'unknown',
            summary: alert.annotations.summary || 'No summary provided',
            description: alert.annotations.description || 'No description provided',
            startsAt: alert.startsAt,
            status: {
              state: alert.status.state,
              silenced: alert.status.silencedBy.length > 0,
              inhibited: alert.status.inhibitedBy.length > 0,
            },
            labels: alert.labels,
          }));
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(formattedAlerts, null, 2)
            }]
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{
              type: "text",
              text: `Error fetching alerts: ${errorMessage}`
            }],
            isError: true
          };
        }
      }
    );
  • Utility function for making API requests to Alertmanager with timeout handling and error management, used by the get-alerts handler.
    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;
      }
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

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

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