get_weather_stations
Retrieve real-time meteorological observation data from weather stations across Portugal to access current weather conditions and measurements.
Instructions
Obter dados de observação das estações meteorológicas
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:446-497 (handler)The handler function that fetches weather station observations from the IPMA API, retrieves station info, selects the latest timestamp data, formats up to 15 stations' temperature, humidity, pressure, wind, and precipitation into a markdown text response.private async getWeatherStations() { try { const response = await fetch(`${this.baseUrl}/observation/meteorology/stations/observations.json`); const data = await response.json() as { [timestamp: string]: { [stationId: string]: StationObservation } }; // Obter também informações das estações const stationsResponse = await fetch(`${this.baseUrl}/observation/meteorology/stations/stations.json`); const stationsData = await stationsResponse.json() as StationInfo[]; const stationsInfo = stationsData.reduce((acc: any, station: StationInfo) => { acc[station.properties.idEstacao] = station.properties.localEstacao; return acc; }, {}); let result = "🌡️ **Observações das Estações Meteorológicas**\n\n"; // Pegar apenas as observações mais recentes (última timestamp) const timestamps = Object.keys(data); const latestTimestamp = timestamps[timestamps.length - 1]; const latestObservations = data[latestTimestamp]; result += `🕐 Observações de: ${latestTimestamp}\n\n`; // Mostrar apenas as primeiras 15 estações para não exceder limites const stationIds = Object.keys(latestObservations).slice(0, 15); stationIds.forEach((stationId: string) => { const obs = latestObservations[stationId]; const stationName = stationsInfo[stationId] || `Estação ${stationId}`; result += `📍 **${stationName}**\n`; if (obs.temperatura > -99) result += `🌡️ Temperatura: ${obs.temperatura}°C\n`; if (obs.humidade > -99) result += `💧 Humidade: ${obs.humidade}%\n`; if (obs.pressao > -99) result += `📊 Pressão: ${obs.pressao} hPa\n`; if (obs.intensidadeVento > -99) result += `💨 Vento: ${obs.intensidadeVento} m/s\n`; if (obs.precAcumulada > -99) result += `🌧️ Precipitação: ${obs.precAcumulada} mm\n`; result += "\n"; }); return { content: [ { type: "text", text: result } ] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Erro ao obter dados das estações: ${errorMessage}`); } }
- src/index.ts:181-188 (registration)Registration of the 'get_weather_stations' tool in the ListToolsRequestSchema handler, including name, description, and empty input schema (no parameters required).{ name: "get_weather_stations", description: "Obter dados de observação das estações meteorológicas", inputSchema: { type: "object", properties: {} } },
- src/index.ts:217-218 (registration)Dispatch case in the CallToolRequestSchema handler that routes calls to the getWeatherStations method.case "get_weather_stations": return await this.getWeatherStations();
- src/index.ts:184-187 (schema)Input schema for the tool: empty object (no required parameters).inputSchema: { type: "object", properties: {} }
- src/index.ts:72-78 (helper)TypeScript interfaces used by the handler for station observations and station metadata.interface StationObservation { temperatura: number; humidade: number; pressao: number; intensidadeVento: number; precAcumulada: number; }