Skip to main content
Glama
davidan90

MCP Node Time

by davidan90

get_current_time

Retrieve the current date and time in any timezone with customizable formatting options to ensure accurate time information.

Instructions

Get the current date and time in a specific timezone with various formatting options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneYesIANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")
formatNoOutput format: "iso" for ISO 8601, "local" for MM/DD/YYYY HH:MM:SS, "full" for human-readableiso

Implementation Reference

  • Handler for 'get_current_time' tool in the switch statement of CallToolRequestSchema, parses params, calls TimeService, formats and returns MCP response.
    case 'get_current_time': {
      const { timezone, format = 'iso' } = (args as unknown) as GetCurrentTimeParams;
      const result = TimeService.getCurrentTime(timezone, format);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              timezone: result.timezone,
              datetime: result.datetime,
              isDST: result.isDST,
              utcOffset: result.utcOffset,
              localizedFormat: result.localizedFormat,
              format: format,
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:27-45 (registration)
    Registration of 'get_current_time' tool in the tools array provided to ListToolsRequestSchema.
      name: 'get_current_time',
      description: 'Get the current date and time in a specific timezone with various formatting options',
      inputSchema: {
        type: 'object',
        properties: {
          timezone: {
            type: 'string',
            description: 'IANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")',
          },
          format: {
            type: 'string',
            enum: ['iso', 'local', 'full'],
            description: 'Output format: "iso" for ISO 8601, "local" for MM/DD/YYYY HH:MM:SS, "full" for human-readable',
            default: 'iso',
          },
        },
        required: ['timezone'],
      },
    },
  • TypeScript interface defining input parameters for get_current_time tool.
    export interface GetCurrentTimeParams {
      timezone: string;
      format?: 'iso' | 'local' | 'full';
    }
  • Core implementation of getCurrentTime logic in TimeService class, handles timezone validation, DST, offset, and formatting.
    static getCurrentTime(timezone: string, format: 'iso' | 'local' | 'full' = 'iso'): TimezoneInfo {
      this.validateTimezone(timezone);
    
      const now = new Date();
      
      const isDST = this.isDaylightSavingTime(now, timezone);
      const utcOffset = this.getUTCOffset(now, timezone);
    
      let datetime: string;
      let localizedFormat: string;
    
      switch (format) {
        case 'iso':
          datetime = new Date(now.toLocaleString('en-US', { timeZone: timezone })).toISOString();
          localizedFormat = datetime;
          break;
        case 'local':
          datetime = now.toLocaleString('en-US', { 
            timeZone: timezone,
            year: 'numeric',
            month: '2-digit',
            day: '2-digit',
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit',
            hour12: false
          });
          localizedFormat = datetime;
          break;
        case 'full':
          datetime = now.toLocaleString('en-US', { timeZone: timezone });
          localizedFormat = now.toLocaleString('en-US', { 
            timeZone: timezone,
            weekday: 'long',
            year: 'numeric',
            month: 'long',
            day: 'numeric',
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit',
            timeZoneName: 'long'
          });
          break;
      }
    
      return {
        timezone,
        datetime,
        isDST,
        utcOffset,
        localizedFormat
      };
    }

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/davidan90/time-node-mcp'

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