Skip to main content
Glama
amittell

firewalla-mcp-server

get_statistics_by_box

Retrieve statistics for Firewalla boxes, identifying top performers by blocked flows or security alarms to monitor network security effectiveness.

Instructions

Get statistics for each Firewalla box (top boxes by blocked flows or security alarms)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeNoStatistics type to retrievetopBoxesByBlockedFlows
groupNoGet statistics for specific box group
limitNoMaximum number of results (optional, default: 5)

Implementation Reference

  • The primary handler class GetStatisticsByBoxHandler that implements the core logic for the 'get_statistics_by_box' tool. It extends BaseToolHandler, defines the tool name and description, and in the execute method calls firewalla.getStatisticsByBox() to fetch data, processes box statistics with validation, calculates summaries, and returns a unified response.
    export class GetStatisticsByBoxHandler extends BaseToolHandler {
      name = 'get_statistics_by_box';
      description =
        'Get statistics for each Firewalla box with activity scores and health monitoring. No required parameters. Data cached for 1 hour for performance.';
      category = 'analytics' as const;
    
      constructor() {
        super({
          enableGeoEnrichment: false, // No IP fields in box statistics
          enableFieldNormalization: true,
          additionalMeta: {
            data_source: 'box_statistics',
            entity_type: 'firewalla_box_statistics',
            supports_geographic_enrichment: false,
            supports_field_normalization: true,
            standardization_version: '2.0.0',
          },
        });
      }
    
      async execute(
        _args: ToolArgs,
        firewalla: FirewallaClient
      ): Promise<ToolResponse> {
        try {
          const stats = await withToolTimeout(
            async () => firewalla.getStatisticsByBox(),
            this.name
          );
    
          // Validate stats response structure
          if (!stats || typeof stats !== 'object') {
            throw new Error('Invalid stats response: not an object');
          }
    
          if (
            !SafeAccess.getNestedValue(stats, 'results') ||
            !Array.isArray(stats.results)
          ) {
            throw new Error('Invalid stats response: results is not an array');
          }
    
          // Process and validate each box statistic
          const boxStatistics = SafeAccess.safeArrayMap(
            stats.results,
            (stat: any) => {
              const boxMeta = SafeAccess.getNestedValue(stat, 'meta', {}) as any;
              return {
                box_id: SafeAccess.getNestedValue(
                  boxMeta,
                  'gid',
                  'unknown'
                ) as string,
                name: SafeAccess.getNestedValue(
                  boxMeta,
                  'name',
                  'Unknown Box'
                ) as string,
                model: SafeAccess.getNestedValue(
                  boxMeta,
                  'model',
                  'unknown'
                ) as string,
                status: (SafeAccess.getNestedValue(
                  boxMeta,
                  'online',
                  false
                ) as boolean)
                  ? 'online'
                  : 'offline',
                version: SafeAccess.getNestedValue(
                  boxMeta,
                  'version',
                  'unknown'
                ) as string,
                location: SafeAccess.getNestedValue(
                  boxMeta,
                  'location',
                  'unknown'
                ) as string,
                device_count: SafeAccess.getNestedValue(
                  boxMeta,
                  'deviceCount',
                  0
                ) as number,
                rule_count: SafeAccess.getNestedValue(
                  boxMeta,
                  'ruleCount',
                  0
                ) as number,
                alarm_count: SafeAccess.getNestedValue(
                  boxMeta,
                  'alarmCount',
                  0
                ) as number,
                activity_score: SafeAccess.getNestedValue(
                  stat,
                  'value',
                  0
                ) as number,
                last_seen: (SafeAccess.getNestedValue(
                  boxMeta,
                  'lastSeen',
                  0
                ) as number)
                  ? unixToISOString(
                      SafeAccess.getNestedValue(boxMeta, 'lastSeen', 0) as number
                    )
                  : 'Never',
              };
            }
          ).sort((a: any, b: any) => b.activity_score - a.activity_score);
    
          // Calculate summary with safe operations
          const onlineBoxes = SafeAccess.safeArrayFilter(
            stats.results,
            (s: any) =>
              SafeAccess.getNestedValue(s, 'meta.online', false) as boolean
          ).length;
    
          const totalDevices = stats.results.reduce(
            (sum: number, s: any) =>
              sum + (SafeAccess.getNestedValue(s, 'meta.deviceCount', 0) as number),
            0
          );
          const totalRules = stats.results.reduce(
            (sum: number, s: any) =>
              sum + (SafeAccess.getNestedValue(s, 'meta.ruleCount', 0) as number),
            0
          );
          const totalAlarms = stats.results.reduce(
            (sum: number, s: any) =>
              sum + (SafeAccess.getNestedValue(s, 'meta.alarmCount', 0) as number),
            0
          );
    
          const startTime = Date.now();
    
          const unifiedResponseData = {
            total_boxes: stats.results.length,
            box_statistics: boxStatistics,
            summary: {
              online_boxes: onlineBoxes,
              total_devices: totalDevices,
              total_rules: totalRules,
              total_alarms: totalAlarms,
            },
          };
    
          const executionTime = Date.now() - startTime;
          return this.createUnifiedResponse(unifiedResponseData, {
            executionTimeMs: executionTime,
          });
        } catch (error: unknown) {
          logger.error(
            'Error in get_statistics_by_box',
            error instanceof Error ? error : new Error(String(error))
          );
    
          return this.createErrorResponse(
            `Failed to get box statistics: ${error instanceof Error ? error.message : 'Unknown error'}`,
            ErrorType.API_ERROR,
            {
              total_boxes: 0,
              box_statistics: [],
              summary: {
                online_boxes: 0,
                total_devices: 0,
                total_rules: 0,
                total_alarms: 0,
              },
            }
          );
        }
      }
  • Registration of the GetStatisticsByBoxHandler in the central ToolRegistry during automatic handler registration in the constructor.
    this.register(new GetStatisticsByBoxHandler());
  • The input schema definition for the 'get_statistics_by_box' tool provided in the MCP server's listTools response, defining parameters like type, group, and limit.
    name: 'get_statistics_by_box',
    description:
      'Get statistics for each Firewalla box (top boxes by blocked flows or security alarms)',
    inputSchema: {
      type: 'object',
      properties: {
        type: {
          type: 'string',
          enum: ['topBoxesByBlockedFlows', 'topBoxesBySecurityAlarms'],
          description: 'Statistics type to retrieve',
          default: 'topBoxesByBlockedFlows',
        },
        group: {
          type: 'string',
          description: 'Get statistics for specific box group',
        },
        limit: {
          type: 'number',
          description:
            'Maximum number of results (optional, default: 5)',
          minimum: 1,
          default: 5,
        },
      },
      required: [],
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what statistics are retrieved without behavioral details. It does not disclose whether this is a read-only operation, requires authentication, has rate limits, or describes the return format (e.g., list structure, pagination). 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 a single, efficient sentence that front-loads the core purpose with no wasted words. It directly communicates the tool's function and key examples, making it easy to parse and understand quickly.

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 no annotations and no output schema, the description is incomplete for a tool that retrieves statistical data. It adequately states the purpose but lacks details on behavioral traits, return values, or error handling. The high schema coverage helps, but overall context is insufficient for full agent understanding without additional structured data.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters (type, group, limit). The description adds minimal value by mentioning 'top boxes by blocked flows or security alarms', which aligns with the 'type' enum but does not provide additional semantics beyond what the schema already specifies. Baseline 3 is appropriate as the schema does the heavy lifting.

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 action ('Get statistics') and resource ('for each Firewalla box'), with specific examples of statistics types ('top boxes by blocked flows or security alarms'). It distinguishes from some siblings like 'get_simple_statistics' by specifying box-level focus, though not explicitly from 'get_statistics_by_region' which has a different grouping dimension.

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

Usage Guidelines3/5

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

The description implies usage for retrieving box-level statistics, particularly top performers in blocked flows or security alarms. However, it lacks explicit guidance on when to use this tool versus alternatives like 'get_simple_statistics' or 'get_statistics_by_region', and does not mention prerequisites or exclusions.

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