Skip to main content
Glama

get_forecast

Retrieve weather forecasts for specific locations by providing latitude and longitude coordinates.

Instructions

Get weather forecast for a location using coordinates.

Args:
    latitude: Latitude of the location (-90 to 90)
    longitude: Longitude of the location (-180 to 180)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'get_forecast' tool. It validates coordinates, fetches forecast data using a helper, formats the next 10 forecast periods including temperature, wind, humidity, precipitation, and detailed forecast, and returns a formatted string.
    @mcp.tool()
    async def get_forecast(latitude: float, longitude: float) -> str:
        """Get weather forecast for a location using coordinates.
    
        Args:
            latitude: Latitude of the location (-90 to 90)
            longitude: Longitude of the location (-180 to 180)
        """
        if not validate_coordinates(latitude, longitude):
            return "Error: Invalid coordinates. Latitude must be between -90 and 90, longitude between -180 and 180."
    
        forecast_data = await get_forecast_data(latitude, longitude)
        
        if not forecast_data:
            return f"Unable to fetch forecast data for coordinates ({latitude}, {longitude}). The location may be outside NWS coverage area (US only)."
    
        periods = forecast_data["properties"]["periods"]
        location = forecast_data.get("_location", {})
        location_str = f"{location.get('city', 'Unknown')}, {location.get('state', 'Unknown')}"
        
        forecasts = []
        for period in periods[:10]:  # Show next 10 periods (5 days)
            forecast = f"""
    {period['name']}:
      Temperature: {period['temperature']}°{period['temperatureUnit']}
      Wind: {period['windSpeed']} {period['windDirection']}
      {f"Humidity: {period.get('relativeHumidity', {}).get('value', 'N/A')}%" if period.get('relativeHumidity') else ""}
      {f"Precipitation: {period.get('probabilityOfPrecipitation', {}).get('value', 0)}%" if period.get('probabilityOfPrecipitation') else ""}
      Forecast: {period['detailedForecast']}
    """
            forecasts.append(forecast)
    
        return f"Weather Forecast for {location_str}:\n" + "\n---\n".join(forecasts)
  • Helper function that fetches raw forecast data from the National Weather Service (NWS) API for given coordinates, adds location information, and returns the data or None on error.
    async def get_forecast_data(latitude: float, longitude: float) -> dict[str, Any] | None:
        """Get forecast data for coordinates. Returns None on error."""
        if not validate_coordinates(latitude, longitude):
            return None
        
        points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
        points_data = await make_nws_request(points_url)
    
        if not points_data or "properties" not in points_data:
            return None
    
        forecast_url = points_data["properties"].get("forecast")
        if not forecast_url:
            return None
    
        forecast_data = await make_nws_request(forecast_url)
        if not forecast_data or "properties" not in forecast_data:
            return None
    
        # Add location info to the forecast data
        location_info = points_data["properties"].get("relativeLocation", {})
        forecast_data["_location"] = {
            "city": location_info.get("properties", {}).get("city", "Unknown"),
            "state": location_info.get("properties", {}).get("state", "Unknown")
        }
        
        return forecast_data
  • weather.py:158-158 (registration)
    The @mcp.tool() decorator registers the get_forecast function as an MCP tool.
    @mcp.tool()
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 the tool gets a forecast but doesn't cover key aspects like whether it's read-only, what data format is returned, potential rate limits, error handling, or authentication needs. This leaves significant gaps in understanding the tool's behavior beyond basic functionality.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded, with the core purpose stated first followed by parameter details. It avoids unnecessary fluff, but the parameter explanations could be slightly more integrated into the flow rather than listed as 'Args:'.

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 tool's moderate complexity (2 required parameters) and the presence of an output schema, the description is partially complete. It covers the purpose and parameters adequately but lacks usage guidelines and behavioral details. The output schema mitigates the need to describe return values, but other gaps remain.

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

Parameters4/5

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

The description adds meaningful context beyond the input schema, which has 0% description coverage. It specifies that latitude ranges from -90 to 90 and longitude from -180 to 180, clarifying valid coordinate ranges that aren't in the schema. However, it doesn't explain units (e.g., degrees) or precision, leaving minor gaps.

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 weather forecast for a location using coordinates.' It specifies the verb ('Get'), resource ('weather forecast'), and method ('using coordinates'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'get_forecast_by_city' or 'get_current_conditions', keeping it from a perfect score.

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_forecast_by_city' (which might use city names instead of coordinates) or 'get_current_conditions' (which might provide current rather than forecasted weather), leaving the agent without context for tool selection.

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

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/zayedansari2/MCP_WeatherServer'

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