Skip to main content
Glama

flights_with_airline

Retrieve real-time flight data for a specific airline, including the number of active flights, using the Aviationstack MCP Server API.

Instructions

MCP tool to get flights with a specific airline.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
airline_nameYes
number_of_flightsYes

Implementation Reference

  • Handler function for 'flights_with_airline' tool. Decorated with @mcp.tool() which handles registration. Fetches flights for a given airline using AviationStack API and returns JSON of flight details.
    @mcp.tool() def flights_with_airline(airline_name: str, number_of_flights: int) -> str: """MCP tool to get flights with a specific airline.""" try: data = fetch_flight_data( 'http://api.aviationstack.com/v1/flights', {'airline_name': airline_name, 'limit': number_of_flights} ) filtered_flights = [] data_list = data.get('data', []) number_of_flights_to_fetch = min(number_of_flights, len(data_list)) # Sample random flights from the data list sampled_flights = random.sample(data_list, number_of_flights_to_fetch) for flight in sampled_flights: filtered_flights.append({ 'flight_number': flight.get('flight').get('iata'), 'airline': flight.get('airline').get('name'), 'departure_airport': flight.get('departure').get('airport'), 'departure_timezone': flight.get('departure').get('timezone'), 'departure_time': flight.get('departure').get('scheduled'), 'arrival_airport': flight.get('arrival').get('airport'), 'arrival_timezone': flight.get('arrival').get('timezone'), 'flight_status': flight.get('flight_status'), 'departure_delay': flight.get('departure').get('delay'), 'departure_terminal': flight.get('departure').get('terminal'), 'departure_gate': flight.get('departure').get('gate'), }) return json.dumps(filtered_flights) if filtered_flights else ( f"No flights found for airline '{airline_name}'." ) except requests.RequestException as e: return f"Request error: {str(e)}" except (KeyError, ValueError, TypeError) as e: return f"Error fetching flights: {str(e)}"
  • Helper function used by flights_with_airline to fetch data from AviationStack API.
    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()
  • Function signature and docstring defining input parameters and tool description (schema).
    def flights_with_airline(airline_name: str, number_of_flights: int) -> str: """MCP tool to get flights with a specific airline."""
  • @mcp.tool() decorator registers the function as an MCP tool.
    @mcp.tool()

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pradumnasaraf/aviationstack-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server