Skip to main content
Glama

request_booking_link

Generate a booking link for a selected flight option to complete the reservation process after expressing booking intent.

Instructions

Request link for booking a flight option. This tool generates a booking link for a specific flight option.This tool is recommended to be used after the user expressed intention to book the flight option.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_idYesSearch ID from the previous search_flights tool.
offer_idYesOffer ID of the flight option for which to request a booking link.
agency_idYesInternal agency ID for generating booking link.

Implementation Reference

  • The main handler function for the 'request_booking_link' tool, including decorator, parameters with schema via Field, and logic to fetch booking link from Travelpayouts API using cached search results.
    @mcp.tool(
        description="Request link for booking a flight option. " \
        "This tool generates a booking link for a specific flight option." \
        "This tool is recommended to be used after the user expressed intention to book the flight option." \
    )
    async def request_booking_link(
        search_id: str = Field(..., description="Search ID from the previous search_flights tool."),
        offer_id: str = Field(..., description="Offer ID of the flight option for which to request a booking link."),
        agency_id: str = Field(..., description="Internal agency ID for generating booking link.")
    ) -> str:
        """Request a booking link for a specific flight option."""
        
        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. " \
                            "Please perform a search first using the `search_flights` tool.")
        
        proposal = batch.get_proposal_by_id(offer_id)
        if not proposal:
            raise ToolError(f"No flight details found for offer_id: {offer_id} in search_id: {search_id}.")
        
        terms = proposal.terms[agency_id]
        
        get_book_link_api_url = f"https://api.travelpayouts.com/v1/flight_searches/{search_id}/clicks/{terms.url}.json?marker={MARKER}"
        async with httpx.AsyncClient(timeout=40) as client:
            response = await client.get(get_book_link_api_url)
            if response.status_code != 200:
                raise ToolError(f"Aviasales API returned non-200 status code: {response.status_code}", raw_response=response.text)
            data = response.json()
            if not data or "url" not in data:
                raise ToolError("Booking link not found in the response from Aviasales API.")
            book_link = data["url"]
            agency_name = batch.gates_info.get(agency_id).label if batch.gates_info.get(agency_id) else ''
            return f"Booking link on {agency_name}: {book_link}"
  • Helper method on ProposalsBatchModel used to retrieve the specific Proposal instance by its sign (offer_id). Essential for accessing the flight proposal data in the handler.
    def get_proposal_by_id(self, proposal_id: str) -> Optional[Proposal]:
        for proposal in self.proposals:
            if proposal.sign == proposal_id:
                return proposal
        return None

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