Skip to main content
Glama
panther-labs

Panther MCP Server

Official

get_rule_alert_metrics

Read-only

Analyze alert metrics by detection rule to identify patterns and hotspots across alerts, detection errors, and system errors within a specified time period.

Instructions

Gets alert metrics grouped by detection rule for ALL alert types, including alerts, detection errors, and system errors within a given time period. Use this tool to identify hot spots in alerts and use list_alerts for specific alert details.

Returns: Dict: - alerts_per_rule: List of series with entityId, label, and value - total_alerts: Total number of alerts in the period - start_date: Start date of the period - end_date: End date of the period - interval_in_minutes: Grouping interval for the metrics - rule_ids: List of rule IDs if provided

Permissions:{'all_of': ['Read Panther Metrics']}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoOptional start date in ISO-8601 format. If provided, defaults to the start of the current day UTC.
end_dateNoOptional end date in ISO-8601 format. If provided, defaults to the end of the current day UTC.
interval_in_minutesNoIntervals for aggregating data points. Smaller intervals provide more granular detail of when events occurred, while larger intervals show broader trends but obscure the precise timing of incidents.
rule_idsNoA valid JSON list of Panther rule IDs to get metrics for

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function for get_rule_alert_metrics tool. Executes GraphQL query for metrics, handles date ranges, filters by rule_ids, and returns formatted results. Includes input schema definitions and @mcp_tool decorator for registration.
    @mcp_tool(
        annotations={
            "permissions": all_perms(Permission.SUMMARY_READ),
            "readOnlyHint": True,
        }
    )
    async def get_rule_alert_metrics(
        start_date: Annotated[
            str | None,
            Field(
                description="Optional start date in ISO-8601 format. If provided, defaults to the start of the current day UTC.",
                examples=["2024-03-20T00:00:00Z"],
            ),
        ] = None,
        end_date: Annotated[
            str | None,
            Field(
                description="Optional end date in ISO-8601 format. If provided, defaults to the end of the current day UTC.",
                examples=["2024-03-20T00:00:00Z"],
            ),
        ] = None,
        interval_in_minutes: Annotated[
            int,
            BeforeValidator(_validate_interval),
            Field(
                description="Intervals for aggregating data points. Smaller intervals provide more granular detail of when events occurred, while larger intervals show broader trends but obscure the precise timing of incidents.",
                examples=[15, 30, 60, 180, 360, 720, 1440],
            ),
        ] = 15,
        rule_ids: Annotated[
            list[str],
            BeforeValidator(_validate_rule_ids),
            Field(
                description="A valid JSON list of Panther rule IDs to get metrics for",
                examples=[["AppOmni.Alert.Passthrough", "Auth0.MFA.Policy.Disabled"]],
            ),
        ] = [],
    ) -> dict[str, Any]:
        """Gets alert metrics grouped by detection rule for ALL alert types, including alerts, detection errors, and system errors within a given time period. Use this tool to identify hot spots in alerts and use list_alerts for specific alert details.
    
        Returns:
            Dict:
            - alerts_per_rule: List of series with entityId, label, and value
            - total_alerts: Total number of alerts in the period
            - start_date: Start date of the period
            - end_date: End date of the period
            - interval_in_minutes: Grouping interval for the metrics
            - rule_ids: List of rule IDs if provided
        """
        try:
            # If start or end date is missing, use week's date range
            if not start_date or not end_date:
                default_start_date, default_end_date = _get_week_date_range()
                if not start_date:
                    start_date = default_start_date
                if not end_date:
                    end_date = default_end_date
    
            logger.info(f"Fetching alerts per rule metrics from {start_date} to {end_date}")
    
            # Prepare variables
            variables = {
                "input": {
                    "fromDate": start_date,
                    "toDate": end_date,
                    "intervalInMinutes": interval_in_minutes,
                }
            }
    
            # Execute query
            result = await _execute_query(METRICS_ALERTS_PER_RULE_QUERY, variables)
    
            if not result or "metrics" not in result:
                logger.error(f"Could not find key 'metrics' in result: {result}")
                raise Exception("Failed to fetch metrics data")
    
            metrics_data = result["metrics"]
    
            # Filter by rule IDs if provided
            if rule_ids:
                alerts_per_rule = [
                    item
                    for item in metrics_data["alertsPerRule"]
                    if item["entityId"] in rule_ids
                ]
            else:
                alerts_per_rule = metrics_data["alertsPerRule"]
    
            return {
                "success": True,
                "alerts_per_rule": alerts_per_rule,
                "total_alerts": len(alerts_per_rule),
                "start_date": start_date,
                "end_date": end_date,
                "interval_in_minutes": interval_in_minutes,
                "rule_ids": rule_ids if rule_ids else None,
            }
    
        except Exception as e:
            logger.error(f"Failed to fetch rule alert metrics: {str(e)}")
            return {
                "success": False,
                "message": f"Failed to fetch rule alert metrics: {str(e)}",
            }
  • Registration of all MCP tools (including get_rule_alert_metrics) to the FastMCP server instance via register_all_tools(mcp).
    # Create the MCP server with lifespan context for shared HTTP client management
    # Note: Dependencies are declared in fastmcp.json for FastMCP v2.14.0+
    mcp = FastMCP(MCP_SERVER_NAME, lifespan=lifespan)
    
    # Register all tools with MCP using the registry
    register_all_tools(mcp)
    # Register all prompts with MCP using the registry
    register_all_prompts(mcp)
    # Register all resources with MCP using the registry
    register_all_resources(mcp)
  • GraphQL query definition used by the get_rule_alert_metrics handler to fetch alerts per rule metrics.
    METRICS_ALERTS_PER_RULE_QUERY = gql("""
    query Metrics($input: MetricsInput!) {
        metrics(input: $input) {
            alertsPerRule {
                entityId
                label
                value
            }
            totalAlerts
        }
    }
    """)
  • Pydantic validator for rule_ids parameter used in the tool's input schema.
    def _validate_rule_ids(v: list[str]) -> list[str]:
        """Validate rule IDs don't contain problematic characters."""
        problematic_chars = re.compile(r"[@\s#]")
        for rule_id in v:
            if problematic_chars.search(rule_id):
                raise ValueError(
                    f"Invalid rule ID '{rule_id}'. Rule IDs cannot contain '@', spaces, or '#' characters"
                )
        return v
