Skip to main content
Glama

weather_current

Get current weather conditions and air quality data for any location using city names, coordinates, or postal codes.

Instructions

Get current weather for a location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYesLocation query (city name, lat/lon, postal code, etc)
aqiNoInclude air quality data ('yes' or 'no')no

Implementation Reference

  • Handler logic for the 'weather_current' tool: parses arguments, validates location query, fetches current weather data using the shared 'fetch' helper, and formats the JSON response.
    if tool_name == "weather_current":
        q = arguments.get("q")
        aqi = arguments.get("aqi", "no")
        if not q:
            raise ValueError("Location (q) is required")
        result = await fetch("current.json", {"q": q, "aqi": aqi})
        content = json.dumps(result, indent=2)
  • Input schema defining the parameters for the 'weather_current' tool: required 'q' for location and optional 'aqi'.
    "inputSchema": {
        "type": "object",
        "properties": {
            "q": {
                "type": "string",
                "description": "Location query (city name, lat/lon, postal code, etc)"
            },
            "aqi": {
                "type": "string",
                "description": "Include air quality data ('yes' or 'no')",
                "default": "no"
            }
        },
        "required": ["q"]
    }
  • server.py:109-127 (registration)
    Registration of the 'weather_current' tool in the tools/list response, including name, description, and schema.
    {
        "name": "weather_current",
        "description": "Get current weather for a location",
        "inputSchema": {
            "type": "object",
            "properties": {
                "q": {
                    "type": "string",
                    "description": "Location query (city name, lat/lon, postal code, etc)"
                },
                "aqi": {
                    "type": "string",
                    "description": "Include air quality data ('yes' or 'no')",
                    "default": "no"
                }
            },
            "required": ["q"]
        }
    },
  • Shared 'fetch' utility function that performs HTTP requests to the WeatherAPI for all tools, including 'weather_current', handling API key, errors, and JSON parsing.
    async def fetch(endpoint: str, params: dict) -> dict:
        """Perform async GET to WeatherAPI and return JSON."""
        logger.debug(f"fetch() called with endpoint: {endpoint}, params: {params}")
        
        if not WEATHER_API_KEY:
            logger.error("Weather API key not set.")
            raise Exception("Weather API key not set.")
    
        params["key"] = WEATHER_API_KEY
        url = f"https://api.weatherapi.com/v1/{endpoint}"
        logger.info(f"Requesting {url}")
        
        async with httpx.AsyncClient() as client:
            logger.debug("HTTPx client created")
            try:
                resp = await client.get(url, params=params)
                logger.debug(f"HTTP response received: status={resp.status_code}")
                
                if resp.status_code != 200:
                    try:
                        error_data = resp.json()
                        detail = error_data.get("error", {}).get("message", resp.text)
                    except:
                        detail = resp.text
                    logger.error(f"WeatherAPI error {resp.status_code}: {detail}")
                    raise Exception(f"WeatherAPI error {resp.status_code}: {detail}")
                    
                data = resp.json()
                logger.debug(f"JSON parsing successful")
                logger.info(f"WeatherAPI success: {url}")
                return data
                
            except httpx.RequestError as e:
                logger.error(f"HTTPX request error: {e}")
                raise Exception(f"Request error: {e}")
            except Exception as e:
                logger.error(f"Unexpected error: {e}")
                raise Exception(f"Unexpected error: {e}")

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/first-it-consulting/weather-mcp-server'

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