get_station_data
Retrieve detailed weather data for a specific station by providing its unique identifier, sourced directly from Spain's State Meteorological Agency (AEMET) API.
Instructions
Obtain specific weather data for a weather station.
Args: station_id: Station identifier (e.g., "8416Y" for Valencia))
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| station_id | Yes |
Implementation Reference
- src/aemet_mcp/server.py:167-175 (handler)The handler function that executes the tool logic: constructs the AEMET observation API URL for the given station_id and calls the make_aemet_request helper to fetch and parse the data.async def get_station_data(station_id: str): """Obtain specific weather data for a weather station. Args: station_id: Station identifier (e.g., "8416Y" for Valencia)) """ url = f"{AEMET_API_BASE}/observacion/convencional/datos/estacion/{station_id}" return await make_aemet_request(url)
- src/aemet_mcp/server.py:166-166 (registration)The @mcp.tool() decorator registers the get_station_data function as an MCP tool with FastMCP.@mcp.tool()
- src/aemet_mcp/server.py:55-77 (helper)Supporting utility function that handles the HTTP requests to AEMET's two-step API process, including authentication and data parsing, used by get_station_data.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:168-172 (schema)Docstring providing the tool description and input schema: station_id as string (e.g., '8416Y'). FastMCP likely infers schema from signature."""Obtain specific weather data for a weather station. Args: station_id: Station identifier (e.g., "8416Y" for Valencia)) """