Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

calculate_business_hours

Calculate business hours between two timestamps, excluding weekends and holidays, with customizable business hours and timezone settings.

Instructions

Calculate business hours between two times

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_timeYesStart time
end_timeYesEnd time
business_hoursNoBusiness hours definition (default: 9 AM - 5 PM)
timezoneNoTimezone for calculation (default: system timezone)
holidaysNoArray of holiday dates
include_weekendsNoInclude weekends in calculation (default: false)

Implementation Reference

  • Core handler function that executes the business hours calculation logic, including input validation, date range processing, holiday and weekend exclusion, and detailed breakdown.
    export function calculateBusinessHours(
      params: CalculateBusinessHoursParams
    ): CalculateBusinessHoursResult {
      const { start_time, end_time, holidays = [], include_weekends = false } = params;
    
      // Log entry with parameters
      debug.business('calculateBusinessHours called with params: %O', {
        start_time,
        end_time,
        timezone: params.timezone,
        business_hours: params.business_hours ?? 'default',
        holidays_count: holidays.length,
        include_weekends,
      });
    
      const config = getConfig();
      const timezone = resolveTimezone(params.timezone, config.defaultTimezone);
    
      // Validate all input parameters
      validateBusinessHoursParams({
        start_time,
        end_time,
        holidays,
        timezone,
        business_hours: params.business_hours,
      });
    
      // Build cache key
      const cacheKey = buildBusinessHoursCacheKey({
        start_time,
        end_time,
        timezone,
        business_hours: params.business_hours,
        holidays,
        include_weekends,
      });
    
      // Use withCache wrapper for the calculation
      return withCache(cacheKey, CacheTTL.CALCULATIONS, () => {
        // Parse dates
        const startDate = parseDateWithTimezone(start_time, timezone, 'start_time');
        const endDate = parseDateWithTimezone(end_time, timezone, 'end_time');
    
        // Validate date range
        validateBusinessDateRange(startDate, endDate, start_time, end_time);
    
        // Log the calculation context
        debug.business(
          'Business hours calculation: %s to %s in %s',
          formatInTimeZone(startDate, timezone, 'yyyy-MM-dd HH:mm'),
          formatInTimeZone(endDate, timezone, 'yyyy-MM-dd HH:mm'),
          timezone
        );
    
        // Parse holiday dates
        const holidayDates = parseHolidayDates(holidays, timezone);
        if (holidayDates.length > 0) {
          debug.business('Holidays to exclude: %O', holidayDates);
        }
    
        // Generate date range to process
        const dateStrings = generateDateRange(startDate, endDate, timezone);
    
        // Process all days in the date range
        const { breakdown, totalMinutes } = processDateRange({
          dateStrings,
          startDate,
          endDate,
          timezone,
          holidayDates,
          include_weekends,
          business_hours: params.business_hours,
        });
    
        // Build and return the final result
        const result = buildBusinessHoursResult(breakdown, totalMinutes);
    
        // Log successful completion
        debug.business(
          'calculateBusinessHours completed successfully: %d total hours',
          result.total_business_hours
        );
    
        return result;
      });
    }
  • JSON Schema defining the input parameters for the calculate_business_hours MCP tool.
    inputSchema: {
      type: 'object' as const,
      properties: {
        start_time: { type: 'string' as const, description: 'Start time' },
        end_time: { type: 'string' as const, description: 'End time' },
        business_hours: {
          type: 'object' as const,
          description: 'Business hours definition (default: 9 AM - 5 PM)',
        },
        timezone: {
          type: 'string' as const,
          description: 'Timezone for calculation (default: system timezone)',
        },
        holidays: {
          type: 'array' as const,
          items: { type: 'string' as const },
          description: 'Array of holiday dates',
        },
        include_weekends: {
          type: 'boolean' as const,
          description: 'Include weekends in calculation (default: false)',
        },
      },
      required: ['start_time', 'end_time'],
    },
  • src/index.ts:271-272 (registration)
    Registration of the calculate_business_hours tool handler in the TOOL_FUNCTIONS map used by the MCP server for tool calls.
    calculate_business_hours: (params: unknown) =>
      calculateBusinessHours(params as Parameters<typeof calculateBusinessHours>[0]),
  • src/index.ts:202-229 (registration)
    Tool definition registration in TOOL_DEFINITIONS array, providing name, description, and schema for tools/list endpoint.
      name: 'calculate_business_hours',
      description: 'Calculate business hours between two times',
      inputSchema: {
        type: 'object' as const,
        properties: {
          start_time: { type: 'string' as const, description: 'Start time' },
          end_time: { type: 'string' as const, description: 'End time' },
          business_hours: {
            type: 'object' as const,
            description: 'Business hours definition (default: 9 AM - 5 PM)',
          },
          timezone: {
            type: 'string' as const,
            description: 'Timezone for calculation (default: system timezone)',
          },
          holidays: {
            type: 'array' as const,
            items: { type: 'string' as const },
            description: 'Array of holiday dates',
          },
          include_weekends: {
            type: 'boolean' as const,
            description: 'Include weekends in calculation (default: false)',
          },
        },
        required: ['start_time', 'end_time'],
      },
    },
  • TypeScript type definitions for tool parameters, daily breakdown, and result structure.
    export interface CalculateBusinessHoursParams {
      start_time: string;
      end_time: string;
      business_hours?: BusinessHours | WeeklyBusinessHours;
      timezone?: string;
      holidays?: string[];
      include_weekends?: boolean;
    }
    
    export interface DayBusinessHours {
      date: string;
      day_of_week: string;
      business_minutes: number;
      is_weekend: boolean;
      is_holiday: boolean;
    }
    
    export interface CalculateBusinessHoursResult {
      total_business_minutes: number;
      total_business_hours: number;
      breakdown: DayBusinessHours[];
    }
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 specify whether this tool has side effects, requires authentication, has rate limits, or what format the output takes. For a tool with 6 parameters and no annotations, this represents a significant gap in behavioral information.

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 one sentence that directly states the tool's purpose. There's no wasted language or unnecessary elaboration. It's appropriately sized for a calculation tool and front-loads the essential information.

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 tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. While the schema covers parameter details, the description doesn't address behavioral aspects, usage context, or output format. Given the complexity of the tool (business hours calculation with multiple configuration options) and the lack of structured metadata, the description should provide more contextual information.

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%, meaning all parameters are documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema. According to the scoring rules, when schema coverage is high (>80%), the baseline score is 3 even with no parameter information in the description.

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 as calculating business hours between two times, which is a specific verb+resource combination. However, it doesn't distinguish this tool from sibling tools like 'calculate_duration' or 'get_business_days', which likely have overlapping functionality. The description is accurate but lacks sibling differentiation.

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_duration', 'get_business_days', and 'add_time' available, there's no indication of what makes this tool unique or when it should be preferred over those alternatives. The description only states what the tool does, not when to use it.

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