Skip to main content
Glama
DSado88

DateTime MCP Server

by DSado88

get_current_datetime

Retrieve the current date and time in various formats including ISO 8601, Unix timestamp, or human-readable output, with optional timezone specification.

Instructions

Get the current date and time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: 'iso' (ISO 8601), 'unix' (timestamp), 'human' (readable), or a custom format stringiso
timezoneNoTimezone (e.g., 'UTC', 'America/New_York'). Defaults to system timezonesystem

Implementation Reference

  • The switch case that implements the core logic for the 'get_current_datetime' tool, handling different output formats and returning the formatted current datetime.
    case "get_current_datetime": { const format = request.params.arguments?.format || "iso"; const timezone = request.params.arguments?.timezone || "system"; let result: string; if (format === "iso") { result = now.toISOString(); } else if (format === "unix") { result = Math.floor(now.getTime() / 1000).toString(); } else if (format === "human") { result = now.toString(); } else { result = formatDate(now, format as string); } return { content: [{ type: "text", text: result }] }; }
  • src/index.ts:25-43 (registration)
    Registration of the 'get_current_datetime' tool in the ListTools response, including its name, description, and input schema definition.
    { name: "get_current_datetime", description: "Get the current date and time", inputSchema: { type: "object", properties: { format: { type: "string", description: "Output format: 'iso' (ISO 8601), 'unix' (timestamp), 'human' (readable), or a custom format string", default: "iso" }, timezone: { type: "string", description: "Timezone (e.g., 'UTC', 'America/New_York'). Defaults to system timezone", default: "system" } } } },
  • Helper utility function for custom date and time formatting, used by the get_current_datetime handler and others.
    function formatDate(date: Date, format: string): string { const replacements: { [key: string]: string } = { 'YYYY': date.getFullYear().toString(), 'MM': (date.getMonth() + 1).toString().padStart(2, '0'), 'DD': date.getDate().toString().padStart(2, '0'), 'HH': date.getHours().toString().padStart(2, '0'), 'mm': date.getMinutes().toString().padStart(2, '0'), 'ss': date.getSeconds().toString().padStart(2, '0'), }; let result = format; for (const [key, value] of Object.entries(replacements)) { result = result.replace(new RegExp(key, 'g'), value); } return result; }
  • The input schema definition for the 'get_current_datetime' tool, specifying parameters for format and timezone.
    inputSchema: { type: "object", properties: { format: { type: "string", description: "Output format: 'iso' (ISO 8601), 'unix' (timestamp), 'human' (readable), or a custom format string", default: "iso" }, timezone: { type: "string", description: "Timezone (e.g., 'UTC', 'America/New_York'). Defaults to system timezone", default: "system" } } } },

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

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