Skip to main content
Glama

get_flight_options

Filter and sort flight search results by price, departure times, airlines, and other criteria to find suitable travel options.

Instructions

Get flight options from the previously performed search. This tool allows you to filter the found flight options by price, departure and arrival times, and airlines. It returns a paginated list of flight options that match the specified filters and sorting option.IMPORTANT: This is very cheap operation, so you can call it as many times as needed to find the best flight options.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_idYes
filtersYes
pageNoPage number for pagination. Default is 0.
page_sizeNoNumber of results per page. Default is 10.

Implementation Reference

  • The main handler function that implements the get_flight_options tool logic: retrieves cached search results, applies filters, paginates, and formats a list of flight options as a string.
    def get_flight_options(
        search_id: str,
        filters: FiltersModel,
        page: int = Field(0, description="Page number for pagination. Default is 0."),
        page_size: int = Field(10, description="Number of results per page. Default is 10.")
    ):
        batch = search_results_cache.get(search_id)
        if not batch:
            raise ToolError(f"No search results found for search_id: {search_id}. " \
                            "It may have expired after 10 minutes or not been performed yet. " \
                            "Please perform a search first using the `search_flights` tool.")
        filtered_batch = batch.apply_filters(filters)
    
        if not filtered_batch.proposals:
            raise ToolError(f"No flight options found for search_id: {search_id} with the specified filters.")
        
        total_results = len(filtered_batch.proposals)
        start_index = page * page_size
        end_index = start_index + page_size
        paginated_results = filtered_batch.proposals[start_index:end_index]
        result = f'Retrieved {len(paginated_results)} flight options for search_id: {search_id} (Page {page}/{(total_results // page_size) + 1})\n\n'
    
        for i, proposal in enumerate(paginated_results):
            result += proposal.get_short_description()
            if i < len(paginated_results) - 1:
                result += "\n---\n"
        return result
  • The @mcp.tool decorator that registers the get_flight_options function as an MCP tool, including its description.
    @mcp.tool(
        description="Get flight options from the previously performed search. " \
        "This tool allows you to filter the found flight options by price, departure and arrival times, and airlines. " \
        "It returns a paginated list of flight options that match the specified filters and sorting option." \
        "IMPORTANT: This is very cheap operation, so you can call it as many times as needed to find the best flight options."
    )
  • Pydantic schema for the 'filters' input parameter of get_flight_options, defining all filtering options like price, duration, airlines, stops, time ranges, and sorting.
    class FiltersModel(BaseModel):
        """Model for filtering flight proposals"""
        max_total_duration: Optional[int] = Field(None, description="Maximum total duration of whole trip in minutes")
        max_price: Optional[int] = Field(None, description="Maximum price filter")
        allowed_airlines: Optional[List[str]] = Field(None, description="List of allowed airline IATA codes")
        segment_time_filters: Optional[List[SegmentTimeFilter]] = Field(None, description="Time filters for each segment")
        max_stops: Optional[int] = Field(None, description="Maximum number of stops allowed")
        sorting: Optional[SortingMethod] = Field(SortingMethod.CHEAP_FIRST, description="Sorting method")
  • Key helper method on ProposalsBatchModel that performs the filtering and sorting logic called by the tool handler.
    def apply_filters(self, filters: FiltersModel) -> 'ProposalsBatchModel':
        """
        Apply filters to the proposals and return a new ProposalsBatchModel with filtered results.
        
        Args:
            filters: FiltersModel containing all filter criteria
            
        Returns:
            New ProposalsBatchModel with filtered proposals
        """
        filtered_proposals = []
        
        for proposal in self.proposals:
            if self._proposal_matches_filters(proposal, filters):
                filtered_proposals.append(proposal)
        
        # Apply sorting
        if filters.sorting:
            filtered_proposals = self._sort_proposals(filtered_proposals, filters.sorting)
        
        # Create new instance with filtered proposals
        return ProposalsBatchModel(
            proposals=filtered_proposals,
            airports=self.airports,
            search_id=self.search_id,
            chunk_id=self.chunk_id,
            meta=self.meta,
            airlines=self.airlines,
            gates_info=self.gates_info,
            flight_info=self.flight_info,
            segments=self.segments,
            market=self.market,
            clean_marker=self.clean_marker,
            open_jaw=self.open_jaw,
            currency=self.currency,
            initiated_at=self.initiated_at
        )
  • TTL cache used to store search results by search_id, enabling the get_flight_options tool to retrieve previous search batches.
    search_results_cache = TTLCache(
        maxsize=10000,  # Maximum number of cached items
        ttl=10 * 60,  # Time to live for each cached item (10 minutes)
    )
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does well by explicitly stating this is a 'very cheap operation' with permission for frequent calls, and it discloses the paginated nature of the return. It also mentions filtering and sorting capabilities. However, it doesn't cover potential error conditions, rate limits beyond the 'cheap' characterization, or authentication requirements.

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 efficiently structured with three sentences that each earn their place: purpose statement, filtering/sorting capabilities, and important behavioral guidance about cost. It's front-loaded with the core purpose and appropriately sized without wasted words. The IMPORTANT section effectively highlights critical usage 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 tool with 4 parameters, no annotations, and no output schema, the description does reasonably well. It covers the core functionality, behavioral characteristics (cheap operation, pagination), and provides usage context. However, it doesn't describe the return format beyond 'paginated list of flight options,' and with 50% schema coverage, some parameter semantics remain unclear. Given the complexity, it's mostly complete but has gaps.

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?

With 50% schema description coverage, the description adds some value by mentioning filtering by 'price, departure and arrival times, and airlines' and 'sorting option.' However, it doesn't fully compensate for the schema coverage gap - it doesn't explain the 'search_id' parameter's purpose or format, nor does it detail the pagination parameters beyond mentioning 'paginated list.' The description provides context but leaves significant parameter semantics to the schema.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get flight options from the previously performed search' with filtering capabilities. It distinguishes itself from 'search_flights' by focusing on retrieving and filtering results from an existing search rather than initiating a new search. However, it doesn't explicitly differentiate from 'get_flight_option_details' which presumably provides more detailed information about specific options.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool: after a search has been performed ('from the previously performed search'). It implies an alternative ('search_flights' for initial searches) and includes the important guidance that this is 'very cheap operation, so you can call it as many times as needed.' However, it doesn't explicitly state when NOT to use this tool or provide direct comparisons with all sibling tools.

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/maratsarbasov/flights-mcp'

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