query_weather
Retrieve real-time weather data for a specific city using AMap's location services.
Instructions
The weather service of Amap. Query the weather of a given city.
Args:
city (str): The city to query the weather.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes |
Implementation Reference
- amap_mcp/server.py:44-46 (handler)Handler function for the query_weather MCP tool that logs the invocation and delegates execution to the AmapClient's async_query_weather method.async def query_weather(city: str): logger.info(f"query_weather is called.") return await async_client.async_query_weather(city)
- amap_mcp/server.py:37-43 (registration)Registers the 'query_weather' tool on the FastMCP server, including the tool description and input parameter specification.@mcp.tool( description="""The weather service of Amap. Query the weather of a given city. Args: city (str): The city to query the weather. """ )
- amap_mcp/amap/client.py:19-20 (helper)Wrapper method in AmapClient that forwards the query_weather request to the specialized AmapQueryWeatherClient's implementation.async def async_query_weather(self, city: str): return await self.query_weather_client.async_query_weather_impl(city)
- Core implementation of the weather query: constructs the API request to Amap's weather endpoint, performs asynchronous HTTP GET, parses JSON response, with logging and error handling.async def async_query_weather_impl(self, city: str): url = "https://restapi.amap.com/v3/weather/weatherInfo" request_data = { "city": city, "key": self.key } logger.info(f"request_data: {request_data}") try: response = await self.httpx_client.get(url, params=request_data) return response.json() except Exception as e: logger.error(f"error: {e}") raise e