Skip to main content
Glama
RyanCardin15

LocalTides MCP Server

get_sun_times

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

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 execute handler function for the 'get_sun_times' tool. It invokes the sun service's getSunTimes method and handles text or JSON formatting of the response.
    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 the input parameters for the get_sun_times tool.
    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.')
    });
  • Registration of the 'get_sun_times' tool using server.addTool within the registerSunTools function.
    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');
        }
      }
    });
  • Core helper function implementing sun times calculation using the SunCalc library, handling date, location, timezone, and formatting.
    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
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe behavioral traits such as whether it's a read-only operation, potential rate limits, error handling, or what the output looks like (e.g., format details beyond the 'format' parameter). For a tool with no annotations, this is a significant gap in transparency.

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 without unnecessary words. It directly states the tool's function and scope, making it easy to parse. Every part of the sentence earns its place by conveying essential information.

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 the complexity (5 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on output format, error cases, or behavioral context. Without annotations or an output schema, the agent is left with incomplete information about what to expect from the tool's execution.

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%, meaning all parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain what 'other sun event times' includes or provide examples). With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 differentiate from sibling tools like 'get_sun_times_range' or 'get_next_sun_event', which limits it to a 4 rather than a 5.

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 events), nor does it specify any prerequisites or exclusions. This lack of comparative context leaves the agent without clear usage direction.

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-TidesAndCurrents-MCP'

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