Skip to main content
The parsers module provides utilities for parsing and validating user input into strongly-typed domain model objects. These functions are used by both the CLI and MCP interfaces to ensure consistent parameter handling.

resolve_enum

Resolve an enum member by name with normalized errors.
type[T]
required
The enum class to resolve from
str
required
The name of the enum member (case-insensitive)
Returns: The resolved enum member Raises: ParseError if the name is not a valid enum member

Usage

resolve_airport

Resolve an airport code to an Airport enum.
str
required
IATA airport code (e.g., ‘JFK’, ‘LHR’)
Returns: The corresponding Airport enum member Raises: ParseError if the code is not a valid airport

Usage

parse_airlines

Parse a list of airline codes into Airline enums.
list[str] | None
required
List of IATA airline codes (e.g., [‘BA’, ‘KL’]). Can be None.
Returns: List of Airline enums, or None if input is empty Raises: ParseError if any code is not a valid airline

Usage

parse_max_stops

Parse a stops parameter into a MaxStops enum. Accepts both string names (ANY, NON_STOP, ONE_STOP, TWO_PLUS_STOPS) and integer values (0, 1, 2+).
str
required
Stops value as string or integer representation. Valid values:
  • String names: "ANY", "NON_STOP", "NONSTOP", "ONE_STOP", "ONE_STOP_OR_FEWER", "TWO_PLUS_STOPS", "TWO_OR_FEWER_STOPS"
  • Integers: "0" (non-stop), "1" (one stop or fewer), "2" (two or fewer stops)
Returns: The corresponding MaxStops enum member Raises: ParseError if the value is not valid

Usage

parse_cabin_class

Parse a cabin class string into a SeatType enum.
str
required
Cabin class name. Valid values: "ECONOMY", "PREMIUM_ECONOMY", "BUSINESS", "FIRST"
Returns: The corresponding SeatType enum member Raises: ParseError if the value is not valid

Usage

parse_sort_by

Parse a sort_by string into a SortBy enum.
str
required
Sort option. Valid values: "CHEAPEST", "DURATION", "DEPARTURE_TIME", "ARRIVAL_TIME"
Returns: The corresponding SortBy enum member Raises: ParseError if the value is not valid

Usage

parse_time_range

Parse a time range string into start and end hours.
str
required
Time range in ‘HH-HH’ format (e.g., ‘6-20’ for 6 AM to 8 PM)
Returns: Tuple of (start_hour, end_hour) where hours are integers from 0-23 Raises: ParseError if the format is invalid or hours are out of range

Usage

ParseError

Exception raised when parsing fails.
All parser functions raise ParseError when they encounter invalid input. This exception inherits from ValueError and includes descriptive error messages with valid value suggestions.

Usage

Complete example

Here’s how the parser functions are used together in the MCP server: