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

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.8/5.0
Behavior3/5

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

With no annotations, the description carries the burden. It states that the tool generates a booking link, indicating a side effect of creating an external resource. However, it lacks details on required permissions, rate limits, or what the output link contains.

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 two sentences long, starting with the core purpose. It is efficient and avoids redundancy, though the two sentences could be merged without loss of clarity.

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 no output schema, so the description should clarify the return value. It mentions generating a booking link but does not specify whether the link is returned in the response or how it is structured. This leaves ambiguity about what the agent will receive.

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?

The input schema already provides thorough descriptions for all three parameters (100% coverage). The description adds no additional parameter-level information beyond what the schema offers, resulting in a baseline score.

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's action ('request link') and resource ('booking a flight option'). It distinguishes from sibling tools like search_flights and get_flight_option_details by focusing on generating a booking link.

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 explicitly recommends using this tool after the user expresses intention to book, providing clear context for when to invoke it. However, it does not mention when not to use it or list alternative tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.