Skip to main content
Glama
Yang-Charles

Amap (Gaode Maps) MCP Server

by Yang-Charles

如何从零开始构建一个高德地图的MCP服务,涵盖了以下内容:

MCP服务的基本概念和配置

如何使用高德地图API进行IP定位和周边搜索

如何编写MCP服务的核心功能,包括配置管理、日志系统和高德地图SDK

如何编写MCP服务的主程序和入口

如何调试MCP服务,包括使用Inspector和编写测试代码

如何使用Makefile管理项目命令

如何配置MCP客户端连接到我们的服务

Related MCP server: Baidu Map Search MCP Server

配置开发环境

⚠ 请务必根据自己的操作系统调整命令,powershell 和 bash 的命令语法有所不同。

作者使用的是windows+git终端。 本教程前半段与官方基本无异,可查考官方文档中server开发示例

安装UV

# Linux or macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

创建虚拟环境初始化项目

# 使用UV创建并进入项目目录
uv init build-mcp
cd build-mcp

# 创建虚拟环境
uv venv
source .venv/Scripts/activate

# 安装相关依赖
uv add mcp[cli] httpx pytest

src/build_mcp/config.yaml 文件中添加以下内容:

# 高德地图API配置
api_key: test
# 高德地图API的基础URL
base_url: https://restapi.amap.com
# 代理设置
proxy: 
# 日志等级
log_level: INFO
# 接口重试次数
max_retries: 5
# 接口重试间隔时间(秒)
retry_delay: 1
# 指数退避因子
backoff_factor: 2
# 日志文件路径
log_dir: /var/log/build_mcp

config.yaml 文件需要放在 src/build_mcp/ 目录下,这样在加载配置时可以正确找到。

安装代码

⚠ 首次安装代码时需要使用 pip install -e . 命令,这样可以将当前目录作为一个可编辑的包安装到虚拟环境中。这样在开发过程中对代码的修改会立即生效,无需重新安装。

uv pip install -e .

通过以下命令来运行 MCP 服务:

启动stdio协议的MCP服务:

uv run build_mcp

启动streamable-http协议的MCP服务:

uv run build_mcp streamable-http

2.使用Inspector进行测试

Inspector是官方提供的一个MCP服务调试工具,可以通过它来启动一个本地web界面,在界面中可以直接调用MCP服务的工具。 相对更加直观和易用,比较推荐这种方式,详情可以查看官方文档

# 使用Inspector调试stdio协议的MCP服务
API_KEY=你的KEY mcp dev src/build_mcp/__init__.py

如何使用这个MCP服务?

首先你得拥有一个MCP客户端,目前市场上各种类型得MCP客户端层出不穷,至于用什么全凭你的爱好了。

这里有一份非常详细的MCP客户端使用攻略,是github上一个非常棒的项目:MCP客户端使用攻略

选择一个客户端下载安装,然后我们对我们开发的服务进行配置。

配置Stdio协议的MCP服务

{
    "mcpServers": {
        "build_mcp": {
            "command": "uv",
            "args": [
                "run",
                "-m"
                "build_mcp"
            ],
            "env": {
                "API_KEY": "你的高德API Key"
            }
        }
    }
}

⚠ 要注意本地UV环境,如果安装了多个UV可能会导致环境混乱,这是开发过程中比较头疼的一点,要自己注意。

配置Streamable-HTTP协议的MCP服务

启动项目

make streamable-http
$ make streamable-http
Starting MCP service with streamable-http protocol...
uv run build_mcp streamable-http

INFO: 🚀 Starting MCP server with transport type: streamable-http
INFO:     Started server process [6064]
INFO:     Waiting for application startup.
INFO:    StreamableHTTP session manager started                                                                                                                                     streamable_http_manager.py:109
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

启动成功后会在8000端口启动一个HTTP服务。

客户端配置

{
    "mcpServers": {
        "build_mcp_http": {
            "url": "http://localhost:8000/mcp"
        }
    }
}

Available Tools

2 tools
locate_ipC

获取用户的 IP 地址定位信息,返回省市区经纬度等信息。

ParametersJSON Schema
NameRequiredDescriptionDefault
ipNo用户的ip地址

Output Schema

