maps_weather
Get weather information for any Chinese city by entering the city name or adcode to check current conditions and forecasts.
Instructions
根据城市名称或者标准adcode查询指定城市的天气
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | 城市名称或者adcode |
Implementation Reference
- build/index.js:371-401 (handler)Handler function that queries the Amap weather API for the given city and returns formatted weather forecast data or error.async function handleWeather(city) { const url = new URL("https://restapi.amap.com/v3/weather/weatherInfo"); url.searchParams.append("city", city); url.searchParams.append("key", AMAP_MAPS_API_KEY); url.searchParams.append("source", "ts_mcp"); url.searchParams.append("extensions", "all"); const response = await fetch(url.toString()); const data = await response.json(); if (data.status !== "1") { return { content: [{ type: "text", text: `Get weather failed: ${data.info || data.infocode}`, }], isError: true, }; } return { content: [{ type: "text", text: JSON.stringify( { city: data.forecasts[0].city, forecasts: data.forecasts[0].casts, }, null, 2, ), }], isError: false, };
- build/index.js:65-78 (schema)Input schema definition for the maps_weather tool, specifying the 'city' parameter.const WEATHER_TOOL = { name: "maps_weather", description: "根据城市名称或者标准adcode查询指定城市的天气", inputSchema: { type: "object", properties: { city: { type: "string", description: "城市名称或者adcode", }, }, required: ["city"], }, };
- build/index.js:866-869 (registration)Registration of the maps_weather tool in the switch statement handling CallToolRequestSchema.case "maps_weather": { const { city } = request.params.arguments; return await handleWeather(city); }
- build/streamable-http.js:145-181 (handler)Duplicate handler function in the HTTP server version that queries Amap weather API.async function handleWeather(city) { const AMAP_MAPS_API_KEY = getApiKey(); const url = new URL("https://restapi.amap.com/v3/weather/weatherInfo"); url.searchParams.append("city", city); url.searchParams.append("key", AMAP_MAPS_API_KEY); url.searchParams.append("source", "ts_mcp"); url.searchParams.append("extensions", "all"); const response = await fetch(url.toString()); const data = await response.json(); if (data.status !== "1") { return { content: [ { type: "text", text: `Get weather failed: ${data.info || data.infocode}`, }, ], isError: true, }; } return { content: [ { type: "text", text: JSON.stringify( { city: data.forecasts[0].city, forecasts: data.forecasts[0].casts, }, null, 2, ), }, ], isError: false, }; }
- build/streamable-http.js:709-722 (schema)Input schema definition for maps_weather in the HTTP server factory function.const WEATHER_TOOL = { name: "maps_weather", description: "根据城市名称或者标准adcode查询指定城市的天气", inputSchema: { type: "object", properties: { city: { type: "string", description: "城市名称或者adcode", }, }, required: ["city"], }, };