getFutureWeatherByAirport
Retrieve 3-day weather forecasts for airports using IATA 3-letter codes (e.g., PEK, SHA) to plan travel or operations efficiently.
Instructions
Get airport future weather for 3days (today、tomorrow、the day after tomorrow) by airport IATA 3-letter code. Airport codes should be IATA 3-letter codes (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| airport | Yes | Airport IATA 3-letter code (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"airport": {
"description": "Airport IATA 3-letter code (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei)",
"pattern": "^[A-Z]{3}$",
"type": "string"
}
},
"required": [
"airport"
],
"type": "object"
}
Implementation Reference
- dist/index.js:186-209 (registration)Registration of the 'getFutureWeatherByAirport' tool, including description, input schema using Zod, and the handler function that delegates to flightService.getAirportWeatherserver.tool('getFutureWeatherByAirport', 'Get airport future weather for 3days (today、tomorrow、the day after tomorrow) by airport IATA 3-letter code. Airport codes should be IATA 3-letter codes (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei).', { airport: z.string() .regex(/^[A-Z]{3}$/) .describe("Airport IATA 3-letter code (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei)") }, async ({ airport }) => { try { const weather = await flightService.getAirportWeather(airport); return { content: [ { type: "text", text: JSON.stringify(weather, null, 2) } ] }; } catch (error) { console.error('Error getting airport weather:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/index.js:187-189 (schema)Input schema validating the 'airport' parameter as a 3-letter IATA code using Zodairport: z.string() .regex(/^[A-Z]{3}$/) .describe("Airport IATA 3-letter code (e.g. PEK for Beijing, SHA for Shanghai, CAN for Guangzhou, HFE for Hefei)")
- dist/index.js:190-209 (handler)MCP tool handler function that invokes the service method and formats the response}, async ({ airport }) => { try { const weather = await flightService.getAirportWeather(airport); return { content: [ { type: "text", text: JSON.stringify(weather, null, 2) } ] }; } catch (error) { console.error('Error getting airport weather:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/services/openalService.js:56-61 (handler)Core implementation of the weather retrieval: calls the 'futureAirportWeather' API endpoint with airport codeasync getAirportWeather(airport) { return this.makeRequest('futureAirportWeather', { "code": airport, "type": "1" }); }
- dist/services/openalService.js:3-21 (helper)Generic helper method for making POST requests to the backend API with endpoint and paramsasync makeRequest(endpoint, params) { const url = new URL(config.api.baseUrl); const request_body = { endpoint: endpoint, params: params }; const response = await fetch(url.toString(), { method: 'post', headers: { 'X-VARIFLIGHT-KEY': config.api.apiKey || '', 'Content-Type': 'application/json', }, body: JSON.stringify(request_body), }); if (!response.ok) { throw new Error(`API request failed: ${response.status} ${response.statusText}`); } return response.json(); }