monthly_climate_data
Retrieve monthly climate summaries from any AEMET weather station by providing station ID, year, and month. Get temperature, precipitation, and other climatological values.
Instructions
Retrieve monthly climatological data for a specific weather station.
Args: station_id: Weather station identifier (e.g., "3195" for Madrid Retiro). year: Year (YYYY). month: Month (1-12).
Returns: A JSON with the monthly climate summary.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| station_id | Yes | ||
| year | Yes | ||
| month | Yes |
Implementation Reference
- src/aemet_mcp/server.py:263-277 (handler)The tool handler function. It takes a station_id, year, and month, builds the AEMET API URL for monthly/annual climatological data, and delegates to the make_aemet_request helper.
@mcp.tool() async def monthly_climate_data(station_id: str, year: int, month: int): """Retrieve monthly climatological data for a specific weather station. Args: station_id: Weather station identifier (e.g., "3195" for Madrid Retiro). year: Year (YYYY). month: Month (1-12). Returns: A JSON with the monthly climate summary. """ url = f"{AEMET_API_BASE}/valores/climatologicos/mensualesanuales/datos/anioini/{year}/aniofin/{year}/estacion/{station_id}" return await make_aemet_request(url) - src/aemet_mcp/server.py:263-263 (registration)The @mcp.tool() decorator registers monthly_climate_data as an MCP tool on the FastMCP server instance.
@mcp.tool() - src/aemet_mcp/server.py:55-77 (helper)Shared helper used by the handler. It makes an authenticated GET request to AEMET's API, follows the redirect to the actual data URL, decodes the response as latin1, and returns parsed JSON.
async def make_aemet_request(url: str) -> dict[str, Any] | list[Any] | None: logger.info(f"make_aemet_request") headers = { "api_key": API_KEY, "Accept": "application/json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() data_info = response.json() if data_info.get("estado") == 200: data_url = data_info.get("datos") if data_url: data_response = await client.get(data_url, timeout=30.0) data_response.raise_for_status() content = data_response.content.decode('latin1') return json.loads(content) return None except Exception as e: logger.error(f"Error connecting to AEMET: {str(e)}") return None - src/aemet_mcp/server.py:265-274 (schema)The docstring acts as the schema/description for the MCP tool, specifying that station_id (str), year (int), and month (int) are the inputs.
"""Retrieve monthly climatological data for a specific weather station. Args: station_id: Weather station identifier (e.g., "3195" for Madrid Retiro). year: Year (YYYY). month: Month (1-12). Returns: A JSON with the monthly climate summary. """