airbnb_search
Search Airbnb listings by location, dates, and filters like price, guests, and pets. Retrieve direct property links and use pagination for extensive results.
Instructions
Search for Airbnb listings with various filters and pagination. Provide direct links to the user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| adults | No | Number of adults | |
| checkin | No | Check-in date (YYYY-MM-DD) | |
| checkout | No | Check-out date (YYYY-MM-DD) | |
| children | No | Number of children | |
| cursor | No | Base64-encoded string used for Pagination | |
| ignoreRobotsText | No | Ignore robots.txt rules for this request | |
| infants | No | Number of infants | |
| location | Yes | Location to search for (city, state, etc.) | |
| maxPrice | No | Maximum price for the stay | |
| minPrice | No | Minimum price for the stay | |
| pets | No | Number of pets | |
| placeId | No | Google Maps Place ID (overrides the location parameter) |
Input Schema (JSON Schema)
{
"properties": {
"adults": {
"description": "Number of adults",
"type": "number"
},
"checkin": {
"description": "Check-in date (YYYY-MM-DD)",
"type": "string"
},
"checkout": {
"description": "Check-out date (YYYY-MM-DD)",
"type": "string"
},
"children": {
"description": "Number of children",
"type": "number"
},
"cursor": {
"description": "Base64-encoded string used for Pagination",
"type": "string"
},
"ignoreRobotsText": {
"description": "Ignore robots.txt rules for this request",
"type": "boolean"
},
"infants": {
"description": "Number of infants",
"type": "number"
},
"location": {
"description": "Location to search for (city, state, etc.)",
"type": "string"
},
"maxPrice": {
"description": "Maximum price for the stay",
"type": "number"
},
"minPrice": {
"description": "Minimum price for the stay",
"type": "number"
},
"pets": {
"description": "Number of pets",
"type": "number"
},
"placeId": {
"description": "Google Maps Place ID (overrides the location parameter)",
"type": "string"
}
},
"required": [
"location"
],
"type": "object"
}
Implementation Reference
- index.ts:247-450 (handler)Main handler function for airbnb_search tool. Constructs search URL with filters, respects robots.txt, fetches HTML, parses embedded JSON data using cheerio and utility functions, extracts listings with IDs and direct links, handles pagination via cursor.async function handleAirbnbSearch(params: any) { const { location, placeId, checkin, checkout, adults = 1, children = 0, infants = 0, pets = 0, minPrice, maxPrice, cursor, ignoreRobotsText = false, } = params; // Build search URL const searchUrl = new URL(`${BASE_URL}/s/${encodeURIComponent(location)}/homes`); // Add placeId if (placeId) searchUrl.searchParams.append("place_id", placeId); // Add query parameters if (checkin) searchUrl.searchParams.append("checkin", checkin); if (checkout) searchUrl.searchParams.append("checkout", checkout); // Add guests 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()); } // Add price range if (minPrice) searchUrl.searchParams.append("price_min", minPrice.toString()); if (maxPrice) searchUrl.searchParams.append("price_max", maxPrice.toString()); // Add room type // if (roomType) { // const roomTypeParam = roomType.toLowerCase().replace(/\s+/g, '_'); // searchUrl.searchParams.append("room_types[]", roomTypeParam); // } // Add cursor for pagination if (cursor) { searchUrl.searchParams.append("cursor", cursor); } // Check if path is allowed by robots.txt 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: Record<string, any> = { 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 } } } }, // contextualPictures: { // picture: 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 }; } }
- index.ts:36-93 (schema)Tool schema definition including name, description, and comprehensive input schema specifying required 'location' and optional filters for dates, guests, pricing, pagination.const AIRBNB_SEARCH_TOOL: 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:138-141 (registration)Registration of airbnb_search tool in the AIRBNB_TOOLS array used for tool listing.const AIRBNB_TOOLS = [ AIRBNB_SEARCH_TOOL, AIRBNB_LISTING_DETAILS_TOOL, ] as const;
- index.ts:661-663 (registration)Server request handler for ListToolsRequestSchema that exposes AIRBNB_TOOLS, making airbnb_search discoverable.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: AIRBNB_TOOLS, }));
- index.ts:690-693 (registration)Switch case in CallToolRequestSchema handler that routes 'airbnb_search' calls to the handleAirbnbSearch function.case "airbnb_search": { result = await handleAirbnbSearch(request.params.arguments); break; }