Skip to main content
Glama

calculate_distance

Calculate great circle distance between two geographic coordinates for flight planning and aviation route analysis.

Instructions

Calculate great circle distance between two points.

Args: lat1: Latitude of first point in degrees lon1: Longitude of first point in degrees lat2: Latitude of second point in degrees lon2: Longitude of second point in degrees

Returns: JSON string with distance information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lat1Yes
lon1Yes
lat2Yes
lon2Yes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'calculate_distance' tool. It takes two pairs of latitude/longitude coordinates and computes the great circle distance, bearings, and returns a formatted JSON string using the great_circle_points helper.
    def calculate_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> str:
        """Calculate great circle distance between two points.
    
        Args:
            lat1: Latitude of first point in degrees
            lon1: Longitude of first point in degrees
            lat2: Latitude of second point in degrees
            lon2: Longitude of second point in degrees
    
        Returns:
            JSON string with distance information
        """
        try:
            # Calculate great circle route
            route = great_circle_points(
                lat1, lon1, lat2, lon2, step_km=1000000
            )  # Single segment
    
            return json.dumps(
                {
                    "distance_km": route["distance_km"],
                    "distance_nm": route["distance_nm"],
                    "initial_bearing_deg": route["initial_bearing_deg"],
                    "final_bearing_deg": route["final_bearing_deg"],
                    "coordinates": {
                        "start": {"lat": lat1, "lon": lon1},
                        "end": {"lat": lat2, "lon": lon2},
                    },
                },
                indent=2,
            )
    
        except Exception as e:
            return f"Distance calculation error: {str(e)}"
  • Registration of the calculate_distance tool in the FastMCP server using mcp.tool().
    mcp.tool(calculate_distance)
  • The great_circle_points helper function that performs the core geodesic calculation using geographiclib, generating points along the great circle and total distance. Used by the calculate_distance handler.
    def great_circle_points(
        lat1: float, lon1: float, lat2: float, lon2: float, step_km: float
    ) -> tuple[list[tuple[float, float]], float]:
        g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
        dist_m = g["s12"]
        line = Geodesic.WGS84.Line(lat1, lon1, g["azi1"])
        n = max(1, int(math.ceil((dist_m / 1000.0) / step_km)))
        pts = []
        for i in range(n + 1):
            s = min(dist_m, (dist_m * i) / n)
            p = line.Position(s)
            pts.append((p["lat2"], p["lon2"]))
        return pts, dist_m / 1000.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden. While it states what the tool does, it doesn't disclose important behavioral traits like units of measurement (e.g., kilometers, miles), precision, error handling for invalid coordinates, or computational characteristics. The mention of 'JSON string with distance information' is minimal and doesn't detail the response structure.

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 well-structured with clear sections for the main purpose, arguments, and returns. It's appropriately sized with no wasted sentences, though the 'Args:' and 'Returns:' formatting could be more integrated into natural language flow.

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's moderate complexity (4 required parameters, no annotations, but has output schema), the description is partially complete. It covers the basic purpose and parameters but lacks behavioral context and usage guidance. The output schema existence reduces the need to detail return values, but more operational context would be beneficial.

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 by clearly explaining all four parameters: 'lat1', 'lon1', 'lat2', 'lon2' as latitudes and longitudes in degrees. This adds essential meaning beyond the bare schema, though it could be enhanced with range constraints or coordinate system details.

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

Purpose5/5

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

The description clearly states the specific action ('calculate great circle distance') and the resources involved ('between two points'). It distinguishes itself from sibling tools like 'calculate_ground_track' or 'trajectory_sensitivity_analysis' by focusing specifically on distance calculation rather than broader trajectory or analysis functions.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'calculate_ground_track' and 'search_airports' that might involve distance calculations, there's no indication of when this specific distance calculation tool is preferred or what its limitations are.

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