request_booking_link
Generate a booking link for a specific flight option using search ID, offer ID, and agency ID. Use this tool after the user confirms intent to book a flight.
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
| Name | Required | Description | Default |
|---|---|---|---|
| agency_id | Yes | Internal agency ID for generating booking link. | |
| offer_id | Yes | Offer ID of the flight option for which to request a booking link. | |
| search_id | Yes | Search ID from the previous search_flights tool. |
Input Schema (JSON Schema)
{
"properties": {
"agency_id": {
"description": "Internal agency ID for generating booking link.",
"title": "Agency Id",
"type": "string"
},
"offer_id": {
"description": "Offer ID of the flight option for which to request a booking link.",
"title": "Offer Id",
"type": "string"
},
"search_id": {
"description": "Search ID from the previous search_flights tool.",
"title": "Search Id",
"type": "string"
}
},
"required": [
"search_id",
"offer_id",
"agency_id"
],
"type": "object"
}
Implementation Reference
- src/flights-mcp/main.py:214-218 (registration)Registers the request_booking_link tool using the @mcp.tool decorator with its description.@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." \ )
- src/flights-mcp/main.py:219-249 (handler)The handler function that executes the request_booking_link tool logic: retrieves the proposal from cache, constructs the booking link API URL, fetches the booking URL from Travelpayouts API, and returns the formatted booking link.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}"