Skip to main content
Glama

search_airports

Find airport information by IATA code or city name to support flight planning and aviation operations. Filter results by country code for precise airport identification.

Instructions

Search for airports by IATA code or city name.

Args: query: IATA code (e.g., 'SJC') or city name (e.g., 'San Jose') country: Optional ISO country code to filter by (e.g., 'US', 'JP') query_type: Type of query - 'iata' for IATA codes, 'city' for city names, 'auto' to detect

Returns: Formatted string with airport information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
countryNo
query_typeNoauto

Implementation Reference

  • Main handler function that executes the search_airports tool logic, supporting IATA or city-based queries and returning formatted airport information.
    def search_airports( query: str, country: str | None = None, query_type: Literal["iata", "city", "auto"] = "auto", ) -> str: """Search for airports by IATA code or city name. Args: query: IATA code (e.g., 'SJC') or city name (e.g., 'San Jose') country: Optional ISO country code to filter by (e.g., 'US', 'JP') query_type: Type of query - 'iata' for IATA codes, 'city' for city names, 'auto' to detect Returns: Formatted string with airport information """ query = query.strip() if not query: return "Error: Query parameter is required" results = [] # Auto-detect query type if needed if query_type == "auto": query_type = "iata" if len(query) == 3 and query.isalpha() else "city" try: if query_type == "iata": # Search by IATA code airport = _airport_from_iata(query) if airport: results = [airport] else: # Search by city name results = _find_city_airports(query, country) if not results: message = f"No airports found for {query_type} '{query}'" if country: message += f" in country '{country}'" return message # Format results response_lines = [f"Found {len(results)} airport(s):"] for airport in results: line = f"• {airport.iata} ({airport.icao}) - {airport.name}" line += f"\n City: {airport.city}, {airport.country}" line += f"\n Coordinates: {airport.lat:.4f}, {airport.lon:.4f}" if airport.tz: line += f"\n Timezone: {airport.tz}" response_lines.append(line) return "\n\n".join(response_lines) except Exception as e: return f"Search error: {str(e)}"
  • Registers the search_airports tool with the FastMCP server.
    mcp.tool(search_airports)
  • Helper function to retrieve airport data by IATA code from the airports database.
    def _airport_from_iata(iata: str) -> AirportOut | None: ap = _AIRPORTS_IATA.get(iata.upper()) if not ap: return None return AirportOut( iata=iata.upper(), icao=ap.get("icao", ""), name=ap.get("name", ""), city=ap.get("city", ""), country=ap.get("country", ""), lat=float(ap["lat"]), lon=float(ap["lon"]), tz=ap.get("tz"), )
  • Helper function to find airports matching a city name, optionally filtered by country.
    def _find_city_airports(city: str, country: str | None = None) -> list[AirportOut]: city_l = city.strip().lower() if not city_l: # Return empty list for empty city names return [] out = [] for iata, ap in _AIRPORTS_IATA.items(): if not iata or not ap.get("iata"): continue if ( ap.get("city", "").strip().lower() == city_l or city_l in ap.get("name", "").lower() ): if country is None or (ap.get("country", "").upper() == country.upper()): out.append( AirportOut( iata=iata.upper(), icao=ap.get("icao", ""), name=ap.get("name", ""), city=ap.get("city", ""), country=ap.get("country", ""), lat=float(ap["lat"]), lon=float(ap["lon"]), tz=ap.get("tz"), ) ) # Heuristic: prefer airports with "International" in the name, else keep order out.sort(key=lambda a: ("international" not in a.name.lower(), a.name)) # De-dup city matches that are clearly heliports or without IATA (already filtered) return out
  • Pydantic model defining the structure of airport data used in search results.
    class AirportOut(BaseModel): iata: str icao: str name: str city: str country: str lat: float lon: float tz: str | None = None

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/cheesejaguar/aerospace-mcp'

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