Skip to main content
Glama
ntk148v

alertmanager-mcp-server

get_alert_groups

Retrieve alert groups from Alertmanager to monitor active, silenced, or inhibited alerts for system oversight.

Instructions

Get a list of alert groups

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
silencedNo
inhibitedNo
activeNo
countNo
offsetNo

Implementation Reference

  • The core handler function for the 'get_alert_groups' MCP tool. It validates pagination parameters, constructs query parameters based on filters (silenced, inhibited, active), fetches data from Alertmanager's /api/v2/alerts/groups endpoint using make_request helper, applies pagination using paginate_results, and returns the structured response. The @mcp.tool decorator registers it as a tool.
    @mcp.tool(description="Get a list of alert groups")
    async def get_alert_groups(silenced: Optional[bool] = None,
                               inhibited: Optional[bool] = None,
                               active: Optional[bool] = None,
                               count: int = DEFAULT_ALERT_GROUP_PAGE,
                               offset: int = 0):
        """Get a list of alert groups
    
        Params
        ------
        silenced
            If true, include silenced alerts.
        inhibited
            If true, include inhibited alerts.
        active
            If true, include active alerts.
        count
            Number of alert groups to return per page (default: 3, max: 5).
            Alert groups can be large as they contain all alerts within the group.
        offset
            Number of alert groups to skip before returning results (default: 0).
            To paginate through all results, make multiple calls with increasing
            offset values (e.g., offset=0, offset=3, offset=6, etc.).
    
        Returns
        -------
        dict
            A dictionary containing:
            - data: List of AlertGroup objects for the current page
            - pagination: Metadata about pagination (total, offset, count, has_more)
              Use the 'has_more' flag to determine if additional pages are available.
        """
        # Validate pagination parameters
        count, offset, error = validate_pagination_params(
            count, offset, MAX_ALERT_GROUP_PAGE)
        if error:
            return {"error": error}
    
        params = {"active": True}
        if silenced is not None:
            params["silenced"] = silenced
        if inhibited is not None:
            params["inhibited"] = inhibited
        if active is not None:
            params["active"] = active
    
        # Get all alert groups from the API
        all_groups = make_request(method="GET", route="/api/v2/alerts/groups",
                                  params=params)
    
        # Apply pagination and return results
        return paginate_results(all_groups, count, offset)
  • Helper function used by get_alert_groups to apply client-side pagination to the list of alert groups fetched from the API, generating metadata like total count, current offset, page size, and whether more results are available.
    def paginate_results(items: List[Any], count: int, offset: int) -> Dict[str, Any]:
        """Apply pagination to a list of items and generate pagination metadata.
    
        Parameters
        ----------
        items : List[Any]
            The full list of items to paginate
        count : int
            Number of items to return per page (must be >= 1)
        offset : int
            Number of items to skip (must be >= 0)
    
        Returns
        -------
        Dict[str, Any]
            A dictionary containing:
            - data: List of items for the current page
            - pagination: Metadata including total, offset, count, requested_count, and has_more
        """
        total = len(items)
        end_index = offset + count
        paginated_items = items[offset:end_index]
        has_more = end_index < total
    
        return {
            "data": paginated_items,
            "pagination": {
                "total": total,
                "offset": offset,
                "count": len(paginated_items),
                "requested_count": count,
                "has_more": has_more
            }
        }
  • Helper function used by get_alert_groups to validate the count and offset pagination parameters against configured limits (e.g., MAX_ALERT_GROUP_PAGE=5), returning an error message if invalid.
    def validate_pagination_params(count: int, offset: int, max_count: int) -> tuple[int, int, Optional[str]]:
        """Validate and normalize pagination parameters.
    
        Parameters
        ----------
        count : int
            Requested number of items per page
        offset : int
            Requested offset for pagination
        max_count : int
            Maximum allowed count value
    
        Returns
        -------
        tuple[int, int, Optional[str]]
            A tuple of (normalized_count, normalized_offset, error_message).
            If error_message is not None, the parameters are invalid and should
            return an error to the caller.
        """
        error = None
    
        # Validate count parameter
        if count < 1:
            error = f"Count parameter ({count}) must be at least 1."
        elif count > max_count:
            error = (
                f"Count parameter ({count}) exceeds maximum allowed value ({max_count}). "
                f"Please use count <= {max_count} and paginate through results using the offset parameter."
            )
    
        # Validate offset parameter
        if offset < 0:
            error = f"Offset parameter ({offset}) must be non-negative (>= 0)."
    
        return count, offset, error
  • Core helper function used by get_alert_groups to make authenticated HTTP requests to the Alertmanager API, handling basic auth, multi-tenant headers (X-Scope-OrgId), URL joining, error handling, and JSON parsing.
    def make_request(method="GET", route="/", **kwargs):
        """Make HTTP request and return a requests.Response object.
    
        Parameters
        ----------
        method : str
            HTTP method to use for the request.
        route : str
            (Default value = "/")
            This is the url we are making our request to.
        **kwargs : dict
            Arbitrary keyword arguments.
    
    
        Returns
        -------
        dict:
            The response from the Alertmanager API. This is a dictionary
            containing the response data.
        """
        try:
            route = url_join(config.url, route)
            auth = (
                requests.auth.HTTPBasicAuth(config.username, config.password)
                if config.username and config.password
                else None
            )
    
            # Add X-Scope-OrgId header for multi-tenant setups
            # Priority: 1) Request header from caller (via ContextVar), 2) Static config tenant
            headers = kwargs.get("headers", {})
    
            tenant_id = _current_scope_org_id.get() or config.tenant_id
    
            if tenant_id:
                headers["X-Scope-OrgId"] = tenant_id
            if headers:
                kwargs["headers"] = headers
    
            response = requests.request(
                method=method.upper(), url=route, auth=auth, timeout=60, **kwargs
            )
            response.raise_for_status()
            result = response.json()
    
            # Ensure we always return something (empty list is valid but might cause issues)
            if result is None:
                return {"message": "No data returned"}
            return result
        except requests.exceptions.RequestException as e:
            return {"error": str(e)}
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. 'Get a list' implies a read operation, but there's no mention of pagination behavior (despite count/offset parameters), rate limits, authentication requirements, or what constitutes an 'alert group' versus individual alerts. The description doesn't provide meaningful behavioral context beyond the basic read implication.

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

