Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

format_time

Convert and display time in relative, calendar, or custom formats, with optional timezone adjustments for accurate and user-friendly time representation.

Instructions

Format time in various human-readable formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
custom_formatNoFor custom format
formatYesFormat type
timeYesTime to format
timezoneNoTimezone for display (default: system timezone)

Implementation Reference

  • Main formatTime tool handler function that orchestrates parameter validation, time parsing, caching, and formatting logic using helper functions.
    export function formatTime(params: FormatTimeParams): FormatTimeResult { debug.timing('formatTime called with params: %O', params); // Validate parameters first validateFormatParams(params); const formatType = params.format.toLowerCase(); const config = getConfig(); const timezone = resolveTimezone(params.timezone, config.defaultTimezone); // Use withCache wrapper return withCache( `format_time_${params.time}_${formatType}_${params.custom_format ?? ''}_${timezone}`, CacheTTL.TIMEZONE_CONVERT, () => { // Parse the time input const date = parseTimeWithFallback(params.time, timezone); let formatted: string; // Format based on type - now much simpler! switch (formatType) { case 'relative': case 'calendar': formatted = formatRelativeTime(date, timezone); break; case 'custom': // We know custom_format exists due to validation formatted = formatCustomTime(date, params.custom_format as string, timezone); break; default: // Should never reach here due to validation debug.error('Invalid format type (should never reach): %s', formatType); throw new ValidationError('Invalid format type', { format: formatType }); } const result: FormatTimeResult = { formatted, original: date.toISOString(), }; debug.timing('formatTime returning: %O', result); return result; } ); }
  • TypeScript interface definitions for FormatTimeParams (input parameters) and FormatTimeResult (output). Used for type safety and referenced in the handler.
    export interface FormatTimeParams { time: string; format: 'relative' | 'calendar' | 'custom'; custom_format?: string; timezone?: string; } export interface FormatTimeResult { formatted: string; original: string; }
  • src/index.ts:181-199 (registration)
    MCP tool registration definition for 'format_time', including name, description, and input schema for the tools/list response.
    name: 'format_time', description: 'Format time in various human-readable formats', inputSchema: { type: 'object' as const, properties: { time: { type: 'string' as const, description: 'Time to format' }, format: { type: 'string' as const, enum: ['relative', 'calendar', 'custom'], description: 'Format type', }, custom_format: { type: 'string' as const, description: 'For custom format' }, timezone: { type: 'string' as const, description: 'Timezone for display (default: system timezone)', }, }, required: ['time', 'format'], },
  • src/index.ts:270-273 (registration)
    Mapping of tool name 'format_time' to the formatTime handler function in TOOL_FUNCTIONS for execution during tools/call.
    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]),
  • Helper function for validating FormatTimeParams, including format type, custom_format presence, string lengths, and timezone validity.
    export function validateFormatParams(params: FormatTimeParams): void { debug.validation('validateFormatParams called with: %O', params); // Validate string lengths first if (typeof params.time === 'string') { validateDateString(params.time, 'time'); } if (params.custom_format) { validateStringLength(params.custom_format, LIMITS.MAX_FORMAT_LENGTH, 'custom_format'); } const formatType = params.format.toLowerCase(); // Validate format type const validFormats = ['relative', 'calendar', 'custom']; if (!validFormats.includes(formatType)) { debug.error('Invalid format type: %s', params.format); throw new ValidationError('Invalid format type', { format: params.format }); } // Validate custom format requirements if (formatType === 'custom') { if (params.custom_format === undefined || params.custom_format === null) { debug.error('custom_format is required when format is "custom"'); throw new ValidationError('custom_format is required when format is "custom"'); } if (params.custom_format === '') { debug.error('custom_format cannot be empty'); throw new ValidationError('custom_format cannot be empty', { custom_format: '' }); } } // Validate timezone if provided if (params.timezone) { const config = getConfig(); const timezone = resolveTimezone(params.timezone, config.defaultTimezone); if (!validateTimezone(timezone)) { debug.error('Invalid timezone: %s', timezone); throw new TimezoneError(`Invalid timezone: ${timezone}`, timezone); } } debug.validation('Parameter validation passed'); }

Other Tools

Related 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