Skip to main content
Glama
SergeSerb2

Time & Location MCP Server

by SergeSerb2

get_location

Retrieve your current location using IP geolocation or system settings. Ideal for applications requiring accurate place-based data without manual input.

Instructions

Get your current location based on IP geolocation or system settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler for the 'get_location' tool call, which awaits location detection if necessary and returns the location data as JSON.
    case 'get_location': { // Wait for location if not yet loaded if (!LOCATION) { LOCATION = await detectLocation(); } return { content: [ { type: 'text', text: JSON.stringify(LOCATION, null, 2), }, ], }; }
  • server.js:126-133 (registration)
    Registration of the 'get_location' tool in the ListTools response, including name, description, and empty input schema.
    { name: 'get_location', description: 'Get your current location based on IP geolocation or system settings', inputSchema: { type: 'object', properties: {}, }, },
  • Core helper function that fetches location data via IP geolocation from ipapi.co/json, with fallbacks to environment variables, providing city, region, country, coordinates, timezone, and IP.
    async function detectLocation() { return new Promise((resolve) => { https.get('https://ipapi.co/json/', (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { try { const locationData = JSON.parse(data); resolve({ city: locationData.city || 'Unknown', province: locationData.region || 'Unknown', country: locationData.country_name || 'Unknown', country_code: locationData.country || 'Unknown', coordinates: { latitude: locationData.latitude || 0, longitude: locationData.longitude || 0 }, timezone: locationData.timezone || detectTimezone(), ip: locationData.ip || 'Unknown' }); } catch (e) { // Fallback to environment variables or defaults resolve({ city: process.env.CITY || 'Unknown', province: process.env.PROVINCE || 'Unknown', country: process.env.COUNTRY || 'Unknown', coordinates: { latitude: parseFloat(process.env.LATITUDE) || 0, longitude: parseFloat(process.env.LONGITUDE) || 0 }, timezone: detectTimezone() }); } }); }).on('error', () => { // Fallback to environment variables or defaults resolve({ city: process.env.CITY || 'Unknown', province: process.env.PROVINCE || 'Unknown', country: process.env.COUNTRY || 'Unknown', coordinates: { latitude: parseFloat(process.env.LATITUDE) || 0, longitude: parseFloat(process.env.LONGITUDE) || 0 }, timezone: detectTimezone() }); }); }); }
  • Supporting helper function to detect the system timezone from environment, /etc/timezone, or /etc/localtime symlink, used by detectLocation.
    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'; }

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