Skip to main content
Glama

compare_periods

Analyze productivity trends by comparing statistics between two time periods. Generate HTML and Markdown reports showing changes in metrics like meetings, email, and focus time.

Instructions

Compare productivity statistics between two time periods. Generates comparison reports in HTML and Markdown formats showing trends and changes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
period1YesFirst period to compare
period2YesSecond period to compare
metricsNoMetrics to compare (default: all)
output_formatNoOutput format(s) to generate (default: both)both
save_to_fileNoWhether to save comparison to summaries directory (default: true)

Implementation Reference

  • The core handler function for the 'compare_periods' tool. It validates input periods, calculates date ranges, generates instructions for data collection, processes comparison data if provided, computes changes between periods, and handles file saving for HTML/Markdown outputs.
    export async function comparePeriods(args) {
      try {
        if (!args.period1 || !args.period2) {
          throw {
            code: 'MISSING_PARAMETER',
            message: 'Both period1 and period2 must be provided',
            details: 'Each period should have start_date and end_date',
          };
        }
        
        // Calculate date ranges for both periods
        const period1Range = calculateDateRange({
          start_date: args.period1.start_date,
          end_date: args.period1.end_date,
        });
        
        const period2Range = calculateDateRange({
          start_date: args.period2.start_date,
          end_date: args.period2.end_date,
        });
        
        const metrics = args.metrics || ['all'];
        const outputFormat = args.output_format || config.defaults.outputFormat || 'both';
        const saveToFile = args.save_to_file !== false;
        
        // Generate comparison instructions
        const instructions = generateComparisonInstructions(period1Range, period2Range, metrics);
        
        const result = {
          success: true,
          message: 'Period comparison initiated. Follow instructions to collect data for both periods.',
          period1: period1Range,
          period2: period2Range,
          metrics_to_compare: metrics,
          output_format: outputFormat,
          save_to_file: saveToFile,
          instructions,
          note: 'This tool helps identify trends by comparing two time periods. Collect the same metrics for both periods, then calculate differences.',
        };
        
        // If comparison data is provided, process it
        if (args.comparison_data) {
          result.comparison = processComparisonData(
            args.comparison_data,
            period1Range,
            period2Range,
            metrics
          );
          
          // Save comparison files if requested
          if (saveToFile && args.comparison_data.html && args.comparison_data.markdown) {
            const files = [];
            const filenameBase = `period-comparison-${period1Range.startDate}-vs-${period2Range.startDate}`;
            
            if (outputFormat === 'both' || outputFormat === 'html') {
              const htmlPath = await saveSummary(
                args.comparison_data.html,
                `${filenameBase}.html`
              );
              files.push(htmlPath);
            }
            
            if (outputFormat === 'both' || outputFormat === 'markdown') {
              const mdPath = await saveSummary(
                args.comparison_data.markdown,
                `${filenameBase}.md`
              );
              files.push(mdPath);
            }
            
            result.files_saved = files;
            result.message = `Period comparison completed and saved to ${files.length} file(s).`;
          }
        }
        
        return result;
        
      } catch (error) {
        if (error.code) {
          throw error;
        }
        throw {
          code: 'COMPARISON_FAILED',
          message: 'Failed to compare periods',
          details: error.message,
        };
      }
    }
  • JSON Schema defining the input parameters for the compare_periods tool, including required period1 and period2 objects with dates, optional metrics, output_format, and save_to_file.
      name: 'compare_periods',
      description: 'Compare productivity statistics between two time periods. Generates comparison reports in HTML and Markdown formats showing trends and changes.',
      inputSchema: {
        type: 'object',
        properties: {
          period1: {
            type: 'object',
            description: 'First period to compare',
            properties: {
              start_date: {
                type: 'string',
                pattern: '^\\d{4}-\\d{2}-\\d{2}$',
              },
              end_date: {
                type: 'string',
                pattern: '^\\d{4}-\\d{2}-\\d{2}$',
              },
            },
            required: ['start_date', 'end_date'],
          },
          period2: {
            type: 'object',
            description: 'Second period to compare',
            properties: {
              start_date: {
                type: 'string',
                pattern: '^\\d{4}-\\d{2}-\\d{2}$',
              },
              end_date: {
                type: 'string',
                pattern: '^\\d{4}-\\d{2}-\\d{2}$',
              },
            },
            required: ['start_date', 'end_date'],
          },
          metrics: {
            type: 'array',
            items: {
              type: 'string',
              enum: ['meetings', 'slack', 'email', 'focus_time', 'all'],
            },
            description: 'Metrics to compare (default: all)',
            default: ['all'],
          },
          output_format: {
            type: 'string',
            enum: ['both', 'html', 'markdown'],
            description: 'Output format(s) to generate (default: both)',
            default: 'both',
          },
          save_to_file: {
            type: 'boolean',
            description: 'Whether to save comparison to summaries directory (default: true)',
            default: true,
          },
        },
        required: ['period1', 'period2'],
      },
    },
  • Registration of the compare_periods tool in the central handleToolCall switch statement, which dispatches calls to the comparePeriods implementation.
    case 'compare_periods':
      result = await comparePeriods(args);
      break;
  • Helper function that calculates absolute and percentage changes between two sets of statistics for various metrics like meeting hours, slack messages, emails, and focus time.
    function calculateChanges(stats1, stats2) {
      const changes = {};
      
      // Helper to calculate change
      const calcChange = (val1, val2, unit = '') => {
        const diff = val2 - val1;
        const percentage = val1 !== 0 ? ((diff / val1) * 100).toFixed(1) : 0;
        const direction = diff > 0 ? 'increase' : diff < 0 ? 'decrease' : 'no change';
        
        return {
          value: `${diff > 0 ? '+' : ''}${diff}${unit}`,
          percentage: `${percentage > 0 ? '+' : ''}${percentage}%`,
          direction,
        };
      };
      
      // Meeting hours
      if (stats1.meeting_hours !== undefined && stats2.meeting_hours !== undefined) {
        changes.meeting_hours = calcChange(stats1.meeting_hours, stats2.meeting_hours, ' hours');
      }
      
      // Slack messages
      if (stats1.slack_messages !== undefined && stats2.slack_messages !== undefined) {
        changes.slack_messages = calcChange(stats1.slack_messages, stats2.slack_messages, ' messages');
      }
      
      // Emails
      if (stats1.emails_sent !== undefined && stats2.emails_sent !== undefined) {
        changes.emails_sent = calcChange(stats1.emails_sent, stats2.emails_sent, ' emails');
      }
      
      // Focus time
      if (stats1.focus_time_hours !== undefined && stats2.focus_time_hours !== undefined) {
        changes.focus_time_hours = calcChange(stats1.focus_time_hours, stats2.focus_time_hours, ' hours');
      }
      
      return changes;
    }
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 offers limited behavioral insight. It mentions output formats and that reports are 'generated,' but doesn't disclose whether this is a read-only operation, if it requires specific permissions, whether it's computationally intensive, or what happens when save_to_file=true (where files are saved, naming conventions, overwrite behavior). For a tool with 5 parameters and no annotation coverage, this is insufficient.

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 efficiently structured in two sentences: first states the core purpose, second specifies output formats. There's no wasted language, though it could be slightly more front-loaded by mentioning key parameters. Every sentence earns its place by adding distinct information.

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 5 parameters with nested objects, no annotations, and no output schema, the description is moderately complete but has significant gaps. It covers the what (comparison) and output formats but lacks behavioral context (permissions, side effects), usage guidance, and output details. For a comparative analysis tool that likely produces complex reports, more context about report structure, data sources, or limitations would be helpful.

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 already documents all parameters thoroughly. The description adds minimal value beyond the schema - it mentions 'productivity statistics' which loosely relates to metrics, and 'HTML and Markdown formats' which relates to output_format, but provides no additional semantic context about parameter interactions or interpretation. Baseline 3 is appropriate when 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 tool's purpose: 'Compare productivity statistics between two time periods' with specific outputs ('HTML and Markdown formats showing trends and changes'). It distinguishes from siblings like generate_daily_summary or get_quick_stats by focusing on comparative analysis rather than single-period reporting. However, it doesn't explicitly differentiate from all siblings (e.g., get_summary could potentially involve comparisons).

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 doesn't mention when this comparative tool is preferred over single-period tools like generate_daily_summary or get_quick_stats, nor does it specify prerequisites or appropriate contexts for comparison. The agent must infer usage from the purpose alone.

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/philipbloch/summary-mcp'

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