Skip to main content
Glama
SergeSerb2

Time & Location MCP Server

by SergeSerb2

get_current_time

Retrieve the current date and time in your local timezone using system-detected settings. Ideal for applications needing accurate time data without manual configuration.

Instructions

Get the current date and time in your local timezone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler for the 'get_current_time' tool. It gets the current date/time using Intl.DateTimeFormat in the detected local timezone (TIMEZONE), with fallback, and returns formatted time, ISO, Unix timestamp, and UTC offset as JSON.
    case 'get_current_time': { const now = new Date(); let localTime; try { localTime = 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, weekday: 'long', timeZoneName: 'long' }).format(now); } catch (e) { // Fallback if timezone is invalid localTime = now.toString(); } const isoString = now.toISOString(); return { content: [ { type: 'text', text: JSON.stringify({ current_time: localTime, timezone: TIMEZONE, iso_time: isoString, unix_timestamp: Math.floor(now.getTime() / 1000), utc_offset: new Date().getTimezoneOffset() }, null, 2), }, ], }; }
  • server.js:118-125 (registration)
    Registration of the 'get_current_time' tool in the ListTools response, specifying name, description (no input parameters).
    { name: 'get_current_time', description: 'Get the current date and time in your local timezone', inputSchema: { type: 'object', properties: {}, }, },
  • Input schema for 'get_current_time': an empty object (no parameters).
    inputSchema: { type: 'object', properties: {}, },
  • Helper function detectTimezone() used to initialize the TIMEZONE variable for the handler.
    function detectTimezone() { // Try environment variable first if (process.env.TZ) { return process.env.TZ; } // Try reading /etc/timezone (Linux) try { const tz = readFileSync('/etc/timezone', 'utf8').trim(); if (tz) return tz; } catch (e) {} // Try reading /etc/localtime symlink (Linux/Mac) try { const result = execSync('readlink /etc/localtime', { encoding: 'utf8' }).trim(); const match = result.match(/zoneinfo\/(.+)$/); if (match) return match[1]; } catch (e) {} // Default fallback return 'UTC'; }
  • Async initializer that sets TIMEZONE, potentially overriding from location detection.
    (async () => { LOCATION = await detectLocation(); if (LOCATION.timezone && LOCATION.timezone !== 'Unknown') { TIMEZONE = LOCATION.timezone; } console.error(`Detected timezone: ${TIMEZONE}`); console.error(`Detected location: ${LOCATION.city}, ${LOCATION.province}, ${LOCATION.country}`); })();

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/SergeSerb2/time_mcp'

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