Skip to main content
Glama

maps_weather

Get weather forecasts for Chinese cities using city names or adcodes to plan travel and outdoor activities.

Instructions

根据城市名称或者标准adcode查询指定城市的天气

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes

Implementation Reference

  • The main handler function for the 'maps_weather' tool. It takes a city parameter, calls the Amap weather API, and returns weather forecast data or an error.
    @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)}"}
  • The @mcp.tool() decorator registers the maps_weather function as an MCP tool.
    @mcp.tool()

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/sugarforever/amap-mcp-server'

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