query_weather
Get current weather conditions for any city using this tool. Enter a city name to receive weather data for planning activities or travel.
Instructions
Query the weather
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | The City of the weather query |
Implementation Reference
- src/index.ts:306-338 (handler)Handler implementation for the query_weather tool, which fetches weather data based on city coordinates.
case "query_weather": { const city = String(request.params.arguments?.city); if (!city) { throw new Error("City is required"); } const cityCoordinates: Record<string, { lat: number; lon: number }> = { '哈尔滨': { lat: 45.75, lon: 126.65 }, '三亚': { lat: 18.25, lon: 109.51 }, '北京': { lat: 39.90, lon: 116.41 }, '上海': { lat: 31.23, lon: 121.47 }, '广州': { lat: 23.13, lon: 113.26 }, '深圳': { lat: 22.54, lon: 114.06 }, '成都': { lat: 30.57, lon: 104.07 }, '杭州': { lat: 30.27, lon: 120.16 }, '重庆': { lat: 29.56, lon: 106.55 }, '西安': { lat: 34.27, lon: 108.93 }, '武汉': { lat: 30.59, lon: 114.30 } }; // 获取城市经纬度,默认使用北京坐标 const coords = cityCoordinates[city] || { lat: 39.90, lon: 116.41 }; const url = `https://api.open-meteo.com/v1/forecast?latitude=${coords.lat}&longitude=${coords.lon}¤t_weather=true&hourly=temperature_2m,precipitation`; const weatherClient = new WeatherClient({ apiUrl: url }); const result = await weatherClient.getWeather({ city }); return { content: [{ type: "text", text: `The weather report is: ${JSON.stringify(result)}` }] }; } - src/index.ts:183-196 (registration)Tool definition and schema registration for query_weather.
{ name: "query_weather", description: "Query the weather", inputSchema: { type: "object", properties: { city: { type: "string", description: "The City of the weather query" } }, required: ["city"] } }