future_flights_arrival_departure_schedule
Retrieve scheduled flight arrivals and departures for specific airports, airlines, and dates to plan travel and monitor flight operations.
Instructions
MCP tool to get flight future arrival and departure schedule.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| airport_iata_code | Yes | ||
| schedule_type | Yes | ||
| airline_iata | Yes | ||
| date | Yes | ||
| number_of_flights | Yes |
Implementation Reference
- src/aviationstack_mcp/server.py:107-151 (handler)The main handler function for the 'future_flights_arrival_departure_schedule' tool. It fetches future flight data from AviationStack API using the provided parameters, samples random flights, extracts relevant schedule information, and returns it as JSON. The @mcp.tool() decorator registers this function as an MCP tool.@mcp.tool() 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 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()