Skip to main content
Glama

get_sun_position

Calculate the sun's position for a specific date, time, and location. Input latitude, longitude, and format (JSON/text) to retrieve accurate solar data.

Instructions

Get sun position information for a specific date, time, and location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoDate to get sun position for (YYYY-MM-DD format). Defaults to current date.
formatNoOutput format (json or text)
latitudeYesLatitude for location-specific calculations
longitudeYesLongitude for location-specific calculations
timeNoTime to get sun position for (HH:MM:SS format). Defaults to current time.

Implementation Reference

  • The MCP tool handler for 'get_sun_position', which calls the sun service and handles text/JSON output formatting and error handling.
    server.addTool({ name: 'get_sun_position', description: 'Get sun position information for a specific date, time, and location', parameters: SunPositionParamsSchema, execute: async (params) => { try { const result = sunService.getSunPosition(params); if (params.format === 'text') { let text = `Sun position for ${result.date} ${result.time} at latitude ${params.latitude}, longitude ${params.longitude}:\n`; text += `Azimuth: ${result.azimuth.toFixed(2)}°\n`; text += `Altitude: ${result.altitude.toFixed(2)}°\n`; text += `Declination: ${result.declination.toFixed(2)}°\n`; text += `Right Ascension: ${result.rightAscension.toFixed(2)}h\n`; return text; } return JSON.stringify(result); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get sun position: ${error.message}`); } throw new Error('Failed to get sun position'); } } });
  • Zod schema defining input parameters for the get_sun_position tool, including date, time, location, and format.
    export const SunPositionParamsSchema = z.object({ date: z.string().optional().describe('Date to get sun position for (YYYY-MM-DD format). Defaults to current date.'), time: z.string().optional().describe('Time to get sun position for (HH:MM:SS format). Defaults to current time.'), latitude: z.number().min(-90).max(90).describe('Latitude for location-specific calculations'), longitude: z.number().min(-180).max(180).describe('Longitude for location-specific calculations'), format: z.enum(['json', 'text']).optional().describe('Output format (json or text)') }); export type SunPositionParams = z.infer<typeof SunPositionParamsSchema>;
  • Calls registerSunTools to register sun tools including get_sun_position to the MCP server.
    registerSunTools(server, sunService);
  • Core implementation of sun position calculation using SunCalc library, including position retrieval and approximate equatorial coordinates computation.
    getSunPosition(params: SunPositionParams): SunPositionInfo { const date = params.date ? new Date(params.date) : new Date(); const time = params.time; const { latitude, longitude } = params; // Set the time if provided if (time) { const [hours, minutes, seconds] = time.split(':').map(Number); if (!isNaN(hours) && !isNaN(minutes) && (!seconds || !isNaN(seconds))) { date.setHours(hours, minutes, seconds || 0, 0); } else { throw new Error('Invalid time format. Please use HH:MM:SS format.'); } } // Get sun position data const position = SunCalc.getPosition(date, latitude, longitude); // Calculate right ascension and declination (approximate values) // Note: These are approximate calculations and may not be precise const equatorialCoords = this.calculateEquatorialCoordinates(date, position.azimuth, position.altitude, latitude, longitude); return { date: date.toISOString().split('T')[0], time: date.toISOString().split('T')[1].split('.')[0], azimuth: position.azimuth * (180 / Math.PI), altitude: position.altitude * (180 / Math.PI), declination: equatorialCoords.declination, rightAscension: equatorialCoords.rightAscension }; }

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/RyanCardin15/NOAA'

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