get_moon_phases_range
Retrieve moon phase data for a specific date range and location using start and end dates, latitude, longitude, and preferred output format (JSON or text).
Instructions
Get moon phase information for a date range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | End date (YYYY-MM-DD format) | |
| format | No | Output format (json or text) | |
| latitude | No | Latitude for location-specific calculations | |
| longitude | No | Longitude for location-specific calculations | |
| start_date | Yes | Start date (YYYY-MM-DD format) |
Implementation Reference
- src/services/moon-phase-service.ts:55-82 (handler)Core handler function that computes moon phases over a date range by iterating daily and calling getMoonPhase.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; }
- src/tools/moon-tools.ts:35-55 (registration)Tool registration in FastMCP server, including name, description, input schema, and execute handler that wraps the service call and handles formatting/errors.server.addTool({ 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'); } } });
- src/interfaces/moon.ts:19-25 (schema)Zod schema defining the input parameters for the get_moon_phases_range tool.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)') });