ParametersJSON Schema
NameRequiredDescription
dataNo
metaNo
errorNo
successYes

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the output format but doesn't describe error handling, rate limits, authentication needs, or whether the tool is read-only or has side effects. For a tool with no annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the purpose and output. It avoids unnecessary words, though it could be slightly more structured (e.g., separating purpose from output details).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, no nested objects) and the presence of an output schema, the description is minimally adequate. However, it lacks behavioral context (e.g., error cases, performance), which is needed since no annotations are provided. The output schema likely covers return values, so the description doesn't need to detail them.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'ip' documented as '用户的ip地址' (user's IP address). The description doesn't add meaning beyond the schema, such as explaining default behavior when 'ip' is null or providing examples. Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '获取用户的 IP 地址定位信息' (get user's IP address location information) and specifies the output '返回省市区经纬度等信息' (returns province, city, district, latitude/longitude, etc.). It uses specific verbs and resources, though it doesn't explicitly differentiate from the sibling tool 'search_nearby'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_nearby'. It lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_nearbyB

根据经纬度和关键词进行周边搜索,返回指定半径内的 POI 列表。

ParametersJSON Schema
NameRequiredDescriptionDefault
locationYes中心点经纬度,格式为 'lng,lat',如 '116.397128,39.916527'
keywordsNo搜索关键词,例如: '餐厅'。
typesNoPOI 分类码,多个分类用逗号分隔
radiusNo搜索半径(米),最大50000
page_numNo页码,从1开始
page_sizeNo每页数量,最大25

Output Schema

ParametersJSON Schema
NameRequiredDescription
dataNo
metaNo
errorNo
successYes

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the basic operation (search and return POI list) but doesn't describe important behavioral aspects like whether this is a read-only operation, potential rate limits, authentication requirements, error conditions, or what happens when no results are found. For a search tool with 6 parameters and no annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core functionality without unnecessary words. It's appropriately sized for the tool's complexity and front-loads the essential information (search based on location/keywords, returns POIs within radius). Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's an output schema (which should document return values), no annotations, and 100% schema coverage for parameters, the description provides adequate basic context. However, for a search tool with pagination parameters and no behavioral annotations, the description could better address usage patterns, result limitations, or common scenarios. It's minimally viable but lacks depth for optimal agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly. The description mentions '经纬度和关键词' (longitude/latitude and keywords) and '指定半径' (specified radius), which aligns with parameters in the schema but doesn't add meaningful semantic context beyond what's already in the parameter descriptions. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据经纬度和关键词进行周边搜索,返回指定半径内的 POI 列表' (Search nearby based on longitude/latitude and keywords, returning a list of POIs within a specified radius). It specifies the verb ('搜索' - search), resource ('POI 列表' - POI list), and scope ('周边' - nearby/within radius). However, it doesn't explicitly differentiate from the sibling tool 'locate_ip', which appears to be a different type of location tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'locate_ip' or any other potential alternatives. There's no information about prerequisites, appropriate contexts, or when this tool would be preferred over other search or location tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv1.0.0
    • Changedlocate_ip1 field changed
      • addedInput schema / title
        Added value: +"locate_ipArguments"
    • Changedsearch_nearby1 field changed
      • addedInput schema / title
        Added value: +"search_nearbyArguments"
  2. 2 tool updates
    • First observedlocate_ip
    • First observedsearch_nearby

TDQS

B3.1/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have completely distinct purposes: one retrieves location data from an IP address, while the other searches for points of interest near given coordinates. There is no overlap in functionality or ambiguity in their intended use.

Naming Consistency5/5

Both tools follow a consistent verb_noun naming pattern (locate_ip and search_nearby), using clear, descriptive verbs that align with their actions. The naming style is uniform and predictable across the set.

Tool Count2/5

With only two tools, the server feels under-scoped for a mapping service like Amap, which typically involves broader functionality such as routing, geocoding, or traffic data. This limited set may hinder agents from performing comprehensive mapping-related tasks.

Completeness2/5

The toolset is severely incomplete for a maps domain, lacking essential operations like geocoding addresses, calculating routes, or retrieving traffic information. Agents will face significant gaps when trying to handle common mapping workflows.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables location-based services through AMap/AutoNavi Maps API including geocoding, weather information, route planning, and POI searches. Supports multiple transportation modes and provides detailed geographic data for Chinese locations.
    12
    3
    Mulan Permissive Software , Version 2
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides a suite of tools for location retrieval and multi-modal route planning within China using the Baidu Maps API. It enables AI agents to perform address-to-coordinate conversions, nearby place searches, and calculate directions for driving, transit, walking, and cycling.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides comprehensive geographic information services and route planning for AI agents via the Amap (Gaode Maps) API. It supports geocoding, multi-modal navigation, POI searches, and administrative region queries.
    3
    -
  • A
    license
    A
    quality
    D
    maintenance
    Enables IP address location and latitude/longitude address queries, providing detailed geographic information such as country, province, city, and district.
    2
    6 npm
    MIT