maps_weather
Get weather forecasts for any Chinese city by entering the city name or adcode to plan activities and travel with current conditions.
Instructions
根据城市名称或者标准adcode查询指定城市的天气
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes |
Input Schema (JSON Schema)
{
"properties": {
"city": {
"title": "City",
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
Implementation Reference
- amap_mcp_server/server.py:110-137 (handler)Implementation of the maps_weather tool: fetches current and forecast weather data for a specified city using the Amap weather API. Includes error handling for API requests and response validation.@mcp.tool() def maps_weather(city: str) -> Dict[str, Any]: """根据城市名称或者标准adcode查询指定城市的天气""" try: response = requests.get( "https://restapi.amap.com/v3/weather/weatherInfo", params={ "key": AMAP_MAPS_API_KEY, "city": city, "extensions": "all" } ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Get weather failed: {data.get('info') or data.get('infocode')}"} forecasts = data.get("forecasts", []) if not forecasts: return {"error": "No forecast data available"} return { "city": forecasts[0]["city"], "forecasts": forecasts[0]["casts"] } except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}