Sponsored by Deepsite.site

Baidu Map

Created By
baidu-maps9 months ago
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Content

百度地图 MCP Server

简介

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。关于MCP协议,详见MCP官方文档

目前提供的MCP工具列表包含8个核心API接口和MCP协议的对接, 涵盖逆地理编码、地点检索、路线规划等。

依赖MCP Python SDKMCP Typescript SDK开发,任意支持MCP协议的智能体助手(如ClaudeCursor以及千帆AppBuilder等)都可以快速接入。

以下会给更出详细的适配说明。

工具列表

  1. 地理编码 geocoder_v2

    • 将地址解析为对应的位置坐标
    • 输入: address
    • 输出: location
  2. 逆地理编码 reverse_geocoding_v3

    • 将坐标点转换为对应语义化地址
    • 输入: location
    • 输出: formatted_address, uid, addressComponent
  3. 地点检索 place_v2_search

    • 多种场景的地点(POI)检索,包括城市检索、圆形区域检索
    • 输入:
      • query 检索关键词
      • location 圆形检索的中心点
      • radius 圆形检索的半径
      • region 城市检索指定城市
    • 输出: POI列表,包含name, location, address
  4. 地点详情检索 place_v2_detail

    • 根据POI的uid,检索POI详情信息
    • 输入: uid
    • 输出: POI详情,包含name, location, address, brand, price
  5. 批量算路 routematrix_v2_driving

    • 根据起点和终点坐标,计算所有起终点组合间的路线距离和行驶时间
    • 输入:
      • origins 起点经纬度列表
      • destinations 终点经纬度列表
      • mode 出行类型,可选取值包括 drivingwalkingriding,默认使用driving
    • 输出: 每条路线的耗时和距离,包含distance, duration
  6. 路线规划 directionlite_v1

    • 根据起终点坐标规划出行路线和耗时,可指定驾车、步行、骑行、公交等出行方式
    • 输入:
      • origin 起点经纬度
      • destination 终点经纬度
      • model 出行类型,可选取值包括 drivingwalkingridingtransit,默认使用driving
    • 输出: 路线详情,包含steps, distance, duration
  7. 天气查询 weather_v1

    • 根据行政区划编码查询天气
    • 输入: district_id 行政区划编码
    • 输出: 天气信息,包含temperature, weather, wind
  8. IP定位 location_ip

    • 根据请求的IP获取当前请求的位置(定位到城市),如果当使用的是IPv6需要申请高级权限
    • 输入: 无
    • 输出: 当前所在城市和城市中点location

快速开始

使用百度地图MCP Server主要通过两种形式,分别是PythonTypescript,下面分别介绍。

获取AK

在选择两种方法之前,你需要在百度地图开放平台的控制台中创建一个服务端AK,通过AK你才能够调用百度地图API能力。

Python

搭建Python虚拟环境

我们推荐通过Python虚拟环境来运行MCP server,环境搭建的过程参考MCP官方文档

按照官方流程,你会安装Python包管理工具uv。除此之外,你也可以尝试其他方法(如Anaconda)来创建你的Python虚拟环境。

通过uv添加mcp依赖

uv add "mcp[cli]"

验证mcp依赖是否安装成功,执行如下命令

uv run mcp

当出现下图时代表安装成功

通过uv安装python,最低版本要求为3.11

uv python install 3.11

获取 MCP Server

前往百度地图 Mcp Server 官方开源仓库下载

配置本地项目

通过uv创建一个项目

uv init baidu_map_mcp_server

map.py拷贝到该目录下,通过如下命令测试mcp server是否正常运行

uv run --with mcp[cli] mcp run {替换成您的路径}/baidu_map_mcp_server/map.py
# 如果是mac,需要加转义符
uv run --with mcp\[cli\] mcp run {替换成您的路径}/baidu_map_mcp_server/map.py

如果没有报错则MCP Server启动成功

在Cursor中使用

打开Cursor配置,在MCP中添加MCP Server

在文件中添加如下内容后保存

{
  "mcpServers": {
    "baidu-map": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "{替换成您的路径}/baidu_map_mcp_server/map.py"
      ],
      "env": {
        "BAIDU_MAPS_API_KEY": "{您的AK}"
      }
    }
  }
}

回到配置,此时百度MCP Server已经启用

测试

行程规划:

Typescript接入

打开Claude for DesktopSetting,切换到Developer,点击Edit Config,用任意的IDE打开配置文件。

将以下配置添加到配置文件中,BAIDU_MAP_API_KEY 是访问百度地图开放平台API的AK,在此页面中申请获取:

{
    "mcpServers": {
        "baidu-map": {
            "command": "npx",
            "args": [
                "-y",
                "@baidumap/mcp-server-baidu-map"
            ],
            "env": {
                "BAIDU_MAP_API_KEY": "xxx"
            }
        }
    }
}

