Skip to main content
Glama
Pradumnasaraf

Aviationstack MCP Server

flights_with_airline

Get a random sample of live flights for a specified airline. Provide the airline name and number of flights to retrieve real-time data.

Instructions

Return a random sample of live flights filtered by airline name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
airline_nameYesAirline name to filter flights (for example: Delta Air Lines).
number_of_flightsYesNumber of random flights to return.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Pydantic input model for flights_with_airline tool with airline_name (str) and number_of_flights (int) fields.
    class FlightsWithAirlineInput(BaseModel):
        """Input schema for flights_with_airline tool."""
    
        model_config = ConfigDict(extra="forbid")
    
        airline_name: str = Field(
            ...,
            description="Airline name to filter flights (for example: Delta Air Lines).",
            min_length=1,
        )
        number_of_flights: int = Field(
            ...,
            description="Number of random flights to return.",
            gt=0,
        )
  • MCP tool registration for flights_with_airline via @mcp.tool decorator with name and description.
    @mcp.tool(
        name="flights_with_airline",
        description="Return a random sample of live flights filtered by airline name.",
    )
    def flights_with_airline_tool(
        airline_name: Annotated[
            str, Field(description="Airline name to filter flights (for example: Delta Air Lines).")
        ],
        number_of_flights: Annotated[
            int, Field(description="Number of random flights to return.", gt=0)
        ],
    ) -> str:
        """Tool wrapper for flights_with_airline."""
        validated_input = FlightsWithAirlineInput(
            airline_name=airline_name,
            number_of_flights=number_of_flights,
        )
        return flights_with_airline(
            airline_name=validated_input.airline_name,
            number_of_flights=validated_input.number_of_flights,
        )
  • Core handler function flights_with_airline that fetches live flights filtered by airline name, samples results, and returns a JSON string of filtered flight data.
    def flights_with_airline(airline_name: str, number_of_flights: int) -> str:
        """Get a random sample of real-time flights for an airline."""
        try:
            _validate_positive_int(number_of_flights, "number_of_flights")
            data = fetch_flight_data(
                "flights", {"airline_name": airline_name, "limit": number_of_flights}
            )
            sampled_flights = _sample_data(data.get("data", []), number_of_flights)
    
            filtered_flights = []
            for flight in sampled_flights:
                filtered_flights.append(
                    {
                        "flight_number": _safe_get(flight, "flight", "iata"),
                        "airline": _safe_get(flight, "airline", "name"),
                        "departure_airport": _safe_get(flight, "departure", "airport"),
                        "departure_timezone": _safe_get(flight, "departure", "timezone"),
                        "departure_time": _safe_get(flight, "departure", "scheduled"),
                        "arrival_airport": _safe_get(flight, "arrival", "airport"),
                        "arrival_timezone": _safe_get(flight, "arrival", "timezone"),
                        "flight_status": flight.get("flight_status"),
                        "departure_delay": _safe_get(flight, "departure", "delay"),
                        "departure_terminal": _safe_get(flight, "departure", "terminal"),
                        "departure_gate": _safe_get(flight, "departure", "gate"),
                    }
                )
            if not filtered_flights:
                return f"No flights found for airline '{airline_name}'."
            return json.dumps(filtered_flights)
        except requests.RequestException as exc:
            return _error_response("fetching flights", exc)
        except (KeyError, ValueError, TypeError) as exc:
            return _error_response("fetching flights", exc)
  • fetch_flight_data helper used by the handler to call the Aviationstack API with params.
    def fetch_flight_data(endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
        """Fetch data from the Aviationstack API."""
        api_key = _get_api_key()
        request_params = {"access_key": api_key, **params}
        response = requests.get(f"{API_BASE_URL}/{endpoint}", params=request_params, timeout=15)
        try:
            payload = response.json()
        except ValueError:
            payload = {}
    
        if payload.get("error"):
            error = payload["error"]
            code = error.get("code", "api_error")
            error_type = error.get("type", "api_error")
            message = error.get("message", "Unknown API error")
            raise ValueError(f"{error_type} ({code}): {message}")
    
        response.raise_for_status()
        return payload
  • _sample_data helper used to randomly sample flights from API results.
    def _sample_data(items: list[dict[str, Any]], count: int) -> list[dict[str, Any]]:
        _validate_positive_int(count, "count")
        number_to_fetch = min(count, len(items))
        return random.sample(items, number_to_fetch)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description mentions the random and live nature of the results, which is helpful. However, with no annotations, it does not disclose other behavioral aspects such as response limits, determinism, or caching. The output schema may cover return format, but behavior beyond randomness is not addressed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-front-loaded sentence that efficiently communicates the tool's purpose without extraneous information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with two parameters and an output schema, the description covers the core functionality: random sample, live flights, and filtering by airline. It does not elaborate on sampling method or rate limits, but given the low complexity, it is fairly complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds no additional meaning beyond what the schema already provides for 'airline_name' and 'number_of_flights'. No extra context on formatting, defaults, or allowed values.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns a random sample of live flights filtered by airline name. The verb 'return' and resource 'live flights' are specific, and the sibling tools (e.g., flight_arrival_departure_schedule, historical_flights_by_date) have distinct purposes, making this tool's function unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is given on when to use this tool versus alternatives like flight_arrival_departure_schedule or historical_flights_by_date. The description does not mention exclusions or prerequisites, leaving the agent to infer context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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