maps_weather
Get weather forecasts for Chinese cities by entering city names or adcodes to plan activities and prepare for conditions.
Instructions
根据城市名称或者标准adcode查询指定城市的天气
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | 城市名称或者adcode |
Implementation Reference
- build/index.js:371-401 (handler)The main handler function for the 'maps_weather' tool. It queries the AMap weather API with the given city and returns formatted weather forecast data or an 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)The input schema definition for the 'maps_weather' tool, specifying the required 'city' parameter.const WEATHER_TOOL = { name: "maps_weather", description: "根据城市名称或者标准adcode查询指定城市的天气", inputSchema: { type: "object", properties: { city: { type: "string", description: "城市名称或者adcode", }, }, required: ["city"], }, };
- build/index.js:848-850 (registration)Registration of the tool list handler, which includes 'maps_weather' via MAPS_TOOLS array.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: MAPS_TOOLS, }));
- build/index.js:866-869 (registration)Dispatch registration in the CallToolRequestSchema switch statement, calling the handleWeather function.case "maps_weather": { const { city } = request.params.arguments; return await handleWeather(city); }
- build/streamable-http.js:145-181 (handler)Duplicate handler function for 'maps_weather' in the HTTP server version, identical logic.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, }; }