重启Claude,此时设置面板已经成功加载了百度地图MCP Server。在软件主界面对话框处可以看到有8个可用的MCP工具,点击可以查看详情。

接下来就可以进行提问,验证出行规划小助手的能力了。

通过千帆AppBuilder平台接入

千帆平台接入,目前支持SDK接入或是API接入,通过AppBuilder构建一个应用,每个应用拥有一个独立的app_id,在python文件中调用对应的app_id,再调用百度地图 Python MCP Tool即可。

模板代码可向下跳转,通过SDK Agent &&地图MCP Server,拿到导航路线及路线信息,并给出出行建议。

Agent配置

前往千帆平台,新建一个应用,并发布。

将Agent的思考轮数调到6。发布应用。

调用

此代码可以当作模板,以SDK的形式调用千帆平台上已经构建好且已发布的App,再将MCP Server下载至本地,将文件相对路径写入代码即可。

(注意:使用实际的app_id、token、query、mcp文件)

import os
import asyncio
import appbuilder
from appbuilder.core.console.appbuilder_client.async_event_handler import (
    AsyncAppBuilderEventHandler,
)
from appbuilder.modelcontextprotocol.client import MCPClient
class MyEventHandler(AsyncAppBuilderEventHandler):
    def __init__(self, mcp_client):
        super().__init__()
        self.mcp_client = mcp_client
    def get_current_weather(self, location=None, unit="摄氏度"):
        return "{} 的温度是 {} {}".format(location, 20, unit)
    async def interrupt(self, run_context, run_response):
        thought = run_context.current_thought
        # 绿色打印
        print("\033[1;31m", "-> Agent 中间思考: ", thought, "\033[0m")
        tool_output = []
        for tool_call in run_context.current_tool_calls:
            tool_res = ""
            if tool_call.function.name == "get_current_weather":
                tool_res = self.get_current_weather(**tool_call.function.arguments)
            else:
                print(
                    "\033[1;32m",
                    "MCP工具名称: {}, MCP参数:{}\n".format(tool_call.function.name, tool_call.function.arguments),
                    "\033[0m",
                )
                mcp_server_result = await self.mcp_client.call_tool(
                    tool_call.function.name, tool_call.function.arguments
                )
                print("\033[1;33m", "MCP结果: {}\n\033[0m".format(mcp_server_result))
                for i, content in enumerate(mcp_server_result.content):
                    if content.type == "text":
                        tool_res += mcp_server_result.content[i].text
            tool_output.append(
                {
                    "tool_call_id": tool_call.id,
                    "output": tool_res,
                }
            )
        return tool_output
    async def success(self, run_context, run_response):
        print("\n\033[1;34m", "-> Agent 非流式回答: ", run_response.answer, "\033[0m")
async def agent_run(client, mcp_client, query):
    tools = mcp_client.tools
    conversation_id = await client.create_conversation()
    with await client.run_with_handler(
        conversation_id=conversation_id,
        query=query,
        tools=tools,
        event_handler=MyEventHandler(mcp_client),
    ) as run:
        await run.until_done()
### 用户Token
os.environ["APPBUILDER_TOKEN"] = (
    ""
)
async def main():
    appbuilder.logger.setLoglevel("DEBUG")
    ### 发布的应用ID
    app_id = ""
    appbuilder_client = appbuilder.AsyncAppBuilderClient(app_id)
    mcp_client = MCPClient()
    
    ### 注意这里的路径为MCP Server文件在本地的相对路径
    await mcp_client.connect_to_server("./<YOUR_FILE_PATH>/map.py")
    print(mcp_client.tools)
    await agent_run(
        appbuilder_client,
        mcp_client,
        '开车导航从北京到上海',
    )
    await appbuilder_client.http_client.session.close()
if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
效果

经过Agent自己的思考,通过调用MCPServer 地点检索、地理编码服务、路线规划服务等多个tool,拿到导航路线及路线信息,并给出出行建议。

实际用户请求:“请为我计划一次北京赏花一日游。尽量给出更舒适的出行安排,当然,也要注意天气状况。”

思考过程

Agent结果

更新日志

版本功能说明更新日期
V1.0百度地图MCP Server正式上线2025年3月21日
V1.1补充uvxpip形式的快速接入---

Server Config

{
  "mcpServers": {
    "baidu-map": {
      "command": "npx",
      "args": [
        "-y",
        "@baidumap/mcp-server-baidu-map"
      ],
      "env": {
        "BAIDU_MAP_API_KEY": "xxx"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
DeepChatYour AI Partner on Desktop
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright McpPlaywright MCP server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Amap Maps高德地图官方 MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Serper MCP ServerA Serper MCP Server
CursorThe AI Code Editor
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"