Skip to main content
Glama
DSado88

DateTime MCP Server

by DSado88

get_current_datetime

Retrieve the current date and time in ISO, Unix, human-readable, or custom formats, with optional timezone specification for accurate results.

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 handler that executes the get_current_datetime tool logic, formatting the current date and time based on the provided format and timezone parameters.
    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 }] }; }
  • Input schema defining the parameters for the get_current_datetime tool (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" } } }
  • src/index.ts:25-43 (registration)
    Registration of the get_current_datetime tool in the ListTools response, including name, description, and schema.
    { 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 formatDate used by the handler for custom date formatting.
    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; }

Other Tools

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

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