Skip to main content
Glama
amittell

firewalla-mcp-server

get_alarm_trends

Analyze historical alarm trends to identify patterns in daily security alerts from Firewalla firewall systems.

Instructions

Get historical alarm trend data (alarms generated per day)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupNoGet trends for a specific box group

Implementation Reference

  • The GetAlarmTrendsHandler class implements the core logic for the get_alarm_trends tool. It validates the optional 'period' parameter (1h, 24h, 7d, 30d), fetches alarm trends from Firewalla API via firewalla.getAlarmTrends(), processes the data with safe access patterns, normalizes timestamps, calculates summary statistics (total alarms, average, peak, frequency), and returns a unified response with execution metadata.
    export class GetAlarmTrendsHandler extends BaseToolHandler {
      name = 'get_alarm_trends';
      description =
        'Get historical alarm data trends over time with configurable periods. Optional period parameter. Data cached for 1 hour for performance.';
      category = 'analytics' as const;
    
      constructor() {
        super({
          enableGeoEnrichment: false, // No IP fields in alarm trends
          enableFieldNormalization: true,
          additionalMeta: {
            data_source: 'alarm_trends',
            entity_type: 'historical_alarm_data',
            supports_geographic_enrichment: false,
            supports_field_normalization: true,
            standardization_version: '2.0.0',
          },
        });
      }
    
      async execute(
        _args: ToolArgs,
        firewalla: FirewallaClient
      ): Promise<ToolResponse> {
        try {
          const periodValidation = ParameterValidator.validateEnum(
            _args?.period,
            'period',
            ['1h', '24h', '7d', '30d'],
            false,
            '24h'
          );
    
          if (!periodValidation.isValid) {
            return this.createErrorResponse(
              'Parameter validation failed',
              ErrorType.VALIDATION_ERROR,
              undefined,
              periodValidation.errors
            );
          }
    
          const period = periodValidation.sanitizedValue!;
    
          const trends = await withToolTimeout(
            async () =>
              firewalla.getAlarmTrends(period as '1h' | '24h' | '7d' | '30d'),
            this.name
          );
    
          // Defensive programming: validate trends response structure
          if (
            !trends ||
            !SafeAccess.getNestedValue(trends, 'results') ||
            !Array.isArray(trends.results)
          ) {
            return this.createSuccessResponse({
              period,
              data_points: 0,
              trends: [],
              summary: {
                total_alarms: 0,
                avg_alarms_per_interval: 0,
                peak_alarm_count: 0,
                intervals_with_alarms: 0,
                alarm_frequency: 0,
              },
              error: 'Invalid alarm trends data received',
            });
          }
    
          // Validate individual trend entries
          const validTrends = SafeAccess.safeArrayFilter(
            trends.results,
            (trend: any) =>
              trend &&
              typeof SafeAccess.getNestedValue(trend, 'ts') === 'number' &&
              typeof SafeAccess.getNestedValue(trend, 'value') === 'number' &&
              (SafeAccess.getNestedValue(trend, 'ts', 0) as number) > 0 &&
              (SafeAccess.getNestedValue(trend, 'value', 0) as number) >= 0
          );
    
          const startTime = Date.now();
    
          const unifiedResponseData = {
            period,
            data_points: validTrends.length,
            trends: SafeAccess.safeArrayMap(validTrends, (trend: any) => ({
              timestamp: SafeAccess.getNestedValue(trend, 'ts', 0),
              timestamp_iso: unixToISOString(
                SafeAccess.getNestedValue(trend, 'ts', 0) as number
              ),
              alarm_count: SafeAccess.getNestedValue(trend, 'value', 0),
            })),
            summary: {
              total_alarms: validTrends.reduce(
                (sum: number, t: any) =>
                  sum + (SafeAccess.getNestedValue(t, 'value', 0) as number),
                0
              ),
              avg_alarms_per_interval:
                validTrends.length > 0
                  ? Math.round(
                      (validTrends.reduce(
                        (sum: number, t: any) =>
                          sum +
                          (SafeAccess.getNestedValue(t, 'value', 0) as number),
                        0
                      ) /
                        validTrends.length) *
                        100
                    ) / 100
                  : 0,
              // Performance Buffer Strategy: Same defensive slicing as flow trends
              // to prevent call stack overflow with large alarm trend datasets
              peak_alarm_count:
                validTrends.length > 0
                  ? Math.max(
                      ...validTrends
                        .slice(0, 1000) // Defensive limit to prevent call stack overflow
                        .map(
                          (t: any) =>
                            SafeAccess.getNestedValue(t, 'value', 0) as number
                        )
                    )
                  : 0,
              intervals_with_alarms: SafeAccess.safeArrayFilter(
                validTrends,
                (t: any) => (SafeAccess.getNestedValue(t, 'value', 0) as number) > 0
              ).length,
              alarm_frequency:
                validTrends.length > 0
                  ? Math.round(
                      (SafeAccess.safeArrayFilter(
                        validTrends,
                        (t: any) =>
                          (SafeAccess.getNestedValue(t, 'value', 0) as number) > 0
                      ).length /
                        validTrends.length) *
                        100
                    )
                  : 0,
            },
          };
    
          const executionTime = Date.now() - startTime;
          return this.createUnifiedResponse(unifiedResponseData, {
            executionTimeMs: executionTime,
          });
        } catch (error: unknown) {
          const errorMessage =
            error instanceof Error ? error.message : 'Unknown error occurred';
          return this.createErrorResponse(
            `Failed to get alarm trends: ${errorMessage}`,
            ErrorType.API_ERROR
          );
        }
      }
    }
  • Registration of the GetAlarmTrendsHandler in the ToolRegistry constructor, adding the tool to the central registry used by the MCP server.
    this.register(new GetAlarmTrendsHandler());
  • MCP tool schema definition for get_alarm_trends in the server's listTools response handler, specifying the tool name, description, and input schema with optional 'group' parameter.
      name: 'get_alarm_trends',
      description:
        'Get historical alarm trend data (alarms generated per day)',
      inputSchema: {
        type: 'object',
        properties: {
          group: {
            type: 'string',
            description: 'Get trends for a specific box group',
          },
        },
        required: [],
      },
    },
  • Import statement for GetAlarmTrendsHandler from the analytics handlers module, prerequisite for registration.
      GetAlarmTrendsHandler,
      GetRuleTrendsHandler,
    } from './handlers/analytics.js';
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'historical' data and 'per day' aggregation, which adds some context, but fails to detail critical aspects like whether the data is read-only, if authentication is required, rate limits, or the format of returned data. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 extremely concise and front-loaded, consisting of a single, clear sentence: 'Get historical alarm trend data (alarms generated per day)'. Every word contributes directly to understanding the tool's function, with no wasted information or redundancy, making it highly efficient for an AI agent.

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

Completeness3/5

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

Given the tool's moderate complexity (historical data retrieval with one optional parameter), no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and data type but lacks details on behavior, usage context, and output format. This leaves the agent with incomplete information, though the core function is clear.

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?

The input schema has 100% description coverage, with one optional parameter 'group' documented as 'Get trends for a specific box group'. The description does not add any meaning beyond this, such as explaining what 'box group' entails or providing examples. Since schema coverage is high, the baseline score of 3 is appropriate, as the schema adequately handles parameter documentation.

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

Purpose4/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: 'Get historical alarm trend data (alarms generated per day)'. It specifies the verb ('Get'), resource ('alarm trend data'), and scope ('historical', 'per day'), making the function unambiguous. However, it does not explicitly differentiate from sibling tools like 'get_rule_trends' or 'get_active_alarms', which prevents a perfect score.

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. It does not mention sibling tools such as 'get_active_alarms' for current alarms or 'search_alarms' for filtered searches, nor does it specify prerequisites or exclusions. This lack of contextual usage information limits its helpfulness for an AI agent.

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/amittell/firewalla-mcp-server'

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