Conciseness5/5

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

The description is maximally concise - a single sentence with no wasted words. It's front-loaded with the core purpose and contains no unnecessary elaboration. While it may be too brief for adequate tool understanding, it achieves perfect conciseness within its limited scope.

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

Completeness2/5

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

For a tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description is severely inadequate. It doesn't explain what 'alert groups' are, how they differ from individual alerts, what the filtering parameters do, or what format the response takes. The description leaves critical gaps given the tool's complexity and lack of supporting documentation.

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

Parameters2/5

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

With 0% schema description coverage and 5 parameters, the description provides no information about any parameters. It doesn't explain what 'silenced', 'inhibited', 'active' filters mean, what 'count' and 'offset' control, or how these parameters affect the returned list. The description fails to compensate for the complete lack of schema documentation.

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

Purpose3/5

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

The description 'Get a list of alert groups' clearly states the verb ('Get') and resource ('alert groups'), making the basic purpose understandable. However, it doesn't distinguish this from sibling tools like 'get_alerts' or 'get_silences' - it's unclear what differentiates 'alert groups' from plain 'alerts' or 'silences'. The purpose is stated but lacks specificity about what makes this tool unique.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'get_alerts', 'get_silences', and 'get_silence', there's no indication of when an agent should choose 'get_alert_groups' over these other options. No context about appropriate use cases or exclusions is provided.

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

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