Skip to main content
Glama
Pradumnasaraf

Aviationstack MCP Server

historical_flights_by_date

Get random historical flights for a date, with optional airline and route filters.

Instructions

Return a random sample of historical flights for a date with optional airline and route filters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
flight_dateYesDate in YYYY-MM-DD format.
number_of_flightsYesNumber of random flights to return.
airline_iataNoOptional airline IATA code filter (for example: DL).
dep_iataNoOptional departure airport IATA code filter (for example: JFK).
arr_iataNoOptional arrival airport IATA code filter (for example: LAX).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function for historical_flights_by_date. Accepts flight_date, number_of_flights, and optional filters (airline_iata, dep_iata, arr_iata). Validates inputs, fetches flight data from API, samples results, and returns JSON string of historical flight details.
    def historical_flights_by_date(
        flight_date: str,
        number_of_flights: int,
        airline_iata: str = "",
        dep_iata: str = "",
        arr_iata: str = "",
    ) -> str:
        """Get a random sample of historical flights for a specific date (Basic plan+)."""
        try:
            _validate_positive_int(number_of_flights, "number_of_flights")
            _validate_iso_date(flight_date, "flight_date")
            params: dict[str, Any] = {"flight_date": flight_date, "limit": number_of_flights}
            if airline_iata:
                params["airline_iata"] = airline_iata
            if dep_iata:
                params["dep_iata"] = dep_iata
            if arr_iata:
                params["arr_iata"] = arr_iata
    
            data = fetch_flight_data("flights", params)
            sampled_flights = _sample_data(data.get("data", []), number_of_flights)
    
            historical_flights = []
            for flight in sampled_flights:
                historical_flights.append(
                    {
                        "flight_date": flight.get("flight_date"),
                        "flight_status": flight.get("flight_status"),
                        "flight_number": _safe_get(flight, "flight", "iata"),
                        "airline": _safe_get(flight, "airline", "name"),
                        "departure_airport": _safe_get(flight, "departure", "airport"),
                        "departure_time": _safe_get(flight, "departure", "scheduled"),
                        "arrival_airport": _safe_get(flight, "arrival", "airport"),
                        "arrival_time": _safe_get(flight, "arrival", "scheduled"),
                    }
                )
            if not historical_flights:
                return f"No historical flights found for date '{flight_date}'."
            return json.dumps(historical_flights)
        except requests.RequestException as exc:
            return _error_response("fetching historical flights", exc)
        except (KeyError, ValueError, TypeError) as exc:
            return _error_response("fetching historical flights", exc)
  • Pydantic BaseModel input schema (HistoricalFlightsByDateInput) defining fields: flight_date (str), number_of_flights (int, gt=0), airline_iata, dep_iata, arr_iata (all str with defaults).
    class HistoricalFlightsByDateInput(BaseModel):
        """Input schema for historical_flights_by_date tool."""
    
        model_config = ConfigDict(extra="forbid")
    
        flight_date: str = Field(
            ...,
            description="Date in YYYY-MM-DD format.",
            examples=["2026-03-01"],
        )
        number_of_flights: int = Field(
            ...,
            description="Number of random flights to return.",
            gt=0,
        )
        airline_iata: str = Field(
            default="",
            description="Optional airline IATA code filter (for example: DL).",
        )
        dep_iata: str = Field(
            default="",
            description="Optional departure airport IATA code filter (for example: JFK).",
        )
        arr_iata: str = Field(
            default="",
            description="Optional arrival airport IATA code filter (for example: LAX).",
        )
  • Tool registration via @mcp.tool decorator with name='historical_flights_by_date' and description. The wrapper function historical_flights_by_date_tool calls the core handler.
    @mcp.tool(
        name="historical_flights_by_date",
        description=(
            "Return a random sample of historical flights for a date with optional airline "
            "and route filters."
        ),
    )
    def historical_flights_by_date_tool(
        flight_date: Annotated[
            str, Field(description="Date in YYYY-MM-DD format.", examples=["2026-03-01"])
        ],
        number_of_flights: Annotated[
            int, Field(description="Number of random flights to return.", gt=0)
        ],
        airline_iata: Annotated[
            str, Field(description="Optional airline IATA code filter (for example: DL).")
        ] = "",
        dep_iata: Annotated[
            str, Field(description="Optional departure airport IATA code filter (for example: JFK).")
        ] = "",
        arr_iata: Annotated[
            str, Field(description="Optional arrival airport IATA code filter (for example: LAX).")
        ] = "",
    ) -> str:
        """Tool wrapper for historical_flights_by_date."""
        validated_input = HistoricalFlightsByDateInput(
            flight_date=flight_date,
            number_of_flights=number_of_flights,
            airline_iata=airline_iata,
            dep_iata=dep_iata,
            arr_iata=arr_iata,
        )
        return historical_flights_by_date(
            flight_date=validated_input.flight_date,
            number_of_flights=validated_input.number_of_flights,
            airline_iata=validated_input.airline_iata,
            dep_iata=validated_input.dep_iata,
            arr_iata=validated_input.arr_iata,
        )
  • Sample payload for historical_flights_by_date used as a resource/test sample, with example values for flight_date, number_of_flights, airline_iata, dep_iata, arr_iata.
    "historical_flights_by_date": {
        "flight_date": "2026-03-01",
        "number_of_flights": 5,
        "airline_iata": "DL",
        "dep_iata": "JFK",
        "arr_iata": "LAX",
    },
Behavior3/5

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

With no annotations, the description should disclose behavioral traits. It adds 'random sample' and 'optional filters' beyond the schema, but does not mention side effects, mutability, or that it's a read-only operation. The random sampling is a key disclosure, but lacks depth.

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

Conciseness4/5

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

The description is a single sentence that is front-loaded with the core action ('Return a random sample') and includes key constraints. No unnecessary words, but could be slightly more structured with additional context.

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

Completeness3/5

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

The tool has an output schema, so return values need not be explained. However, with 5 parameters and random sampling, the description lacks details on sampling methodology or edge cases. It is adequate but not complete given the complexity.

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 ('with optional airline and route filters') adds minimal new meaning beyond what the schema already provides for parameters like airline_iata and dep_iata.

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 historical flights for a date with optional filters, using a specific verb ('Return') and resource ('historical flights'). It distinguishes from sibling tools like flight_arrival_departure_schedule (scheduled flights) by specifying 'historical' and 'random sample'.

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 explicit guidance on when to use this tool versus alternatives, nor any exclusions or prerequisites. The description only states the basic functionality, leaving the agent to infer context from the tool name and sibling list.

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