Skip to main content
Glama
lis186

Taiwan Holiday MCP Server

by lis186

get_holidays_in_range

Retrieve all Taiwanese holidays within a specified date range to plan schedules and avoid conflicts.

Instructions

獲取指定日期範圍內的所有台灣假期

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYes開始日期,支援格式:YYYY-MM-DD 或 YYYYMMDD
end_dateYes結束日期,支援格式:YYYY-MM-DD 或 YYYYMMDD

Implementation Reference

  • Handler for executing the get_holidays_in_range tool. Validates parameters, fetches holidays using HolidayService, filters actual holidays (isHoliday: true), and returns formatted JSON response.
    private async handleGetHolidaysInRange(args: any) {
      const { start_date, end_date } = args;
      
      if (!start_date || typeof start_date !== 'string') {
        throw new Error('缺少必要參數:start_date');
      }
      
      if (!end_date || typeof end_date !== 'string') {
        throw new Error('缺少必要參數:end_date');
      }
    
      const holidays = await this.holidayService.getHolidaysInRange(start_date, end_date);
      
      // 只返回實際的假期(isHoliday: true)
      const actualHolidays = holidays.filter(h => h.isHoliday);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              data: {
                startDate: start_date,
                endDate: end_date,
                holidays: actualHolidays,
                totalCount: actualHolidays.length,
                summary: `在 ${start_date} 到 ${end_date} 期間共有 ${actualHolidays.length} 個假期`
              },
              timestamp: new Date().toISOString(),
              tool: 'get_holidays_in_range'
            }, null, 2),
          },
        ],
      };
    }
  • Tool schema definition in ListTools response, including name, description, and input schema with validation for start_date and end_date parameters.
      name: 'get_holidays_in_range',
      description: '獲取指定日期範圍內的所有台灣假期',
      inputSchema: {
        type: 'object',
        properties: {
          start_date: {
            type: 'string',
            description: '開始日期,支援格式:YYYY-MM-DD 或 YYYYMMDD',
            pattern: '^(\\d{4}-\\d{2}-\\d{2}|\\d{8})$'
          },
          end_date: {
            type: 'string',
            description: '結束日期,支援格式:YYYY-MM-DD 或 YYYYMMDD',
            pattern: '^(\\d{4}-\\d{2}-\\d{2}|\\d{8})$'
          }
        },
        required: ['start_date', 'end_date'],
        additionalProperties: false,
      },
    } as Tool,
  • Core implementation that parses start and end dates, validates range, fetches holidays for each year in range using getHolidaysForYear, filters those within range using isDateInRange, sorts by date, and handles errors.
    async getHolidaysInRange(startDate: string, endDate: string): Promise<Holiday[]> {
      try {
        const start = parseDate(startDate);
        const end = parseDate(endDate);
        
        // 驗證日期範圍
        if (start.year > end.year || 
            (start.year === end.year && start.month > end.month) ||
            (start.year === end.year && start.month === end.month && start.day > end.day)) {
          throw new HolidayServiceError(
            `開始日期 ${startDate} 不能晚於結束日期 ${endDate}`,
            ErrorType.INVALID_DATE
          );
        }
    
        const result: Holiday[] = [];
        
        // 處理跨年度的情況
        for (let year = start.year; year <= end.year; year++) {
          const holidays = await this.getHolidaysForYear(year);
          
          for (const holiday of holidays) {
            const holidayDate = parseDate(holiday.date);
            
            // 檢查是否在範圍內
            if (this.isDateInRange(holidayDate, start, end)) {
              result.push(holiday);
            }
          }
        }
        
        // 按日期排序
        return result.sort((a, b) => a.date.localeCompare(b.date));
      } catch (error) {
        if (error instanceof DateParseError) {
          throw new HolidayServiceError(
            `日期解析錯誤: ${error.message}`,
            error.type,
            error
          );
        }
        throw error;
      }
    }
  • src/server.ts:148-149 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that routes to the specific handler.
    case 'get_holidays_in_range':
      return await this.handleGetHolidaysInRange(args);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.5/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 the full burden of disclosing behavior. However, it only states the purpose (retrieving holidays in a range) and does not mention return format, error handling, rate limits, or whether it is a read-only operation. This leaves significant behavioral context unspecified.

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, concise sentence that front-loads the core action and resource. It contains no wasted words and is appropriately minimal for the tool's simplicity.

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?

The tool is simple with only two parameters, and the schema adequately documents those. However, there is no output schema, and the description does not clarify the return structure or format (e.g., a list of holiday objects). The description implies the result is all holidays in the range, but a bit more detail would make it more complete.

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 schema covers 100% of parameters with descriptions of date formats (YYYY-MM-DD or YYYYMMDD). The description adds no additional parameter semantics beyond what the schema already provides, so the baseline score of 3 applies.

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 uses a specific verb '獲取' (get) with a clear resource '所有台灣假期' (all Taiwan holidays) and scope '指定日期範圍內' (within specified date range). This clearly differentiates it from sibling tools like check_holiday (which checks a single date) and get_holiday_stats (which provides statistics).

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 the tool is used for retrieving holidays within a date range, but it does not explicitly state when to use this tool versus alternatives like check_holiday or get_holiday_stats. No exclusions or alternative guidance is provided.

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