Skip to main content
Glama
masx200

AMap Maps MCP Server

by masx200

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
NameRequiredDescriptionDefault
cityYes城市名称或者adcode

Implementation Reference

  • 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, };
  • 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); }
  • 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, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/masx200/amap-maps-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server