Skip to main content
Glama

random_aircraft_type

Generate random aircraft types based on specified quantity using the AviationStack API. Ideal for simulations, testing, or aviation-related data analysis.

Instructions

MCP tool to get random aircraft type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
number_of_aircraftYes

Implementation Reference

  • The handler function decorated with @mcp.tool() registers and implements the 'random_aircraft_type' tool. It fetches aircraft types from the AviationStack API, randomly samples the requested number, extracts name and ICAO code, and returns them as JSON. Uses the shared fetch_flight_data helper.
    @mcp.tool() def random_aircraft_type(number_of_aircraft: int) -> str: """MCP tool to get random aircraft type.""" try: data = fetch_flight_data('http://api.aviationstack.com/v1/aircraft_types', { 'limit': number_of_aircraft }) data_list = data.get('data', []) number_of_aircraft_to_fetch = min(number_of_aircraft, len(data_list)) # Sample random aircraft types from the data list sampled_aircraft_types = random.sample(data_list, number_of_aircraft_to_fetch) aircraft_types = [] for aircraft_type in sampled_aircraft_types: aircraft_types.append({ 'aircraft_name': aircraft_type.get('aircraft_name'), 'icao_code': aircraft_type.get('iata_code'), }) return json.dumps(aircraft_types) except requests.RequestException as e: return f"Request error: {str(e)}" except (KeyError, ValueError, TypeError) as e: return f"Error fetching aircraft type: {str(e)}"
  • Shared helper function to fetch data from AviationStack API, used by random_aircraft_type to retrieve aircraft types data.
    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()

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