Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
2025/03/29
Baidu Maps API now fully supports the MCP protocol, making it the first map service provider in China to be compatible with the MCP protocol.
The MCP Server provided by Baidu Maps includes 10 API interfaces that comply with MCP protocol standards, covering reverse geocoding, place search, route planning, and more.
Developed using the MCP Python SDK and MCP Typescript SDK, any intelligent agent assistant that supports the MCP protocol (such as Claude, Cursor, and Qianfan AppBuilder) can quickly integrate with it.
map_geocodeaddress address informationlocationmap_reverse_geocodelocation latitude and longitude coordinatesformatted_address, uid, addressComponentmap_search_placesquery search keywordslocation center point of circular searchradius radius of circular searchregion specified city for city searchname, location, address, etc.map_place_detailsuidname, location, address, brand, price, etc.map_distance_matrixorigins list of origin latitude and longitude coordinatesdestinations list of destination latitude and longitude coordinatesmode travel type, optional values include driving, walking, riding, default is drivingdistance, duration, etc.map_directionsorigin origin latitude and longitudedestination destination latitude and longitudemodel travel type, optional values include driving, walking, riding, transit, default is drivingsteps, distance, duration, etc.map_weatherlocation latitude and longitude coordinates requires users to have advanced permissions)district_id administrative division codelocation latitude and longitude coordinatestemperature, weather, wind, etc.map_ip_locationip request IP addresslocationmap_road_trafficmodel traffic query type (optional values include road, bound, polygon, around, default is road)road_name road name and direction, required when model=road (e.g.: Chaoyang Road southbound to northbound)city city name or city adcode, required when model=road (e.g.: Beijing)bounds latitude and longitude coordinates of the bottom-left and top-right corners of the area, required when model=bound (e.g.: 39.912078,116.464303;39.918276,116.475442)vertexes latitude and longitude coordinates of the vertices of the polygon area, required when model=polygon (e.g.: 39.910528,116.472926;39.918276,116.475442;39.916671,116.459056;39.912078,116.464303)center latitude and longitude coordinates of the center point of the circular area, required when model=around (e.g.: 39.912078,116.464303)radius radius of the circular area (meters), value range [1,1000], required when model=around (e.g.: 200)road_name, traffic_condition, etc.map_poi_extracttext_content text description information for extracting POI (complete tourism routes, itinerary planning, scenic spot recommendation descriptions, etc., for example: "Xinjiang Duku Highway and Tarim Lake are so beautiful, the experience from Dushanzi Grand Canyon to Tianshan Mysterious Grand Canyon is also very nice")name, location, etc.Using the Baidu Maps MCP Server is primarily through two forms, namely Python and Typescript, which are described below.
Before choosing between the two methods, you need to create a server-side AK in the Baidu Maps Open Platform console. You can only call Baidu Maps API capabilities through the AK.
To integrate through Typescript, you only need to install node.js.
When you can run the following in terminal:
node -vIt indicates that your node.js has been successfully installed.
Open Claude for Desktop's Setting, switch to Developer, click Edit Config, and open the configuration file with any IDE.
Add the following configuration to the configuration file. BAIDU_MAP_API_KEY is the AK for accessing the Baidu Maps Open Platform API, which can be obtained from this page:
{
"mcpServers": {
"baidu-map": {
"command": "npx",
"args": [
"-y",
"@baidumap/mcp-server-baidu-map"
],
"env": {
"BAIDU_MAP_API_KEY": "xxx"
}
}
}
}Restart Claude, and the Baidu Maps MCP Server will be successfully loaded in the settings panel. In the main interface dialog box, you can see 8 available MCP tools, and click to view details.
Now you can ask questions to verify the capabilities of the travel planning assistant.
Qianfan platform integration currently supports SDK or API integration. Build an application through AppBuilder, each application has a unique app_id, call the corresponding app_id in the python file, and then call the Baidu Maps Python MCP Tool.
You can jump down to the template code, which uses SDK Agent && Map MCP Server to obtain navigation routes and route information, and provides travel suggestions.
Go to the Qianfan Platform, create a new application, and publish it.
Set the Agent's thinking rounds to 6. Publish the application.
This code can be used as a template to call an App that has already been built and published on the Qianfan platform in the form of an SDK, and then download the MCP Server locally and write the relative path of the file into the code.
(Note: Use the actual app_id, token, query, mcp file)
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="Celsius"):
return "{} temperature is {} {}".format(location, 20, unit)
async def interrupt(self, run_context, run_response):
thought = run_context.current_thought
# Print in green
print("\033[1;31m", "-> Agent thinking: ", 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 tool name: {}, MCP parameters:{}\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 result: {}\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 non-streaming answer: ", 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()
### User Token
os.environ["APPBUILDER_TOKEN"] = (
""
)
async def main():
appbuilder.logger.setLoglevel("DEBUG")
### Published application ID
app_id = ""
appbuilder_client = appbuilder.AsyncAppBuilderClient(app_id)
mcp_client = MCPClient()
### Note that the path here is the relative path of the MCP Server file locally
await mcp_client.connect_to_server("./<YOUR_FILE_PATH>/map.py")
print(mcp_client.tools)
await agent_run(
appbuilder_client,
mcp_client,
'Driving navigation from Beijing to Shanghai',
)
await appbuilder_client.http_client.session.close()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())Through the Agent's own thinking, by calling multiple tools such as MCP Server place search, geocoding service, route planning service, etc., it obtains navigation routes and route information, and provides travel suggestions.
Actual user request: "Please plan a one-day flower viewing tour in Beijing for me. Try to provide a more comfortable travel arrangement, of course, also pay attention to the weather conditions."
In the Baidu Maps MCP Server:
The administrative division codes used are based on the Baidu adcode mapping table.
The latitude and longitude coordinates used are based on the National Bureau of Surveying and Mapping latitude and longitude coordinates gcj02ll, see Baidu Coordinate System for details.