Skip to main content
Glama
odgrim

MCP DateTime

by odgrim

get-time-in-timezone

Get the current time in any specified timezone for accurate scheduling and coordination across different regions.

Instructions

Get the current time in a specific timezone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneYesThe timezone to get the current time for

Implementation Reference

  • Handler function that validates the input timezone and returns the current time in that timezone using the helper function getCurrentTimeInTimezone, or an error if invalid.
    async (args) => {
      if (!isValidTimezone(args.timezone)) {
        return {
          content: [{ 
            type: "text", 
            text: `Error: Invalid timezone "${args.timezone}". Use the "list-timezones" tool to see available options.`
          }],
          isError: true
        };
      }
      
      return {
        content: [{ 
          type: "text", 
          text: `The current time in ${args.timezone} is ${getCurrentTimeInTimezone(args.timezone)}`
        }]
      };
    }
  • Input schema for the tool, defining a required 'timezone' string parameter.
    {
      timezone: z.string().describe("The timezone to get the current time for")
    },
  • src/server.ts:46-70 (registration)
    Registration of the 'get-time-in-timezone' tool on the MCP server, including name, description, schema, and handler.
    server.tool(
      "get-time-in-timezone",
      "Get the current time in a specific timezone",
      {
        timezone: z.string().describe("The timezone to get the current time for")
      },
      async (args) => {
        if (!isValidTimezone(args.timezone)) {
          return {
            content: [{ 
              type: "text", 
              text: `Error: Invalid timezone "${args.timezone}". Use the "list-timezones" tool to see available options.`
            }],
            isError: true
          };
        }
        
        return {
          content: [{ 
            type: "text", 
            text: `The current time in ${args.timezone} is ${getCurrentTimeInTimezone(args.timezone)}`
          }]
        };
      }
    );
  • Helper function to validate if a given timezone string is valid using Intl.DateTimeFormat.
    export function isValidTimezone(timezone: string): boolean {
      try {
        // Try to use the timezone with Intl.DateTimeFormat
        Intl.DateTimeFormat(undefined, { timeZone: timezone });
        return true;
      } catch (error) {
        return false;
      }
    }
  • Core helper function that computes and formats the current date-time in the specified timezone using Intl APIs, returning an ISO8601-like string.
    export function getCurrentTimeInTimezone(timezone: string): string {
      try {
        const date = new Date();
        
        // Create a formatter that includes the timezone
        const options: Intl.DateTimeFormatOptions = {
          timeZone: timezone,
          timeZoneName: 'short'
        };
        
        // Get the timezone offset from the formatter
        const formatter = new Intl.DateTimeFormat('en-US', options);
        const formattedDate = formatter.format(date);
        const timezonePart = formattedDate.split(' ').pop() || '';
        
        // Format the date in ISO8601 format with the timezone
        // First get the date in the specified timezone
        const tzFormatter = new Intl.DateTimeFormat('en-US', {
          timeZone: timezone,
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
          second: '2-digit',
          hour12: false,
          fractionalSecondDigits: 3
        });
        
        const parts = tzFormatter.formatToParts(date);
        const dateParts: Record<string, string> = {};
        
        parts.forEach(part => {
          if (part.type !== 'literal') {
            dateParts[part.type] = part.value;
          }
        });
        
        // Format as YYYY-MM-DDTHH:MM:SS.sss±HH:MM (ISO8601)
        const isoDate = `${dateParts.year}-${dateParts.month}-${dateParts.day}T${dateParts.hour}:${dateParts.minute}:${dateParts.second}.${dateParts.fractionalSecond || '000'}`;
        
        // For proper ISO8601, we need to add the timezone offset
        // We can use the Intl.DateTimeFormat to get the timezone offset
        const tzOffset = new Date().toLocaleString('en-US', { timeZone: timezone, timeZoneName: 'longOffset' }).split(' ').pop() || '';
        
        // Format the final ISO8601 string
        return `${isoDate}${tzOffset.replace('GMT', '')}`;
      } catch (error) {
        console.error(`Error formatting time for timezone ${timezone}:`, error);
        return 'Invalid timezone';
      }
    } 
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe how it behaves—for example, it doesn't mention error handling for invalid timezones, whether it returns formatted time or raw data, or any rate limits. This leaves significant gaps in understanding the tool's operation.

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, clear sentence that efficiently conveys the tool's purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete for a tool that performs a read operation. It doesn't explain what the return value looks like (e.g., formatted string, timestamp), error conditions, or how to handle invalid inputs. This leaves the agent with insufficient context to use the tool effectively.

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%, with the single parameter 'timezone' fully documented in the schema. The description adds no additional meaning beyond what the schema provides, such as examples of valid timezone formats (e.g., 'America/New_York') or constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

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 verb 'get' and the resource 'current time in a specific timezone', making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-current-time' (which might return time without timezone specification) or 'list-timezones' (which lists available timezones rather than getting time for one).

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 its siblings. It doesn't mention alternatives like 'get-current-time' for time without timezone or 'list-timezones' for browsing timezones, nor does it specify prerequisites such as needing a valid timezone identifier.

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

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