Skip to main content
Glama
pinkpixel-dev

DateTime MCP Server

get_current_datetime

Retrieve the current date and time from the server, with optional timezone specification for accurate location-based timing.

Instructions

Get the current server date and time. Optionally specify a timezone (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). Defaults to server's configured timezone or UTC.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneNoOptional timezone identifier (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). If not provided, uses the server's default timezone or UTC.

Implementation Reference

  • The core handler logic for executing the 'get_current_datetime' tool. Validates timezone input, determines timezone to use, formats current date/time appropriately (ISO for UTC, date-fns-tz for others), and returns formatted text response in MCP content format.
    case "get_current_datetime": {
      try {
        const args = request.params.arguments as DateTimeToolArgs | undefined;
        const requestedTimezone = args?.timezone;
        
        // Determine which timezone to use
        let timezone: string;
        
        if (requestedTimezone) {
          // User provided a timezone parameter - validate it
          if (!isValidTimezone(requestedTimezone)) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Invalid timezone: ${requestedTimezone}. Please use a valid IANA timezone identifier (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo').`
            );
          }
          timezone = requestedTimezone;
        } else {
          // Use default timezone from server config or fallback
          timezone = getDefaultTimezone(serverConfig);
        }
        
        const now = new Date();
        
        // Format the datetime in the specified timezone
        let dateTimeString: string;
        let timezoneInfo: string;
        
        if (timezone === 'UTC') {
          // For UTC, use the standard ISO format
          dateTimeString = now.toISOString();
          timezoneInfo = 'UTC';
        } else {
          // For other timezones, use date-fns-tz to format in the timezone
          // Format as ISO-like string but with timezone offset
          const formatPattern = "yyyy-MM-dd'T'HH:mm:ss.SSSxxx";
          dateTimeString = formatInTimeZone(now, timezone, formatPattern);
          timezoneInfo = timezone;
        }
        
        // Create a user-friendly response
        const responseText = requestedTimezone 
          ? `The current date and time in ${timezoneInfo} is: ${dateTimeString}`
          : `The current date and time is: ${dateTimeString} (${timezoneInfo})`;
        
        return {
          content: [{
            type: "text",
            text: responseText
          }]
        };
      } catch (error) {
        // Re-throw McpErrors as-is
        if (error instanceof McpError) {
          throw error;
        }
        // Wrap other errors in an McpError
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to get current datetime: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • The JSON schema defining the input parameters for the 'get_current_datetime' tool: an optional 'timezone' string.
    inputSchema: {
      type: "object",
      properties: {
        timezone: {
          type: "string",
          description: "Optional timezone identifier (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). If not provided, uses the server's default timezone or UTC."
        }
      },
    }
  • src/index.ts:103-116 (registration)
    The tool definition object registered in the listTools handler, including name, description, and input schema.
      {
        name: "get_current_datetime",
        description: "Get the current server date and time. Optionally specify a timezone (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). Defaults to server's configured timezone or UTC.",
        inputSchema: {
          type: "object",
          properties: {
            timezone: {
              type: "string",
              description: "Optional timezone identifier (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). If not provided, uses the server's default timezone or UTC."
            }
          },
        }
      }
    ]
  • Helper function used by the handler to validate if a provided timezone identifier is supported.
    function isValidTimezone(timezone: string): boolean {
      try {
        // Use Intl.supportedValuesOf to get all supported timezones
        // This is more robust than try/catch with toLocaleString
        if (typeof Intl !== 'undefined' && 'supportedValuesOf' in Intl) {
          const supportedTimezones = Intl.supportedValuesOf('timeZone');
          return supportedTimezones.includes(timezone);
        }
        
        // Fallback: Try to create a date and format it in the timezone
        // If it throws, the timezone is invalid
        new Intl.DateTimeFormat('en', { timeZone: timezone }).format(new Date());
        return true;
      } catch {
        return false;
      }
    }
  • Helper function to determine the default timezone, prioritizing server config, then TZ env var, then UTC.
    function getDefaultTimezone(config?: ServerConfig): string {
      // Priority: config.defaultTimezone > process.env.TZ > 'UTC'
      if (config?.defaultTimezone && isValidTimezone(config.defaultTimezone)) {
        return config.defaultTimezone;
      }
      
      if (process.env.TZ && isValidTimezone(process.env.TZ)) {
        return process.env.TZ;
      }
      
      return 'UTC';
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool returns current datetime and defaults to server/UTC timezone, but lacks details on response format, precision, or error handling. It adds basic behavioral context but misses richer operational traits.

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 front-loaded with the core purpose, followed by an efficient explanation of the optional parameter. Both sentences are necessary and contribute directly to understanding, with zero wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one optional parameter and no output schema, the description adequately covers purpose and usage. However, without annotations or output details, it lacks information on return format (e.g., ISO string, object) and error cases, leaving minor gaps.

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 fully documents the single optional parameter. The description adds minimal value by restating the timezone examples and default behavior already in the schema, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get') and resource ('current server date and time'), with no siblings to differentiate from. It precisely defines what the tool does without being vague or tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use the optional timezone parameter, but since there are no sibling tools, it cannot specify alternatives or exclusions. It effectively guides usage within its isolated scope.

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/pinkpixel-dev/datetime-mcp'

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