Skip to main content
Glama

random_cities_detailed_info

Fetch detailed information about random cities by specifying the number of cities to retrieve using this MCP tool on the Aviationstack server.

Instructions

MCP tool to get random cities detailed info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
number_of_citiesYes

Implementation Reference

  • The handler function for the 'random_cities_detailed_info' tool. Decorated with @mcp.tool() for registration. Fetches random cities' detailed information from the Aviationstack API /v1/cities endpoint, samples a specified number, extracts fields like gmt, city_id, iata_code, etc., and returns JSON string or error message.
    @mcp.tool() def random_cities_detailed_info(number_of_cities: int) -> str: """MCP tool to get random cities detailed info.""" try: data = fetch_flight_data('http://api.aviationstack.com/v1/cities', { 'limit': number_of_cities }) data_list = data.get('data', []) number_of_cities_to_fetch = min(number_of_cities, len(data_list)) # Sample random cities from the data list sampled_cities = random.sample(data_list, number_of_cities_to_fetch) cities = [] for city in sampled_cities: cities.append({ 'gmt': city.get('gmt'), 'city_id': city.get('city_id'), 'iata_code': city.get('iata_code'), 'country_iso2': city.get('country_iso2'), 'geoname_id': city.get('geoname_id'), 'latitude': city.get('latitude'), 'longitude': city.get('longitude'), 'timezone': city.get('timezone'), 'city_name': city.get('city_name'), }) return json.dumps(cities) except requests.RequestException as e: return f"Request error: {str(e)}" except (KeyError, ValueError, TypeError) as e: return f"Error fetching cities: {str(e)}"
  • Shared helper function used by random_cities_detailed_info (and other tools) to fetch data from Aviationstack API, adding the API key and handling the HTTP request.
    def fetch_flight_data(url: str, params: dict) -> dict: """Fetch flight data from the AviationStack API.""" api_key = os.getenv('AVIATION_STACK_API_KEY') if not api_key: raise ValueError("AVIATION_STACK_API_KEY not set in environment.") params = {'access_key': api_key, **params} response = requests.get(url, params=params, timeout=10) response.raise_for_status() return response.json()
  • The @mcp.tool() decorator registers the random_cities_detailed_info function as an MCP tool.
    @mcp.tool()

Other Tools

Related Tools

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/Pradumnasaraf/aviationstack-mcp'

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