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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions what the tool does (search) and returns (formatted string), but doesn't disclose important behavioral traits like whether this is a local or remote search, potential rate limits, authentication needs, error conditions, or what happens with ambiguous queries. The description is minimal beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with clear sections (purpose, args, returns). The first sentence states the core purpose, followed by structured parameter explanations. No wasted sentences, though the formatting could be slightly more polished.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (returns formatted string), the description doesn't need to detail return values. However, with no annotations and moderate complexity (3 parameters, search functionality), the description is adequate but lacks behavioral context like search scope, data source, or error handling that would be helpful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates well by explaining all 3 parameters: query accepts IATA codes or city names with examples, country is optional with ISO code examples, and query_type has three options with meanings. This adds significant meaning beyond the bare schema, though it doesn't cover all edge cases.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches for airports using specific criteria (IATA code or city name), which is a specific verb+resource combination. However, it doesn't differentiate from sibling tools since all siblings appear to be aerospace/aviation-related but none are direct airport search alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through parameter explanations (query_type options, country filtering) but doesn't explicitly state when to use this tool versus alternatives. No sibling tools appear to be direct alternatives for airport searching, so the guidance is limited to implied context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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