Skip to main content
Glama
lis186

Taiwan Holiday MCP Server

by lis186

get_holiday_stats

Retrieve Taiwan holiday statistics for a specific year or month to analyze holiday distribution and plan schedules effectively.

Instructions

獲取指定年份或年月的台灣假期統計資訊

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yearYes要查詢的年份
monthNo要查詢的月份(可選),1-12

Implementation Reference

  • Core handler function that implements the get_holiday_stats tool logic: fetches holidays for the specified year, optionally filters by month, validates input, and delegates to calculateStats.
    async getHolidayStats(year: number, month?: number): Promise<HolidayStats> {
      const holidays = await this.getHolidaysForYear(year);
      
      let filteredHolidays = holidays;
      
      // 如果指定月份,進行篩選
      if (month !== undefined) {
        if (month < 1 || month > 12) {
          throw new HolidayServiceError(
            `無效的月份: ${month},月份必須在 1-12 之間`,
            ErrorType.INVALID_MONTH
          );
        }
        
        const monthStr = month.toString().padStart(2, '0');
        filteredHolidays = holidays.filter(holiday => {
          const holidayMonth = holiday.date.substring(4, 6);
          return holidayMonth === monthStr;
        });
      }
    
      return this.calculateStats(year, filteredHolidays);
    }
  • MCP server handler for the get_holiday_stats tool: validates arguments, calls HolidayService.getHolidayStats, and formats the JSON response.
    private async handleGetHolidayStats(args: any) {
      const { year, month } = args;
      
      if (!year || typeof year !== 'number') {
        throw new Error('缺少必要參數:year');
      }
    
      const stats = await this.holidayService.getHolidayStats(year, month);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              data: {
                year: year,
                month: month,
                statistics: stats,
                summary: month 
                  ? `${year} 年 ${month} 月共有 ${stats.totalHolidays} 個假期`
                  : `${year} 年共有 ${stats.totalHolidays} 個假期`
              },
              timestamp: new Date().toISOString(),
              tool: 'get_holiday_stats'
            }, null, 2),
          },
        ],
      };
    }
  • src/server.ts:112-134 (registration)
    Tool registration in ListToolsRequestSchema handler: defines name, description, and input schema for get_holiday_stats.
    {
      name: 'get_holiday_stats',
      description: '獲取指定年份或年月的台灣假期統計資訊',
      inputSchema: {
        type: 'object',
        properties: {
          year: {
            type: 'integer',
            description: '要查詢的年份',
            minimum: 2017,
            maximum: 2026
          },
          month: {
            type: 'integer',
            description: '要查詢的月份(可選),1-12',
            minimum: 1,
            maximum: 12
          }
        },
        required: ['year'],
        additionalProperties: false,
      },
    } as Tool,
  • Type definition for HolidayStats, the return type of the get_holiday_stats tool.
    export interface HolidayStats {
      /** 年份 */
      year: number;
      /** 總假日天數 */
      totalHolidays: number;
      /** 國定假日天數 */
      nationalHolidays: number;
      /** 補假天數 */
      compensatoryDays: number;
      /** 調整放假天數 */
      adjustedHolidays: number;
      /** 補班天數 */
      workingDays: number;
      /** 假日類型分布 */
      holidayTypes: Record<string, number>;
    }
  • Helper function that processes holiday data to compute detailed statistics by type and category.
    private calculateStats(year: number, holidays: Holiday[]): HolidayStats {
      const holidayTypes: Record<string, number> = {};
      let totalHolidays = 0;
      let nationalHolidays = 0;
      let compensatoryDays = 0;
      let adjustedHolidays = 0;
      let workingDays = 0;
    
      for (const holiday of holidays) {
        if (holiday.isHoliday) {
          totalHolidays++;
          
          // 分析假日類型
          const description = holiday.description.toLowerCase();
          
          if (description.includes('補假')) {
            compensatoryDays++;
            holidayTypes[HOLIDAY_TYPES.COMPENSATORY] = (holidayTypes[HOLIDAY_TYPES.COMPENSATORY] || 0) + 1;
          } else if (description.includes('調整放假')) {
            adjustedHolidays++;
            holidayTypes[HOLIDAY_TYPES.ADJUSTED] = (holidayTypes[HOLIDAY_TYPES.ADJUSTED] || 0) + 1;
          } else {
            nationalHolidays++;
            holidayTypes[HOLIDAY_TYPES.NATIONAL] = (holidayTypes[HOLIDAY_TYPES.NATIONAL] || 0) + 1;
          }
          
          // 記錄具體假日類型
          if (holiday.description) {
            holidayTypes[holiday.description] = (holidayTypes[holiday.description] || 0) + 1;
          }
        } else if (holiday.description.includes('補行上班')) {
          workingDays++;
          holidayTypes[HOLIDAY_TYPES.WORKING] = (holidayTypes[HOLIDAY_TYPES.WORKING] || 0) + 1;
        }
      }
    
      return {
        year,
        totalHolidays,
        nationalHolidays,
        compensatoryDays,
        adjustedHolidays,
        workingDays,
        holidayTypes
      };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.0.0
    • changedInput schema / properties / year / maximum
      Previous value: -2025New value: +2026
  2. First observed

TDQS

B3.2/5.0
Behavior2/5

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

No annotations are provided, so the description carries full responsibility. It only states the function without disclosing behavioral traits like return format, aggregation details, or potential limitations (e.g., date boundaries). This is a significant gap.

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, clear sentence that front-loads the verb and resource, with no unnecessary words. It is appropriately concise for a simple tool.

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?

With no output schema and no annotations, the description omits what 'statistics' means or what the response contains. For a tool with two parameters, this is under-specified and leaves the agent guessing about the return value.

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 covers 100% of parameters, with year and month each having descriptions. The description adds minimal semantic value, only reaffirming that the tool works for a year or year-month combination, which is already implied by the parameters.

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 retrieves Taiwan holiday statistics for a specified year or year-month, using a specific verb (獲取) and resource (台灣假期統計資訊). However, it does not explicitly differentiate from sibling tools like check_holiday or get_holidays_in_range, though the 'statistics' focus implies a different use case.

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 implicitly conveys usage: use when you need Taiwan holiday statistics for a year or month. It lacks explicit guidance on when to prefer this tool over siblings, such as when checking a single date or a range.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.