random_countries_detailed_info
Obtain comprehensive metadata for a requested number of random countries, facilitating data sampling or geographical exploration.
Instructions
Return detailed metadata for random countries.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| number_of_countries | Yes | Number of random countries to return. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/aviationstack_mcp/server.py:621-650 (handler)Core handler function that fetches detailed info for random countries from the aviationstack API. Validates input, fetches country data, samples randomly, extracts and returns JSON with fields: country_name, capital, currency_code, fips_code, country_iso2, country_iso3, continent, country_id, currency_name, country_iso_numeric, phone_prefix, population.
def random_countries_detailed_info(number_of_countries: int) -> str: """Get detailed info for random countries.""" try: _validate_positive_int(number_of_countries, "number_of_countries") data = fetch_flight_data("countries", {"limit": number_of_countries}) sampled_countries = _sample_data(data.get("data", []), number_of_countries) 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 exc: return _error_response("fetching countries", exc) except (KeyError, ValueError, TypeError) as exc: return _error_response("fetching countries", exc) - src/aviationstack_mcp/server.py:966-981 (registration)Tool wrapper/registration for 'random_countries_detailed_info' using @mcp.tool decorator. Defines the tool's name, description, input parameter (number_of_countries), validates via Pydantic schema, and delegates to the core handler function.
@mcp.tool( name="random_countries_detailed_info", description="Return detailed metadata for random countries.", ) def random_countries_detailed_info_tool( number_of_countries: Annotated[ int, Field(description="Number of random countries to return.", gt=0) ], ) -> str: """Tool wrapper for random_countries_detailed_info.""" validated_input = RandomCountriesDetailedInfoInput( number_of_countries=number_of_countries ) return random_countries_detailed_info( number_of_countries=validated_input.number_of_countries ) - Pydantic input schema (RandomCountriesDetailedInfoInput) for the tool. Validates number_of_countries as a positive integer.
class RandomCountriesDetailedInfoInput(BaseModel): """Input schema for random_countries_detailed_info tool.""" model_config = ConfigDict(extra="forbid") number_of_countries: int = Field( ..., description="Number of random countries to return.", gt=0, )