Skip to main content
Glama
pab1it0

Tripadvisor MCP

search_nearby_locations

Find nearby attractions, restaurants, and points of interest using latitude and longitude coordinates to discover local destinations.

Instructions

Search for locations near a specific latitude/longitude

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes
languageNoen
categoryNo

Implementation Reference

  • The handler function for the 'search_nearby_locations' tool. It formats the latLong parameter and calls the Tripadvisor API's location/search endpoint via make_api_request. The @mcp.tool decorator registers the tool and defines its schema from the function signature and description.
    @mcp.tool(description="Search for locations near a specific latitude/longitude")
    async def search_nearby_locations(
        latitude: float,
        longitude: float,
        language: str = "en",
        category: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Search for locations near a specific latitude/longitude.
        
        Parameters:
        - latitude: Latitude coordinate
        - longitude: Longitude coordinate
        - language: Language code (default: 'en')
        - category: Optional category filter ('hotels', 'attractions', 'restaurants')
        """
        params = {
            "latLong": f"{latitude},{longitude}",
            "language": language,
        }
        
        if category:
            params["category"] = category
        
        return await make_api_request("location/search", params)
  • Shared utility function that handles authenticated HTTP requests to the Tripadvisor Content API, adding the API key and handling responses. Used by search_nearby_locations to fetch nearby locations.
    async def make_api_request(endpoint: str, params: Dict[str, Any] = None) -> Dict[str, Any]:
        """Make a request to the Tripadvisor Content API"""
        if not config.api_key:
            raise ValueError("Tripadvisor API key is missing. Please set TRIPADVISOR_API_KEY environment variable.")
        
        url = f"{config.base_url}/{endpoint}"
        headers = {
            "accept": "application/json"
        }
    
        if params is None:
            params = {}
        params["key"] = config.api_key
        
        async with httpx.AsyncClient() as client:
            response = await client.get(url, headers=headers, params=params)
            response.raise_for_status()
            return response.json()

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/pab1it0/tripadvisor-mcp'

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