Skip to main content
Glama
jagan-shanmugam

OpenStreetMap MCP Server

analyze_commute

Analyze commute options between home and work locations by comparing transportation modes, travel times, distances, and turn-by-turn directions for informed decisions.

Instructions

Perform a detailed commute analysis between home and work locations.

This advanced tool analyzes commute options between two locations (typically home and work), comparing multiple transportation modes and providing detailed metrics for each option. Includes estimated travel times, distances, turn-by-turn directions, and other commute-relevant data. Essential for real estate decisions, lifestyle planning, and workplace relocation analysis.

Args: home_latitude: Home location latitude (decimal degrees) home_longitude: Home location longitude (decimal degrees) work_latitude: Workplace location latitude (decimal degrees) work_longitude: Workplace location longitude (decimal degrees) modes: List of transportation modes to analyze (options: "car", "foot", "bike") depart_at: Optional departure time (format: "HH:MM") for time-sensitive routing

Returns: Comprehensive commute analysis with: - Summary comparing all transportation modes - Detailed route information for each mode - Total distance and duration for each option - Turn-by-turn directions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
home_latitudeYes
home_longitudeYes
work_latitudeYes
work_longitudeYes
modesNo
depart_atNo

Implementation Reference

  • The core handler function for the 'analyze_commute' MCP tool. It performs detailed commute analysis by fetching reverse geocoding for addresses and routing data for multiple transportation modes (car, foot, bike) using the OSMClient, then compiles a comparison of options including distances, durations, and directions.
    @mcp.tool()
    async def analyze_commute(
        home_latitude: float,
        home_longitude: float,
        work_latitude: float,
        work_longitude: float,
        ctx: Context,
        modes: List[str] = ["car", "foot", "bike"],
        depart_at: str = None  # Time in HH:MM format, e.g. "08:30"
    ) -> Dict[str, Any]:
        """
        Perform a detailed commute analysis between home and work locations.
        
        This advanced tool analyzes commute options between two locations (typically home and work),
        comparing multiple transportation modes and providing detailed metrics for each option.
        Includes estimated travel times, distances, turn-by-turn directions, and other commute-relevant
        data. Essential for real estate decisions, lifestyle planning, and workplace relocation analysis.
        
        Args:
            home_latitude: Home location latitude (decimal degrees)
            home_longitude: Home location longitude (decimal degrees)
            work_latitude: Workplace location latitude (decimal degrees)
            work_longitude: Workplace location longitude (decimal degrees)
            modes: List of transportation modes to analyze (options: "car", "foot", "bike")
            depart_at: Optional departure time (format: "HH:MM") for time-sensitive routing
            
        Returns:
            Comprehensive commute analysis with:
            - Summary comparing all transportation modes
            - Detailed route information for each mode
            - Total distance and duration for each option
            - Turn-by-turn directions
        """
        osm_client = ctx.request_context.lifespan_context.osm_client
        
        # Get address information for both locations
        home_info = await osm_client.reverse_geocode(home_latitude, home_longitude)
        work_info = await osm_client.reverse_geocode(work_latitude, work_longitude)
        
        # Get commute information for each mode
        commute_options = []
        
        for mode in modes:
            ctx.info(f"Calculating {mode} route for commute analysis")
            
            # Get route from OSRM
            try:
                route_data = await osm_client.get_route(
                    home_latitude, home_longitude,
                    work_latitude, work_longitude,
                    mode
                )
                
                if "routes" in route_data and len(route_data["routes"]) > 0:
                    route = route_data["routes"][0]
                    
                    # Extract directions
                    steps = []
                    if "legs" in route:
                        for leg in route["legs"]:
                            for step in leg.get("steps", []):
                                steps.append({
                                    "instruction": step.get("maneuver", {}).get("instruction", ""),
                                    "distance": step.get("distance"),
                                    "duration": step.get("duration"),
                                    "name": step.get("name", "")
                                })
                    
                    commute_options.append({
                        "mode": mode,
                        "distance_km": round(route.get("distance", 0) / 1000, 2),
                        "duration_minutes": round(route.get("duration", 0) / 60, 1),
                        "directions": steps
                    })
            except Exception as e:
                ctx.warning(f"Error getting {mode} route: {str(e)}")
                commute_options.append({
                    "mode": mode,
                    "error": str(e)
                })
        
        # Sort by duration (fastest first)
        commute_options.sort(key=lambda x: x.get("duration_minutes", float("inf")))
        
        return {
            "home": {
                "coordinates": {
                    "latitude": home_latitude,
                    "longitude": home_longitude
                },
                "address": home_info.get("display_name", "Unknown location")
            },
            "work": {
                "coordinates": {
                    "latitude": work_latitude,
                    "longitude": work_longitude
                },
                "address": work_info.get("display_name", "Unknown location")
            },
            "commute_options": commute_options,
            "fastest_option": commute_options[0]["mode"] if commute_options else None,
            "depart_at": depart_at
        }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does well describing what the tool does (analysis, comparison, providing metrics) and mentions it's 'advanced' and 'time-sensitive routing', but doesn't cover important behavioral aspects like rate limits, authentication requirements, data freshness, or error conditions. The description doesn't contradict any annotations since none exist.

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 (purpose, capabilities, use cases, args, returns) and front-loaded with the core functionality. While comprehensive, it could be slightly more concise - some phrases like 'commute-relevant data' and 'lifestyle planning' could be tightened. Every sentence earns its place by adding value.

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

Completeness4/5

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

Given the tool's complexity (6 parameters, no annotations, no output schema), the description does a strong job covering purpose, parameters, and return values. It explains what the tool returns in detail despite no output schema. The main gap is lack of behavioral constraints and error handling information, which would be valuable for a tool with this many parameters and no annotations.

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

Parameters5/5

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

With 0% schema description coverage, the description must fully compensate, which it does excellently. It provides detailed semantic explanations for all 6 parameters: clarifying home/work coordinate pairs, listing available transportation modes with specific options, explaining the optional departure time's purpose and format. The description adds substantial meaning beyond what the bare schema provides.

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 tool's purpose with specific verbs ('analyze', 'compare', 'provide') and resources ('commute options between two locations', 'multiple transportation modes', 'detailed metrics'). It distinguishes from siblings by focusing specifically on commute analysis between home/work locations rather than general routing or nearby searches.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool ('essential for real estate decisions, lifestyle planning, and workplace relocation analysis'), but doesn't explicitly state when NOT to use it or mention specific alternatives among the sibling tools. It implies usage for commute-specific analysis but lacks explicit comparison to similar tools like 'get_route_directions'.

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/jagan-shanmugam/open-streetmap-mcp'

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