from urllib.parse import urlencode, quote_plus import gradio as gr from src.common.logger import get_logger from src.common.utils import format_docstring from src.tools.schemas.map_tools_schema import ( MapWalkingDirectionResult, ) logger = get_logger(__name__) ##### get_google_maps_walking_direction ##### def get_google_maps_walking_direction( origin: str, destination: str, waypoints: list[str] | None = None ) -> MapWalkingDirectionResult: """ Generates a Google Maps walking direction URL. """ params = { "api": "1", "origin": origin, "destination": destination, "travelmode": "walking", } if waypoints: # Google Maps expects pipe-separated waypoints params["waypoints"] = "|".join(waypoints) params["dir_action"] = "navigate" # urlencode will properly escape commas, pipes, spaces, etc. query = urlencode(params, quote_via=quote_plus, safe="|,") return MapWalkingDirectionResult( map_url=f"https://www.google.com/maps/dir/?{query}" ) @format_docstring( template_args={"return_schema": MapWalkingDirectionResult._model_json_schema} ) @gr.mcp.tool( name="gm_walking_dir_tool", ) async def gm_walking_dir_tool( origin: str, destination: str, waypoints: list[str] | None = None ) -> str: """ Generates a Maps walking direction route. Args: origin: The origin of the route, it can be a string like "40.1777,44.5126" or "Republic Square, Yerevan" destination: The destination of the route, it can be a string like "40.1777,44.5126" or "Republic Square, Yerevan" waypoints: The waypoints of the route, it can be a list of strings like ["40.1810,44.5140", "40.1850,44.5160"] or ["Republic Square, Yerevan", "40.1850,44.5160"], by default None Returns: {return_schema} """ result = get_google_maps_walking_direction(origin, destination, waypoints) return result.model_dump_json()