Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

get_current_time

Retrieve current time in any timezone with customizable formatting options for accurate time display.

Instructions

Get current time in specified timezone with formatting options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneNoIANA timezone (default: system timezone)
formatNodate-fns format string
include_offsetNoInclude UTC offset (default: true)

Implementation Reference

  • The primary handler function that implements the core logic for the 'get_current_time' tool: validates input, resolves timezone, applies caching, formats current time, handles errors, and constructs the result object.
    export function getCurrentTime(params: GetCurrentTimeParams): GetCurrentTimeResult {
      debug.timezone('getCurrentTime called with params: %O', params);
    
      // Validate format string length first
      if (params.format) {
        validateStringLength(params.format, LIMITS.MAX_FORMAT_LENGTH, 'format');
      }
    
      // Resolve timezone with proper empty string handling
      const config = getConfig();
      const timezone = resolveTimezone(params.timezone, config.defaultTimezone);
      const formatStr = params.format ?? "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
      const includeOffset = params.include_offset !== false;
    
      // Use withCache wrapper instead of manual cache management
      return withCache(getCacheKey(timezone, formatStr, includeOffset), CacheTTL.CURRENT_TIME, () => {
        // Validate timezone
        if (!validateTimezone(timezone)) {
          throw new TimezoneError(`Invalid timezone: ${timezone}`, timezone);
        }
    
        const now = new Date();
    
        try {
          // Format time with appropriate options
          const formattedTime = formatTimeWithOptions(now, timezone, params, formatStr);
    
          // Build result
          const result = buildTimeResult(now, formattedTime, timezone);
    
          return result;
        } catch (error: unknown) {
          handleFormatError(error, params.format ?? formatStr);
        }
      });
    }
  • TypeScript interfaces defining the input parameters (GetCurrentTimeParams) and output structure (GetCurrentTimeResult) for the get_current_time tool.
    export interface GetCurrentTimeParams {
      timezone?: string;
      format?: string;
      include_offset?: boolean;
    }
    
    export interface GetCurrentTimeResult {
      time: string;
      timezone: string;
      offset: string;
      unix: number;
      iso: string;
    }
  • src/index.ts:42-58 (registration)
    Tool registration in TOOL_DEFINITIONS: defines the MCP tool name 'get_current_time', description, and JSON schema for input validation.
      name: 'get_current_time',
      description: 'Get current time in specified timezone with formatting options',
      inputSchema: {
        type: 'object' as const,
        properties: {
          timezone: {
            type: 'string' as const,
            description: 'IANA timezone (default: system timezone)',
          },
          format: { type: 'string' as const, description: 'date-fns format string' },
          include_offset: {
            type: 'boolean' as const,
            description: 'Include UTC offset (default: true)',
          },
        },
      },
    },
  • src/index.ts:258-259 (registration)
    Tool function mapping in TOOL_FUNCTIONS: associates the 'get_current_time' tool name with the getCurrentTime handler implementation.
    get_current_time: (params: unknown) =>
      getCurrentTime(params as Parameters<typeof getCurrentTime>[0]),
  • Helper function buildTimeResult constructs the standardized output object for the tool result, including formatted time, offset, Unix timestamp, and ISO string.
    export function buildTimeResult(
      now: Date,
      formattedTime: string,
      timezone: string
    ): GetCurrentTimeResult {
      // Get offset separately for the result object
      const offset = timezone === 'UTC' ? 'Z' : formatInTimeZone(now, timezone, 'XXX');
    
      return {
        time: formattedTime,
        timezone: timezone,
        offset: offset,
        unix: Math.floor(now.getTime() / 1000),
        iso: formatInTimeZone(now, timezone, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"),
      };
    }
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 mentions timezone and formatting options but fails to describe key behaviors such as error handling (e.g., invalid timezone), default behaviors (implied but not stated), or output characteristics (e.g., format of returned time). This leaves significant gaps for a tool with parameters.

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, efficient sentence that front-loads the core purpose without unnecessary words. Every part of the sentence contributes directly to understanding the tool's functionality, making it highly concise and well-structured.

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 tool's complexity (3 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the return value (e.g., string format), error cases, or behavioral nuances like default timezone handling. For a tool with multiple options and no structured output guidance, this leaves the agent under-informed.

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 description adds minimal value beyond the input schema, which has 100% coverage. It hints at 'specified timezone' and 'formatting options', but the schema already documents these parameters in detail. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't enhance parameter understanding.

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 with a specific verb ('Get') and resource ('current time'), and specifies key aspects like timezone and formatting. However, it doesn't explicitly differentiate from sibling tools like 'format_time' or 'convert_timezone', which prevents a perfect score.

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 like 'format_time' or 'convert_timezone'. It lacks context about prerequisites, exclusions, or comparative use cases, leaving the agent with minimal direction.

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