get_precipitation_for
Retrieve precise 2-hour precipitation forecasts for any location using latitude and longitude coordinates, enabling accurate weather planning.
Instructions
Fetches precipitation data for the next 2 hours from Buienradar.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lat | Yes | ||
| lon | Yes |
Implementation Reference
- server.py:41-47 (handler)Main handler function implementing the tool logic: fetches raw precipitation data via API and formats it for output.async def get_precipitation_for(lat: float, lon: float) -> str: """Fetches precipitation data for the next 2 hours from Buienradar.""" data = await make_request(format_url(lat, lon)) if not data: return "Could not get precipitation data." return format_response(data)
- server.py:40-40 (registration)Registers the tool using FastMCP's @mcp.tool() decorator, which uses the function name 'get_precipitation_for'.@mcp.tool()
- server.py:11-14 (helper)Helper function to construct the Buienradar API URL from latitude and longitude.def format_url(lat: float, lon: float) -> str: lat = round(lat, 2) lon = round(lon, 2) return f"https://gadgets.buienradar.nl/data/raintext/?lat={lat}&lon={lon}"
- server.py:17-26 (helper)Async helper to perform HTTP GET request to the API and return raw text or None on error.async def make_request(url) -> str | None: headers = {"User-Agent": USER_AGENT} try: async with httpx.AsyncClient() as client: response = await client.get(url, headers=headers, timeout=30) response.raise_for_status() except Exception as e: return None return response.text
- server.py:29-37 (helper)Helper to parse raw API response and convert to formatted CSV-like string with mm per hour.def format_response(data: str) -> str: result = ["time, mm per hour"] for line in data.strip().split('\n'): intensity, time = line.split("|") intensity = int(intensity) mm_per_hour = round(10 ** ((intensity - 109) / 32), 1) result.append(f"{time}, {mm_per_hour}") return "\n".join(result)