Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

next_occurrence

Calculate the next occurrence of a recurring event based on specified patterns like daily, weekly, monthly, or yearly schedules.

Instructions

Find next occurrence of a recurring event

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesRecurrence pattern
start_fromNoStart searching from
day_of_weekNoFor weekly (0-6, 0=Sunday)
day_of_monthNoFor monthly (1-31)
timeNoTime in HH:mm format
timezoneNoTimezone for calculation (default: system timezone)

Implementation Reference

  • The core handler function implementing the next_occurrence tool logic, including parameter validation, timezone resolution, caching, and delegation to calculation logic.
    export function nextOccurrence(params: NextOccurrenceParams): NextOccurrenceResult {
      debug.recurrence('nextOccurrence called with params: %O', params);
      // Validate string length first
      if (params.start_from && typeof params.start_from === 'string') {
        validateDateString(params.start_from, 'start_from');
      }
    
      const config = getConfig();
      const fallbackTimezone = config.defaultTimezone;
      const timezone = resolveTimezone(params.timezone, fallbackTimezone);
    
      // Validate timezone if provided
      if (params.timezone) {
        debug.validation('Validating timezone: %s', timezone);
        if (!validateTimezone(timezone)) {
          debug.error('Invalid timezone: %s', timezone);
          throw new TimezoneError(`Invalid timezone: ${timezone}`, timezone);
        }
      }
      const cacheKey = getCacheKey(params, fallbackTimezone, timezone);
    
      // Use withCache wrapper instead of manual cache management
      return withCache(cacheKey, CacheTTL.CALCULATIONS, () => {
        try {
          const result = calculateNextOccurrence(params, timezone);
          debug.recurrence('nextOccurrence returning: %O', result);
          return result;
        } catch (error) {
          handleCalculationError(error);
        }
      });
    }
  • TypeScript type definitions for input parameters (NextOccurrenceParams) and output result (NextOccurrenceResult) used by the handler.
    export interface NextOccurrenceParams {
      pattern: RecurrencePattern;
      start_from?: string;
      day_of_week?: number;
      day_of_month?: number;
      time?: string;
      timezone?: string;
    }
    
    export interface NextOccurrenceResult {
      next: string;
      unix: number;
      days_until: number;
    }
  • src/index.ts:157-179 (registration)
    MCP tool registration in TOOL_DEFINITIONS array, including the tool name, description, and input schema.
    {
      name: 'next_occurrence',
      description: 'Find next occurrence of a recurring event',
      inputSchema: {
        type: 'object' as const,
        properties: {
          pattern: {
            type: 'string' as const,
            enum: ['daily', 'weekly', 'monthly', 'yearly'],
            description: 'Recurrence pattern',
          },
          start_from: { type: 'string' as const, description: 'Start searching from' },
          day_of_week: { type: 'number' as const, description: 'For weekly (0-6, 0=Sunday)' },
          day_of_month: { type: 'number' as const, description: 'For monthly (1-31)' },
          time: { type: 'string' as const, description: 'Time in HH:mm format' },
          timezone: {
            type: 'string' as const,
            description: 'Timezone for calculation (default: system timezone)',
          },
        },
        required: ['pattern'],
      },
    },
  • src/index.ts:268-274 (registration)
    Mapping of the 'next_occurrence' tool name to the nextOccurrence handler function in TOOL_FUNCTIONS record.
      next_occurrence: (params: unknown) =>
        nextOccurrence(params as Parameters<typeof nextOccurrence>[0]),
      format_time: (params: unknown) => formatTime(params as Parameters<typeof formatTime>[0]),
      calculate_business_hours: (params: unknown) =>
        calculateBusinessHours(params as Parameters<typeof calculateBusinessHours>[0]),
      days_until: (params: unknown) => daysUntil(params as Parameters<typeof daysUntil>[0]),
    };
  • Internal helper function that performs the core date calculation using the RecurrenceFactory.
    function calculateNextOccurrence(
      params: NextOccurrenceParams,
      timezone: string
    ): NextOccurrenceResult {
      debug.recurrence('calculateNextOccurrence called with params: %O', params);
      // Parse start date
      let startFrom: Date;
      if (params.start_from) {
        debug.parse('Parsing start_from: %s', params.start_from);
        try {
          startFrom = parseTimeInput(params.start_from, timezone).date;
          debug.parse('Parsed start_from date: %s', startFrom.toISOString());
        } catch {
          debug.error('Invalid start_from date: %s', params.start_from);
          throw new DateParsingError('Invalid start_from date', { start_from: params.start_from });
        }
      } else {
        startFrom = new Date();
      }
    
      // Map parameters to new format
      const recurrenceParams = mapToRecurrenceParams(params);
      recurrenceParams.timezone = timezone;
    
      // Calculate next occurrence using factory
      debug.recurrence('Calculating next occurrence with factory');
      const nextDate = factory.calculate(startFrom, recurrenceParams);
      debug.recurrence('Next occurrence date: %s', nextDate.toISOString());
    
      // Format result
      const result: NextOccurrenceResult = {
        next: nextDate.toISOString(),
        unix: Math.floor(nextDate.getTime() / 1000),
        days_until: calculateDaysUntil(nextDate, timezone),
      };
    
      return result;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't explain how it behaves: whether it returns a single date/time, what format the output is in, if there are any rate limits, error conditions, or dependencies. For a tool with 6 parameters and no output schema, this leaves significant gaps in understanding its operation.

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 efficiently conveys the core purpose without any wasted words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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?

Given the complexity of handling recurring events with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns, how to interpret results, or provide any context about edge cases (e.g., invalid date combinations). For a tool that calculates future occurrences, this leaves too much undefined.

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 no additional parameter information beyond what's in the schema, such as explaining how parameters interact (e.g., 'day_of_week' is only relevant for 'weekly' pattern) or providing examples. Baseline 3 is appropriate when the 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 verb 'find' and the resource 'next occurrence of a recurring event', making the purpose immediately understandable. However, it doesn't distinguish this tool from potential sibling tools that might also handle recurring events or date calculations, though none of the listed siblings appear to directly overlap.

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 any prerequisites, constraints, or compare it to sibling tools like 'days_until' or 'calculate_duration' that might serve related purposes in date/time calculations.

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