Skip to main content
Glama
RyanCardin15

noaa-tidesandcurrents-mcp

get_moon_phases_range

Retrieve moon phase data for a specified date range and location using latitude and longitude. Output in JSON or text format for precise astronomical insights.

Instructions

Get moon phase information for a date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_dateYesEnd date (YYYY-MM-DD format)
formatNoOutput format (json or text)
latitudeNoLatitude for location-specific calculations
longitudeNoLongitude for location-specific calculations
start_dateYesStart date (YYYY-MM-DD format)

Implementation Reference

  • Core handler function that computes moon phases for a range of dates by iterating day-by-day and delegating to getMoonPhase method using the SunCalc library.
    getMoonPhasesRange(params: MoonPhasesRangeParams): MoonPhaseInfo[] {
      const startDate = new Date(params.start_date);
      const endDate = new Date(params.end_date);
      
      if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
        throw new Error('Invalid date format. Please use YYYY-MM-DD format.');
      }
      
      if (startDate > endDate) {
        throw new Error('Start date must be before end date.');
      }
      
      const result: MoonPhaseInfo[] = [];
      const currentDate = new Date(startDate);
      
      while (currentDate <= endDate) {
        result.push(this.getMoonPhase({
          date: currentDate.toISOString().split('T')[0],
          latitude: params.latitude,
          longitude: params.longitude
        }));
        
        // Move to next day
        currentDate.setDate(currentDate.getDate() + 1);
      }
      
      return result;
    }
  • Input schema definition using Zod for validating tool parameters including start_date, end_date, optional location and format.
    export const MoonPhasesRangeParamsSchema = z.object({
      start_date: z.string().describe('Start date (YYYY-MM-DD format)'),
      end_date: z.string().describe('End date (YYYY-MM-DD format)'),
      latitude: z.number().min(-90).max(90).optional().describe('Latitude for location-specific calculations'),
      longitude: z.number().min(-180).max(180).optional().describe('Longitude for location-specific calculations'),
      format: z.enum(['json', 'text']).optional().describe('Output format (json or text)')
    });
    
    export type MoonPhasesRangeParams = z.infer<typeof MoonPhasesRangeParamsSchema>;
  • MCP tool registration that binds the tool name to the service handler, provides description, input schema, and a wrapper execute function for formatting output as text or JSON.
      name: 'get_moon_phases_range',
      description: 'Get moon phase information for a date range',
      parameters: MoonPhasesRangeParamsSchema,
      execute: async (params) => {
        try {
          const results = moonPhaseService.getMoonPhasesRange(params);
          if (params.format === 'text') {
            return results.map(result => 
              `${result.date}: ${result.phaseName} (${(result.illumination * 100).toFixed(1)}% illuminated)`
            ).join('\n');
          }
          return JSON.stringify(results);
        } catch (error) {
          if (error instanceof Error) {
            throw new Error(`Failed to get moon phases: ${error.message}`);
          }
          throw new Error('Failed to get moon phases');
        }
      }
    });

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