search_locations
Find destinations, hotels, restaurants, and attractions on TripAdvisor by entering a query and optional category filter to streamline vacation planning.
Instructions
Search for locations on TripAdvisor
Args:
query: Search term (e.g., "hotels in Paris")
category: Optional category filter (e.g., "hotels", "restaurants", "attractions")
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | ||
| query | Yes |
Implementation Reference
- server.py:116-131 (handler)The handler function for the 'search_locations' tool. It takes a query and optional category, constructs API parameters, calls the TripAdvisor search endpoint via the helper function, and returns the JSON results.@mcp.tool() async def search_locations(query: str, category: Optional[str] = None) -> str: """ Search for locations on TripAdvisor Args: query: Search term (e.g., "hotels in Paris") category: Optional category filter (e.g., "hotels", "restaurants", "attractions") """ params = {"searchQuery": query} if category: params["category"] = category result = await tripadvisor_api_request("location/search", params) return json.dumps(result, indent=2)
- server.py:19-44 (helper)Helper function used by the search_locations tool (and others) to perform HTTP requests to the TripAdvisor API, handling authentication, parameters, and error responses.async def tripadvisor_api_request(endpoint: str, params: Dict[str, Any] = None) -> Dict[str, Any]: """Make a request to the TripAdvisor API""" if not TRIPADVISOR_API_KEY: return {"error": "TripAdvisor API key not configured. Set TRIPADVISOR_API_KEY environment variable."} headers = {"accept": "application/json", "key": TRIPADVISOR_API_KEY} if params is None: params = {} params["key"] = TRIPADVISOR_API_KEY url = f"{API_BASE_URL}/{endpoint}" async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, params=params, timeout=30.0) response.raise_for_status() return response.json() except httpx.HTTPStatusError as e: return { "error": f"HTTP error occurred: {e}", "details": str(e) } #Resources for specific location details