Skip to main content
Glama

weather_forecast

Fetch accurate weather forecasts for 1-14 days using location details like city name, postal code, or coordinates. Ideal for planning activities and updates.

Instructions

Get weather forecast (1-14 days) for a location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoNumber of days (1-14)
qYesLocation query (city name, lat/lon, postal code, etc)

Implementation Reference

  • Handler logic for the weather_forecast tool: extracts and validates location (q) and days parameters, fetches forecast data from WeatherAPI, and prepares JSON response.
    elif tool_name == "weather_forecast": q = arguments.get("q") days = arguments.get("days", 1) if not q: raise ValueError("Location (q) is required") if days < 1 or days > 14: raise ValueError("Days must be between 1 and 14") result = await fetch("forecast.json", {"q": q, "days": days}) content = json.dumps(result, indent=2)
  • Input schema defining the parameters for weather_forecast: required 'q' (location string) and optional 'days' (integer, default 1).
    "inputSchema": { "type": "object", "properties": { "q": { "type": "string", "description": "Location query (city name, lat/lon, postal code, etc)" }, "days": { "type": "integer", "description": "Number of days (1-14)", "default": 1 } }, "required": ["q"] }
  • server.py:128-146 (registration)
    Registration of the weather_forecast tool in the tools/list MCP method response, including name, description, and schema.
    { "name": "weather_forecast", "description": "Get weather forecast (1-14 days) for a location", "inputSchema": { "type": "object", "properties": { "q": { "type": "string", "description": "Location query (city name, lat/lon, postal code, etc)" }, "days": { "type": "integer", "description": "Number of days (1-14)", "default": 1 } }, "required": ["q"] } },
  • Shared helper function fetch() that performs the HTTP request to WeatherAPI, handles errors, and returns JSON data. Used by the weather_forecast handler.
    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}")

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

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