Skip to main content
Glama

random_countries_detailed_info

Retrieve detailed information about random countries to support aviation data analysis and geographic research.

Instructions

MCP tool to get random countries detailed info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
number_of_countriesYes

Implementation Reference

  • The handler function for the 'random_countries_detailed_info' tool. Decorated with @mcp.tool() for registration. Fetches country data from AviationStack API, samples random countries, extracts detailed information (name, capital, currency, etc.), returns JSON string or error message.
    @mcp.tool() def random_countries_detailed_info(number_of_countries: int) -> str: """MCP tool to get random countries detailed info.""" try: data = fetch_flight_data('http://api.aviationstack.com/v1/countries', { 'limit': number_of_countries }) data_list = data.get('data', []) number_of_countries_to_fetch = min(number_of_countries, len(data_list)) # Sample random countries from the data list sampled_countries = random.sample(data_list, number_of_countries_to_fetch) countries = [] for country in sampled_countries: countries.append({ 'country_name': country.get('name'), 'capital': country.get('capital'), 'currency_code': country.get('currency_code'), 'fips_code': country.get('fips_code'), 'country_iso2': country.get('country_iso2'), 'country_iso3': country.get('country_iso3'), 'continent': country.get('continent'), 'country_id': country.get('country_id'), 'currency_name': country.get('currency_name'), 'country_iso_numeric': country.get('country_iso_numeric'), 'phone_prefix': country.get('phone_prefix'), 'population': country.get('population'), }) return json.dumps(countries) except requests.RequestException as e: return f"Request error: {str(e)}" except (KeyError, ValueError, TypeError) as e: return f"Error fetching countries: {str(e)}"
  • Shared helper function used by the tool to make API requests to AviationStack, adding the API key and handling basic response.
    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 function as an MCP tool.
    @mcp.tool()

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