Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

get_business_days

Calculate business days between two dates, excluding weekends and custom holidays for accurate scheduling and deadline tracking.

Instructions

Calculate business days between dates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYesStart date
end_dateYesEnd date
exclude_weekendsNoExclude weekends (default: true)
holidaysNoArray of holiday dates
timezoneNoTimezone for calculation (default: system timezone)

Implementation Reference

  • Core handler function implementing get_business_days tool logic: validates inputs, resolves timezone, aggregates holidays, categorizes days (business/weekend/holiday), applies weekend exclusion, and returns counts with caching.
    export function getBusinessDays(params: GetBusinessDaysParams): GetBusinessDaysResult {
      const { start_date, end_date, holidays = [], holiday_calendar, custom_holidays = [] } = params;
    
      // Log entry with all parameters to show what was provided
      debug.business('getBusinessDays called with params: %O', {
        start_date,
        end_date,
        timezone: params.timezone,
        exclude_weekends: params.exclude_weekends,
        holiday_calendar,
        holidays_count: holidays.length,
        custom_holidays_count: custom_holidays.length,
      });
    
      // Important: Log if no country parameter provided but holidays expected
      if (!holiday_calendar && holidays.length === 0 && custom_holidays.length === 0) {
        debug.validation('No holiday information provided (no country/calendar, no explicit holidays)');
      }
    
      // Validate string lengths and array lengths first
      validateDateString(start_date, 'start_date');
      validateDateString(end_date, 'end_date');
      validateArrayLength(holidays, LIMITS.MAX_ARRAY_LENGTH, 'holidays');
      validateArrayLength(custom_holidays, LIMITS.MAX_ARRAY_LENGTH, 'custom_holidays');
    
      const excludeWeekends = params.exclude_weekends ?? true;
      const includeObserved = params.include_observed ?? true;
      const config = getConfig();
      const timezone = resolveTimezone(params.timezone, config.defaultTimezone);
    
      debug.timezone('Resolved timezone: %s (from: %s)', timezone, params.timezone ?? 'default');
    
      // Build cache key using new utility
      const cacheKey = buildCacheKey('business', {
        single: { timezone },
        dates: [start_date, end_date],
        flags: { excludeWeekends, includeObserved },
        arrays: { holidays, customHolidays: custom_holidays },
        optional: { calendar: holiday_calendar },
      });
    
      // Use withCache wrapper
      return withCache(cacheKey, CacheTTL.BUSINESS_DAYS, () => {
        // Validate timezone if provided
        if (timezone && !validateTimezone(timezone)) {
          debug.error('Invalid timezone: %s', timezone);
          throw new TimezoneError(`Invalid timezone: ${timezone}`, timezone);
        }
    
        // Validate holiday_calendar if provided
        if (holiday_calendar) {
          validateHolidayCalendar(holiday_calendar);
        }
    
        // Parse dates
        const startDate = parseDateWithTimezone(start_date, timezone, 'start_date');
        const endDate = parseDateWithTimezone(end_date, timezone, 'end_date');
    
        // DoS protection: Validate date range
        validateDateRange(startDate, endDate, start_date, end_date);
    
        // Log calculation context
        debug.business(
          'Business days calculation: %s to %s',
          format(startDate, 'yyyy-MM-dd'),
          format(endDate, 'yyyy-MM-dd')
        );
    
        // Use the new holidayAggregator utility
        debug.holidays('Aggregating holidays for calendar: %s', holiday_calendar ?? 'none');
        const allHolidayDates = aggregateHolidays({
          calendar: holiday_calendar,
          includeObserved,
          dateRange: {
            start: startDate,
            end: endDate,
          },
          custom: custom_holidays,
          legacy: holidays,
          timezone,
        });
        debug.holidays('Total holidays found: %d', allHolidayDates.size);
        if (allHolidayDates.size > 0) {
          debug.holidays('Holiday dates: %O', Array.from(allHolidayDates));
        }
    
        // Get all days in the interval
        const days = eachDayOfInterval({
          start: startDate,
          end: endDate,
        });
        debug.timing('Processing %d days from %s to %s', days.length, start_date, end_date);
    
        // Categorize days into business, weekend, and holiday
        const categories = categorizeDays(days, allHolidayDates);
    
        // Adjust for weekend inclusion preference
        const adjustedCategories = adjustForWeekends(categories, excludeWeekends);
    
        const { businessDays, weekendDays, holidayCount } = adjustedCategories;
    
        // Log summary
        debug.business(
          'Calculated business days: %d of %d total days (%d weekends, %d holidays)',
          businessDays,
          days.length,
          weekendDays,
          holidayCount
        );
    
        const result: GetBusinessDaysResult = {
          total_days: days.length,
          business_days: businessDays,
          weekend_days: weekendDays,
          holiday_count: holidayCount,
        };
    
        return result;
      });
    }
  • src/index.ts:266-267 (registration)
    Tool function mapping in TOOL_FUNCTIONS object that registers the getBusinessDays handler for 'get_business_days' tool name.
    get_business_days: (params: unknown) =>
      getBusinessDays(params as Parameters<typeof getBusinessDays>[0]),
  • src/index.ts:133-156 (registration)
    Tool registration in TOOL_DEFINITIONS array defining name, description, and inputSchema for get_business_days.
      name: 'get_business_days',
      description: 'Calculate business days between dates',
      inputSchema: {
        type: 'object' as const,
        properties: {
          start_date: { type: 'string' as const, description: 'Start date' },
          end_date: { type: 'string' as const, description: 'End date' },
          exclude_weekends: {
            type: 'boolean' as const,
            description: 'Exclude weekends (default: true)',
          },
          holidays: {
            type: 'array' as const,
            items: { type: 'string' as const },
            description: 'Array of holiday dates',
          },
          timezone: {
            type: 'string' as const,
            description: 'Timezone for calculation (default: system timezone)',
          },
        },
        required: ['start_date', 'end_date'],
      },
    },
  • TypeScript interfaces defining input parameters (GetBusinessDaysParams) and output structure (GetBusinessDaysResult) for the tool.
    export interface GetBusinessDaysParams {
      start_date: string;
      end_date: string;
      exclude_weekends?: boolean;
      holidays?: string[];
      timezone?: string;
      holiday_calendar?: string;
      include_observed?: boolean;
      custom_holidays?: string[];
    }
    
    export interface GetBusinessDaysResult {
      total_days: number;
      business_days: number;
      weekend_days: number;
      holiday_count: number;
    }
  • src/tools/index.ts:7-7 (registration)
    Central export of getBusinessDays handler from tools index, imported by main index.ts.
    export { getBusinessDays } from './getBusinessDays';
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. While 'calculate' implies a read-only operation, the description doesn't mention any behavioral traits such as error handling, performance characteristics, or whether the calculation is inclusive/exclusive of start/end dates. This leaves significant gaps for a tool with 5 parameters.

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 with just four words, front-loading the core purpose without any unnecessary elaboration. Every word earns its place, making it easy for an agent to quickly understand what the tool does at a high level.

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?

For a calculation tool with 5 parameters and no output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., integer count of days, detailed breakdown), doesn't clarify behavioral aspects like date inclusivity, and provides no context about how business days are defined beyond weekend/holiday exclusion mentioned in parameters.

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 description coverage is 100%, so all parameters are documented in the schema. The description doesn't add any meaningful parameter semantics beyond what's already in the schema (e.g., it doesn't explain date format requirements, holiday array format, or timezone string conventions). This meets the baseline for high schema coverage.

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 with a specific verb ('calculate') and resource ('business days between dates'), making it immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'calculate_business_hours' or 'calculate_duration', which could cause confusion about when to use each.

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. With sibling tools like 'calculate_business_hours' and 'calculate_duration' available, there's no indication of how this tool differs or when it should be preferred, leaving the agent to guess based on tool names 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/pshempel/mcp-time-server-node'

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