search_hotels
Find available hotels in a city for specific dates and guest count, with optional price filters.
Instructions
Search for available hotels in a destination.
Args: destination: City name (e.g. "Tokyo", "Paris", "London") check_in: Check-in date in YYYY-MM-DD format check_out: Check-out date in YYYY-MM-DD format guests: Number of guests (default: 1) max_price: Maximum price per night in USD (optional)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| destination | Yes | ||
| check_in | Yes | ||
| check_out | Yes | ||
| guests | No | ||
| max_price | No |
Implementation Reference
- src/travel_mcp/server.py:42-59 (handler)The MCP tool handler for 'search_hotels' — decorated with @mcp.tool(), accepts destination, check_in, check_out, guests, max_price and delegates to hotels.search().
def search_hotels( destination: str, check_in: str, check_out: str, guests: int = 1, max_price: Optional[float] = None, ) -> list: """ Search for available hotels in a destination. Args: destination: City name (e.g. "Tokyo", "Paris", "London") check_in: Check-in date in YYYY-MM-DD format check_out: Check-out date in YYYY-MM-DD format guests: Number of guests (default: 1) max_price: Maximum price per night in USD (optional) """ return hotels.search(destination, check_in, check_out, guests, max_price) - src/travel_mcp/server.py:42-59 (schema)Type annotations and docstring define the schema: destination (str), check_in (str), check_out (str), guests (int=1), max_price (Optional[float]).
def search_hotels( destination: str, check_in: str, check_out: str, guests: int = 1, max_price: Optional[float] = None, ) -> list: """ Search for available hotels in a destination. Args: destination: City name (e.g. "Tokyo", "Paris", "London") check_in: Check-in date in YYYY-MM-DD format check_out: Check-out date in YYYY-MM-DD format guests: Number of guests (default: 1) max_price: Maximum price per night in USD (optional) """ return hotels.search(destination, check_in, check_out, guests, max_price) - src/travel_mcp/server.py:41-41 (registration)Tool registered via @mcp.tool() decorator on the search_hotels function.
@mcp.tool() - src/travel_mcp/tools/hotels.py:4-14 (helper)The hotels.search() helper function — thin wrapper that calls query_hotels() from mock data and returns results or a 'not found' message.
def search( destination: str, check_in: str, check_out: str, guests: int, max_price: float | None, ) -> list[dict]: results = query_hotels(destination, check_in, check_out, guests, max_price) if not results: return [{"message": f"No hotels found in '{destination}'" + (f" under ${max_price}/night." if max_price else ".")}] return results - The query_hotels() function — core mock data query logic: normalizes city name, looks up hotels, filters by max_price, computes nights/total_price, and returns sorted results.
def query_hotels( destination: str, check_in: str, check_out: str, guests: int, max_price: float | None, ) -> list[dict]: from datetime import datetime city = _normalize(destination) hotels = _HOTELS.get(city, []) if not hotels: for key in _HOTELS: if key in city or city in key: hotels = _HOTELS[key] break try: nights = (datetime.strptime(check_out, "%Y-%m-%d") - datetime.strptime(check_in, "%Y-%m-%d")).days if nights <= 0: nights = 1 except ValueError: nights = 1 results = [] for hotel in hotels: if max_price and hotel["price_per_night"] > max_price: continue results.append({ **hotel, "check_in": check_in, "check_out": check_out, "nights": nights, "guests": guests, "total_price": hotel["price_per_night"] * nights, "currency": "USD", }) return sorted(results, key=lambda x: x["price_per_night"])