Skip to main content
Glama

get_current_conditions

Retrieve current weather conditions for any location by providing latitude and longitude coordinates.

Instructions

Get current weather conditions for a location.

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_current_conditions' tool. It validates coordinates, fetches weather points from NWS API, retrieves the nearest observation station, gets latest observations, and formats current conditions including temperature, humidity, wind, etc.
    @mcp.tool()
    async def get_current_conditions(latitude: float, longitude: float) -> str:
        """Get current weather conditions for a location.
    
        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."
    
        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 f"Unable to fetch weather data for coordinates ({latitude}, {longitude})."
    
        observation_url = points_data["properties"].get("observationStations")
        if not observation_url:
            return "No observation stations available for this location."
    
        # Get the nearest observation station
        stations_data = await make_nws_request(observation_url)
        if not stations_data or not stations_data.get("features"):
            return "No observation stations found for this location."
    
        station_id = stations_data["features"][0]["properties"]["stationIdentifier"]
        observations_url = f"{NWS_API_BASE}/stations/{station_id}/observations/latest"
        observations_data = await make_nws_request(observations_url)
    
        if not observations_data or "properties" not in observations_data:
            return "Unable to fetch current observations."
    
        props = observations_data["properties"]
        location_info = points_data["properties"].get("relativeLocation", {})
        location_str = f"{location_info.get('properties', {}).get('city', 'Unknown')}, {location_info.get('properties', {}).get('state', 'Unknown')}"
    
        temp = props.get("temperature", {}).get("value")
        temp_unit = "°C"
        if temp is not None:
            temp_f = (temp * 9/5) + 32
            temp_unit = f"°F ({temp:.1f}°C)"
    
        dewpoint = props.get("dewpoint", {}).get("value")
        humidity = props.get("relativeHumidity", {}).get("value")
        wind_speed = props.get("windSpeed", {}).get("value")
        wind_direction = props.get("windDirection", {}).get("value")
        pressure = props.get("barometricPressure", {}).get("value")
        visibility = props.get("visibility", {}).get("value")
        text_description = props.get("textDescription", "N/A")
    
        result = f"Current Conditions for {location_str}:\n\n"
        result += f"Temperature: {temp_f:.1f}{temp_unit}\n" if temp is not None else "Temperature: N/A\n"
        result += f"Conditions: {text_description}\n"
        result += f"Humidity: {humidity:.1f}%\n" if humidity is not None else ""
        result += f"Dewpoint: {dewpoint * 9/5 + 32:.1f}°F\n" if dewpoint is not None else ""
        result += f"Wind: {wind_speed * 2.237:.1f} mph from {wind_direction}°\n" if wind_speed is not None and wind_direction is not None else ""
        result += f"Pressure: {pressure / 100:.2f} hPa\n" if pressure is not None else ""
        result += f"Visibility: {visibility / 1609.34:.2f} miles\n" if visibility is not None else ""
    
        return result
  • weather.py:230-230 (registration)
    The @mcp.tool() decorator registers the get_current_conditions function as an MCP tool.
    @mcp.tool()
  • Helper function to validate input coordinates used by get_current_conditions.
    def validate_coordinates(latitude: float, longitude: float) -> bool:
        """Validate that coordinates are within valid ranges."""
        return -90 <= latitude <= 90 and -180 <= longitude <= 180
  • Helper function to make HTTP requests to NWS API endpoints, used multiple times in get_current_conditions.
    async def make_nws_request(url: str) -> dict[str, Any] | None:
        """Make a request to the NWS API with proper error handling."""
        headers = {
            "User-Agent": USER_AGENT,
            "Accept": "application/geo+json"
        }
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, headers=headers, timeout=30.0)
                response.raise_for_status()
                return response.json()
            except httpx.HTTPStatusError as e:
                if e.response.status_code == 404:
                    return None
                return None
            except (httpx.RequestError, httpx.TimeoutException):
                return None
            except Exception:
                return None
  • Docstring providing input schema description for the tool parameters.
    """Get current weather conditions for a location.
    
    Args:
        latitude: Latitude of the location (-90 to 90)
        longitude: Longitude of the location (-180 to 180)
    """

Tool Definition Quality

Score is being calculated. Check back soon.

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