future_flights_arrival_departure_schedule
Retrieve future flight arrival and departure schedules by specifying airport, airline, date, and number of flights using the Aviationstack MCP Server.
Instructions
MCP tool to get flight future arrival and departure schedule.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| airline_iata | Yes | ||
| airport_iata_code | Yes | ||
| date | Yes | ||
| number_of_flights | Yes | ||
| schedule_type | Yes |
Implementation Reference
- src/aviationstack_mcp/server.py:108-151 (handler)The handler function for the future_flights_arrival_departure_schedule tool. It is decorated with @mcp.tool(), fetches future flight data from the Aviationstack API endpoint /v1/flightsFuture, processes and samples the flights, and returns a JSON string of selected flight details.def future_flights_arrival_departure_schedule( airport_iata_code: str, schedule_type: str, airline_iata: str, date: str, number_of_flights: int ) -> str: """MCP tool to get flight future arrival and departure schedule.""" try: data = fetch_flight_data( 'http://api.aviationstack.com/v1/flightsFuture', { 'iataCode': airport_iata_code, 'type': schedule_type, 'airline_iata': airline_iata, 'date': date, } ) # date is in format YYYY-MM-DD data_list = data.get('data', []) number_of_flights = min(number_of_flights, len(data_list)) # Sample random flights from the data list sampled_flights = random.sample(data_list, number_of_flights) filtered_flights = [] for flight in sampled_flights: filtered_flights.append({ 'airline': flight.get('airline').get('name'), 'flight_number': flight.get('flight').get('iataNumber'), 'departure_scheduled_time': flight.get('departure').get('scheduledTime'), 'arrival_scheduled_time': flight.get('arrival').get('scheduledTime'), 'arrival_airport_code': flight.get('arrival').get('iataCode'), 'arrival_terminal': flight.get('arrival').get('terminal'), 'arrival_gate': flight.get('arrival').get('gate'), 'aircraft': flight.get('aircraft').get('modelText') }) return json.dumps(filtered_flights) if filtered_flights else ( f"No flights found for iata code '{airport_iata_code}'." ) except requests.RequestException as e: return f"Request error: {str(e)}" except (KeyError, ValueError, TypeError) as e: return f"Error fetching flight future schedule: {str(e)}"
- Helper utility function used by the tool to fetch data from the Aviationstack API, adding the API key and handling the HTTP request.def fetch_flight_data(url: str, params: dict) -> dict: """Fetch flight data from the AviationStack API.""" api_key = os.getenv('AVIATION_STACK_API_KEY') if not api_key: raise ValueError("AVIATION_STACK_API_KEY not set in environment.") params = {'access_key': api_key, **params} response = requests.get(url, params=params, timeout=10) response.raise_for_status() return response.json()