Behavior4/5

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

The annotations already declare readOnlyHint=true, indicating this is a safe read operation. The description adds valuable context beyond annotations by specifying the scope ('for ALL alert types'), mentioning the permission requirement ('Permissions:{"all_of": ["Read Panther Metrics"]}'), and describing the grouping behavior ('grouped by detection rule'). It doesn't contradict annotations and provides useful operational context.

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

Conciseness4/5

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

The description is well-structured with purpose first, usage guidance second, and return format third. The permission information is appended but relevant. While efficient, the return format section could be more concise since an output schema exists, making some of that detail redundant.

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

Completeness5/5

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

Given the tool's complexity (aggregated metrics with time grouping), the description provides complete context. It covers purpose, differentiation from siblings, permission requirements, and behavioral scope. With both annotations (readOnlyHint) and an output schema present, the description appropriately focuses on operational context rather than repeating structured information.

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

Parameters3/5

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

With 100% schema description coverage, the input schema already fully documents all 4 parameters with clear descriptions and examples. The description doesn't add any parameter-specific information beyond what's in the schema, but it does provide context about the time period grouping. This meets the baseline expectation when schema coverage is complete.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('Gets alert metrics grouped by detection rule') and resources ('for ALL alert types, including alerts, detection errors, and system errors within a given time period'). It explicitly distinguishes from the sibling tool 'list_alerts' by specifying this is for aggregated metrics rather than specific alert details.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('Use this tool to identify hot spots in alerts') versus alternatives ('use list_alerts for specific alert details'). It clearly differentiates this aggregated metrics tool from the detailed listing sibling tool, giving the agent clear decision criteria.

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/panther-labs/mcp-panther'

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