query_weather
Retrieve real-time weather forecasts for cities, regions, and counties across China by providing the location name. Enables accurate weather updates for specific areas.
Instructions
根据城市、地区、区县名称查询当地实时天气预报情况
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"city": "<city>"
},
"name": "query_weather"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | 查询的城市名称,如北京、上海、广州、深圳、泰顺等;城市或区县或地区名使用简写,严格按照规范填写,否则会导致查询失败 |
Implementation Reference
- src/jweather_mcp_server/server.py:17-44 (handler)Full implementation of the query_weather tool, including decorator registration, input schema, and execution logic using JUHE Weather API.
@mcp.tool(name="query_weather", description="根据城市、地区、区县名称查询当地实时天气预报情况") async def query_weather( city: str = Field(description="查询的城市名称,如北京、上海、广州、深圳、泰顺等;城市或区县或地区名使用简写,严格按照规范填写,否则会导致查询失败") ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """根据城市、地区、区县名称查询当地实时天气预报情况""" url = f"{JUHE_WEATHER_API_BASE}/query" params = { "city": city, "key": JUHE_WEATHER_API_KEY } async with httpx.AsyncClient() as client: response = await client.post(url, params=params) data = response.json() if data["error_code"] == 0: result = data["result"] return [ types.TextContent( type="text", text=f"{result}" ) ] else: return [ types.TextContent( type="text", text=f"Error: {data['reason']}" ) ]