Skip to main content
Glama
RyanCardin15

noaa-tidesandcurrents-mcp

get_sun_times

Retrieve sunrise, sunset, and other sun event times for a specific date and location using latitude, longitude, and optional timezone. Outputs in JSON or text format.

Instructions

Get sun rise/set and other sun event times for a specific date and location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoDate to get sun times for (YYYY-MM-DD format). Defaults to current date.
formatNoOutput format (json or text)
latitudeYesLatitude for location-specific calculations
longitudeYesLongitude for location-specific calculations
timezoneNoTimezone for the results. Defaults to UTC.

Implementation Reference

  • The MCP tool's execute handler: calls sunService.getSunTimes(params), formats output as text or JSON based on params.format, handles errors.
    execute: async (params) => {
      try {
        const result = sunService.getSunTimes(params);
        if (params.format === 'text') {
          let text = `Sun times for ${result.date} at latitude ${params.latitude}, longitude ${params.longitude}:\n`;
          text += `Sunrise: ${result.sunrise || 'N/A'}\n`;
          text += `Sunset: ${result.sunset || 'N/A'}\n`;
          text += `Day length: ${Math.floor(result.dayLength / 60)}h ${Math.round(result.dayLength % 60)}m\n`;
          text += `Solar noon: ${result.solarNoon || 'N/A'}\n`;
          text += `Dawn: ${result.dawn || 'N/A'}\n`;
          text += `Dusk: ${result.dusk || 'N/A'}\n`;
          return text;
        }
        return JSON.stringify(result);
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get sun times: ${error.message}`);
        }
        throw new Error('Failed to get sun times');
      }
    }
  • Zod schema defining input parameters for the get_sun_times tool, including date, location, format, and timezone.
    export const SunTimesParamsSchema = z.object({
      date: z.string().optional().describe('Date to get sun times for (YYYY-MM-DD format). Defaults to current date.'),
      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)'),
      timezone: z.string().optional().describe('Timezone for the results. Defaults to UTC.')
    });
    
    export type SunTimesParams = z.infer<typeof SunTimesParamsSchema>;
  • Registers the 'get_sun_times' tool with the FastMCP server using server.addTool, specifying name, description, parameters schema, and execute handler.
    server.addTool({
      name: 'get_sun_times',
      description: 'Get sun rise/set and other sun event times for a specific date and location',
      parameters: SunTimesParamsSchema,
      execute: async (params) => {
        try {
          const result = sunService.getSunTimes(params);
          if (params.format === 'text') {
            let text = `Sun times for ${result.date} at latitude ${params.latitude}, longitude ${params.longitude}:\n`;
            text += `Sunrise: ${result.sunrise || 'N/A'}\n`;
            text += `Sunset: ${result.sunset || 'N/A'}\n`;
            text += `Day length: ${Math.floor(result.dayLength / 60)}h ${Math.round(result.dayLength % 60)}m\n`;
            text += `Solar noon: ${result.solarNoon || 'N/A'}\n`;
            text += `Dawn: ${result.dawn || 'N/A'}\n`;
            text += `Dusk: ${result.dusk || 'N/A'}\n`;
            return text;
          }
          return JSON.stringify(result);
        } catch (error) {
          if (error instanceof Error) {
            throw new Error(`Failed to get sun times: ${error.message}`);
          }
          throw new Error('Failed to get sun times');
        }
      }
    });
  • SunService.getSunTimes method: computes detailed sun event times using SunCalc.getTimes, handles time formatting and timezone, calculates day length.
    getSunTimes(params: SunTimesParams): SunTimesInfo {
      const date = params.date ? new Date(params.date) : new Date();
      const { latitude, longitude } = params;
      
      // Get sun times data
      const sunTimes = SunCalc.getTimes(date, latitude, longitude);
      
      // Format times or return null if not available
      const formatTime = (time: Date | null): string | null => {
        if (!time || isNaN(time.getTime())) return null;
        
        if (params.timezone) {
          try {
            return time.toLocaleTimeString('en-US', { timeZone: params.timezone });
          } catch (error) {
            // If timezone is invalid, fall back to ISO string
            console.warn(`Invalid timezone: ${params.timezone}. Using UTC.`);
          }
        }
        
        return time.toISOString();
      };
      
      // Calculate day length in minutes
      const sunrise = sunTimes.sunrise;
      const sunset = sunTimes.sunset;
      let dayLength = 0;
      
      if (sunrise && sunset && !isNaN(sunrise.getTime()) && !isNaN(sunset.getTime())) {
        dayLength = (sunset.getTime() - sunrise.getTime()) / (60 * 1000);
      }
      
      return {
        date: date.toISOString().split('T')[0],
        sunrise: formatTime(sunTimes.sunrise),
        sunset: formatTime(sunTimes.sunset),
        solarNoon: formatTime(sunTimes.solarNoon),
        dawn: formatTime(sunTimes.dawn),
        dusk: formatTime(sunTimes.dusk),
        nightStart: formatTime(sunTimes.night),
        nightEnd: formatTime(sunTimes.nightEnd),
        goldenHourStart: formatTime(sunTimes.goldenHour),
        goldenHourEnd: formatTime(sunTimes.goldenHourEnd),
        nauticalDawn: formatTime(sunTimes.nauticalDawn),
        nauticalDusk: formatTime(sunTimes.nauticalDusk),
        astronomicalDawn: formatTime(sunTimes.astronomicalDawn),
        astronomicalDusk: formatTime(sunTimes.astronomicalDusk),
        dayLength
      };
    }
  • Top-level registration call to registerSunTools which includes the get_sun_times tool.
    registerMoonTools(server, moonPhaseService);
    registerSunTools(server, sunService);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states what the tool does but doesn't disclose behavioral traits like rate limits, authentication needs, error handling, or what 'other sun event times' includes. For a tool with no annotations, this leaves significant gaps in understanding how it behaves operationally.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. Every word earns its place with no redundancy or unnecessary elaboration, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is minimally complete for a read-only tool. It specifies the action and inputs but lacks details on output format (beyond parameter hints), error cases, or behavioral context. For a tool with 5 parameters and no structured output documentation, it should provide more guidance on what to expect.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't clarify 'other sun event times' or provide examples). Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get sun rise/set and other sun event times for a specific date and location'. It specifies the verb ('Get'), resource ('sun rise/set and other sun event times'), and scope ('for a specific date and location'). However, it doesn't explicitly distinguish this tool from its sibling 'get_sun_times_range', which might handle date ranges rather than single dates.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_sun_times_range' (for date ranges) or 'get_next_sun_event' (for next event), nor does it specify prerequisites or exclusions. Usage is implied by the description but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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