Skip to main content
Glama
masx200

AMap Maps MCP Server

by masx200

maps_geo

Convert structured addresses or landmark names into precise latitude and longitude coordinates for location-based applications and mapping services.

Instructions

将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes待解析的结构化地址信息
cityNo指定查询的城市

Implementation Reference

  • The handleGeo function that executes the maps_geo tool logic: queries Amap geocoding API, parses response to extract location details.
    async function handleGeo(address, city, sig) {
      const url = new URL("https://restapi.amap.com/v3/geocode/geo");
      url.searchParams.append("key", AMAP_MAPS_API_KEY);
      url.searchParams.append("address", address);
      url.searchParams.append("source", "ts_mcp");
      const response = await fetch(url.toString());
      const data = await response.json();
      if (data.status !== "1") {
        return {
          content: [{
            type: "text",
            text: `Geocoding failed: ${data.info || data.infocode}`,
          }],
          isError: true,
        };
      }
      const geocodes = data.geocodes || [];
      const res = geocodes.length > 0
        ? geocodes.map((geo) => ({
          country: geo.country,
          province: geo.province,
          city: geo.city,
          citycode: geo.citycode,
          district: geo.district,
          street: geo.street,
          number: geo.number,
          adcode: geo.adcode,
          location: geo.location,
          level: geo.level,
        }))
        : [];
      return {
        content: [{
          type: "text",
          text: JSON.stringify(
            {
              return: res,
            },
            null,
            2,
          ),
        }],
        isError: false,
      };
    }
  • Input schema and metadata for the maps_geo tool.
    const GEO_TOOL = {
      name: "maps_geo",
      description:
        "将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "待解析的结构化地址信息",
          },
          city: {
            type: "string",
            description: "指定查询的城市",
          },
        },
        required: ["address"],
      },
    };
  • build/index.js:247-260 (registration)
    maps_geo tool (GEO_TOOL) is registered in the MAPS_TOOLS array returned by ListToolsRequestSchema.
    const MAPS_TOOLS = [
      REGEOCODE_TOOL,
      GEO_TOOL,
      IP_LOCATION_TOOL,
      WEATHER_TOOL,
      SEARCH_DETAIL_TOOL,
      BICYCLING_TOOL,
      WALKING_TOOL,
      DRIVING_TOOl,
      TRANSIT_INTEGRATED_TOOL,
      DISTANCE_TOOL,
      TEXT_SEARCH_TOOL,
      AROUND_SEARCH_TOOL,
    ];
  • build/index.js:851-922 (registration)
    Registration of CallToolRequestSchema handler with switch case dispatching to handleGeo for maps_geo.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        switch (request.params.name) {
          case "maps_regeocode": {
            const { location } = request.params.arguments;
            return await handleReGeocode(location);
          }
          case "maps_geo": {
            const { address, city } = request.params.arguments;
            return await handleGeo(address, city);
          }
          case "maps_ip_location": {
            const { ip } = request.params.arguments;
            return await handleIPLocation(ip);
          }
          case "maps_weather": {
            const { city } = request.params.arguments;
            return await handleWeather(city);
          }
          case "maps_search_detail": {
            const { id } = request.params.arguments;
            return await handleSearchDetail(id);
          }
          case "maps_bicycling": {
            const { origin, destination } = request.params.arguments;
            return await handleBicycling(origin, destination);
          }
          case "maps_direction_walking": {
            const { origin, destination } = request.params.arguments;
            return await handleWalking(origin, destination);
          }
          case "maps_direction_driving": {
            const { origin, destination } = request.params.arguments;
            return await handleDriving(origin, destination);
          }
          case "maps_direction_transit_integrated": {
            const { origin, destination, city, cityd } = request.params.arguments;
            return await handleTransitIntegrated(origin, destination, city, cityd);
          }
          case "maps_distance": {
            const { origins, destination, type } = request.params.arguments;
            return await handleDistance(origins, destination, type);
          }
          case "maps_text_search": {
            const { keywords, city, citylimit } = request.params.arguments;
            return await handleTextSearch(keywords, city, citylimit);
          }
          case "maps_around_search": {
            const { location, radius, keywords } = request.params.arguments;
            return await handleAroundSearch(location, radius, keywords);
          }
          default:
            return {
              content: [{
                type: "text",
                text: `Unknown tool: ${request.params.name}`,
              }],
              isError: true,
            };
        }
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error: ${
              error instanceof Error ? error.message : String(error)
            }`,
          }],
          isError: true,
        };
      }
    });
  • Identical handler function for maps_geo tool in the HTTP server variant.
    async function handleGeo(address, city, sig) {
      const AMAP_MAPS_API_KEY = getApiKey();
      const url = new URL("https://restapi.amap.com/v3/geocode/geo");
      url.searchParams.append("key", AMAP_MAPS_API_KEY);
      url.searchParams.append("address", address);
      url.searchParams.append("source", "ts_mcp");
      const response = await fetch(url.toString());
      const data = await response.json();
      if (data.status !== "1") {
        return {
          content: [
            {
              type: "text",
              text: `Geocoding failed: ${data.info || data.infocode}`,
            },
          ],
          isError: true,
        };
      }
      const geocodes = data.geocodes || [];
      const res = geocodes.length > 0
        ? geocodes.map((geo) => ({
          country: geo.country,
          province: geo.province,
          city: geo.city,
          citycode: geo.citycode,
          district: geo.district,
          street: geo.street,
          number: geo.number,
          adcode: geo.adcode,
          location: geo.location,
          level: geo.level,
        }))
        : [];
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                return: res,
              },
              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