weather_search
Find locations by name or query to enable weather data retrieval, supporting accurate weather information access through location identification.
Instructions
Search for locations matching query
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"q": "<q>"
},
"name": "weather_search"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Location query |
Implementation Reference
- server.py:195-200 (handler)Handler logic for the weather_search tool: extracts 'q' parameter, validates it, fetches data from search.json endpoint using the fetch helper, and serializes the result to JSON.
elif tool_name == "weather_search": q = arguments.get("q") if not q: raise ValueError("Location (q) is required") result = await fetch("search.json", {"q": q}) content = json.dumps(result, indent=2) - server.py:150-158 (schema)Input schema definition for the weather_search tool, specifying the required 'q' string parameter.
"inputSchema": { "type": "object", "properties": { "q": { "type": "string", "description": "Location query" } }, "required": ["q"] - server.py:147-160 (registration)Tool registration entry for weather_search in the tools/list response, including name, description, and schema.
{ "name": "weather_search", "description": "Search for locations matching query", "inputSchema": { "type": "object", "properties": { "q": { "type": "string", "description": "Location query" } }, "required": ["q"] } } - server.py:42-72 (helper)Shared helper function fetch() used by weather_search to make asynchronous HTTP requests to the WeatherAPI search endpoint, handling authentication, 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