Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

format_time

Convert timestamps into human-readable formats including relative time, calendar dates, and custom patterns with timezone support.

Instructions

Format time in various human-readable formats

Input Schema

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

Implementation Reference

  • Main handler function for the 'format_time' tool. Orchestrates validation, time parsing, caching, and conditional formatting (relative/calendar/custom) 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 interfaces defining input (FormatTimeParams) and output (FormatTimeResult) for the formatTime tool.
    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-200 (registration)
    MCP tool registration definition for 'format_time', including schema, description, and input validation rules.
      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-270 (registration)
    Handler mapping in TOOL_FUNCTIONS that connects the 'format_time' tool name to the formatTime implementation function.
    format_time: (params: unknown) => formatTime(params as Parameters<typeof formatTime>[0]),
  • Helper function for input validation specific to formatTime parameters, including format type, custom_format checks, and timezone validation.
    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');
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Format time' implies a read-only transformation, it doesn't specify whether this requires specific inputs, what happens with invalid time formats, or what the output looks like. For a tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 - a single sentence that directly states the tool's purpose. There's zero waste or unnecessary elaboration, making it highly efficient and front-loaded.

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?

Given the tool's moderate complexity (4 parameters, 2 required) and 100% schema coverage, the description is minimally adequate. However, with no output schema and no annotations, the description should ideally provide more context about what the formatted output looks like and any behavioral constraints.

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 4 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting, though the description could have provided context about how parameters interact.

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: 'Format time in various human-readable formats' - this specifies the verb (format) and resource (time) with the scope (human-readable formats). However, it doesn't explicitly differentiate from sibling tools like 'convert_timezone' or 'get_current_time', which also deal with time formatting/display.

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 siblings like 'convert_timezone', 'get_current_time', and 'calculate_duration' available, there's no indication of when format_time is the appropriate choice versus other time-related operations.

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