Skip to main content
Glama

airbnb_search

Search for Airbnb listings using location, dates, guest counts, and price filters. Get direct booking links and detailed property information for accommodation planning.

Instructions

Search for Airbnb listings with various filters and pagination. Provide direct links to the user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesLocation to search for (city, state, etc.)
placeIdNoGoogle Maps Place ID (overrides the location parameter)
checkinNoCheck-in date (YYYY-MM-DD)
checkoutNoCheck-out date (YYYY-MM-DD)
adultsNoNumber of adults
childrenNoNumber of children
infantsNoNumber of infants
petsNoNumber of pets
minPriceNoMinimum price for the stay
maxPriceNoMaximum price for the stay
cursorNoBase64-encoded string used for Pagination
ignoreRobotsTextNoIgnore robots.txt rules for this request

Implementation Reference

  • Main handler function for airbnb_search tool: constructs search URL with filters, respects robots.txt, fetches HTML, parses JSON data from script tag using cheerio, extracts and formats listing results with URLs.
    async function handleAirbnbSearch(params: any) { const { location, placeId, checkin, checkout, adults = 1, children = 0, infants = 0, pets = 0, minPrice, maxPrice, cursor, ignoreRobotsText = false, } = params; const searchUrl = new URL(`${BASE_URL}/s/${encodeURIComponent(location)}/homes`); if (placeId) searchUrl.searchParams.append("place_id", placeId); if (checkin) searchUrl.searchParams.append("checkin", checkin); if (checkout) searchUrl.searchParams.append("checkout", checkout); const adults_int = parseInt(adults.toString()); const children_int = parseInt(children.toString()); const infants_int = parseInt(infants.toString()); const pets_int = parseInt(pets.toString()); const totalGuests = adults_int + children_int; if (totalGuests > 0) { searchUrl.searchParams.append("adults", adults_int.toString()); searchUrl.searchParams.append("children", children_int.toString()); searchUrl.searchParams.append("infants", infants_int.toString()); searchUrl.searchParams.append("pets", pets_int.toString()); } if (minPrice) searchUrl.searchParams.append("price_min", minPrice.toString()); if (maxPrice) searchUrl.searchParams.append("price_max", maxPrice.toString()); if (cursor) { searchUrl.searchParams.append("cursor", cursor); } const path = searchUrl.pathname + searchUrl.search; if (!ignoreRobotsText && !isPathAllowed(path)) { log('warn', 'Search blocked by robots.txt', { path, url: searchUrl.toString() }); return { content: [{ type: "text", text: JSON.stringify({ error: robotsErrorMessage, url: searchUrl.toString(), suggestion: "Consider enabling 'ignore_robots_txt' in extension settings if needed for testing" }, null, 2) }], isError: true }; } const allowSearchResultSchema = { demandStayListing : { id: true, description: true, location: true, }, badges: { text: true, }, structuredContent: { mapCategoryInfo: { body: true }, mapSecondaryLine: { body: true }, primaryLine: { body: true }, secondaryLine: { body: true }, }, avgRatingA11yLabel: true, listingParamOverrides: true, structuredDisplayPrice: { primaryLine: { accessibilityLabel: true, }, secondaryLine: { accessibilityLabel: true, }, explanationData: { title: true, priceDetails: { items: { description: true, priceString: true } } } }, }; try { log('info', 'Performing Airbnb search', { location, checkin, checkout, adults, children }); const response = await fetchWithUserAgent(searchUrl.toString()); const html = await response.text(); const $ = cheerio.load(html); let staysSearchResults: any = {}; try { const scriptElement = $("#data-deferred-state-0").first(); if (scriptElement.length === 0) { throw new Error("Could not find data script element - page structure may have changed"); } const scriptContent = $(scriptElement).text(); if (!scriptContent) { throw new Error("Data script element is empty"); } const clientData = JSON.parse(scriptContent).niobeClientData[0][1]; const results = clientData.data.presentation.staysSearch.results; cleanObject(results); staysSearchResults = { searchResults: results.searchResults .map((result: any) => flattenArraysInObject(pickBySchema(result, allowSearchResultSchema))) .map((result: any) => { const id = atob(result.demandStayListing.id).split(":")[1]; return {id, url: `${BASE_URL}/rooms/${id}`, ...result } }), paginationInfo: results.paginationInfo } log('info', 'Search completed successfully', { resultCount: staysSearchResults.searchResults?.length || 0 }); } catch (parseError) { log('error', 'Failed to parse search results', { error: parseError instanceof Error ? parseError.message : String(parseError), url: searchUrl.toString() }); return { content: [{ type: "text", text: JSON.stringify({ error: "Failed to parse search results from Airbnb. The page structure may have changed.", details: parseError instanceof Error ? parseError.message : String(parseError), searchUrl: searchUrl.toString() }, null, 2) }], isError: true }; } return { content: [{ type: "text", text: JSON.stringify({ searchUrl: searchUrl.toString(), ...staysSearchResults }, null, 2) }], isError: false }; } catch (error) { log('error', 'Search request failed', { error: error instanceof Error ? error.message : String(error), url: searchUrl.toString() }); return { content: [{ type: "text", text: JSON.stringify({ error: error instanceof Error ? error.message : String(error), searchUrl: searchUrl.toString(), timestamp: new Date().toISOString() }, null, 2) }], isError: true }; } }
  • Tool definition object with name, description, and detailed inputSchema for parameters including location, dates, guest counts, price range, pagination cursor, and robots.txt override.
    const AIRBNB_SEARCH_TOOL = { name: "airbnb_search", description: "Search for Airbnb listings with various filters and pagination. Provide direct links to the user", inputSchema: { type: "object", properties: { location: { type: "string", description: "Location to search for (city, state, etc.)" }, placeId: { type: "string", description: "Google Maps Place ID (overrides the location parameter)" }, checkin: { type: "string", description: "Check-in date (YYYY-MM-DD)" }, checkout: { type: "string", description: "Check-out date (YYYY-MM-DD)" }, adults: { type: "number", description: "Number of adults" }, children: { type: "number", description: "Number of children" }, infants: { type: "number", description: "Number of infants" }, pets: { type: "number", description: "Number of pets" }, minPrice: { type: "number", description: "Minimum price for the stay" }, maxPrice: { type: "number", description: "Maximum price for the stay" }, cursor: { type: "string", description: "Base64-encoded string used for Pagination" }, ignoreRobotsText: { type: "boolean", description: "Ignore robots.txt rules for this request" } }, required: ["location"] } };
  • index.ts:137-141 (registration)
    Registration of airbnb_search tool in the AIRBNB_TOOLS array, which is returned by the listTools handler.
    const AIRBNB_TOOLS = [ AIRBNB_SEARCH_TOOL, AIRBNB_LISTING_DETAILS_TOOL, ...photoAnalysisTools, ];
  • index.ts:656-658 (registration)
    Dispatch logic in the callTool handler switch statement that invokes handleAirbnbSearch for 'airbnb_search' tool calls.
    case "airbnb_search": { result = await handleAirbnbSearch(request.params.arguments); break;

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/iclickfreedownloads/mcp-server-airbnb'

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