Backend Development 7 min read

How to Integrate Baidu Map MCP Server into Java AI Apps with NPX

This guide explains how to quickly integrate Baidu Map's MCP protocol into Java AI applications using NPX, covering API key setup, configuration, core map APIs, and sample Java code for seamless location and routing services.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How to Integrate Baidu Map MCP Server into Java AI Apps with NPX

Background

MCP (Model Completion Protocol) has become the industry‑standard communication protocol for AI, enabling large language models (LLMs) to call external tools and services through a unified interface. Baidu Map is the first domestic map service provider to fully support MCP, allowing developers to invoke map capabilities in AI applications without complex low‑level development.

百度地图MCP服务架构
百度地图MCP服务架构

Advantages of Baidu Map MCP

One‑click integration : Simple configuration enables map capabilities in AI apps.

Comprehensive features : Provides eight core map APIs covering most geospatial needs.

Lightweight deployment : Supports NPX rapid deployment without heavy development.

Feature List

Baidu Map MCP Server currently offers the following core APIs:

Function

API Interface

Use Case

Geocoding

geocoder_v2

Convert address text to latitude/longitude coordinates

Reverse Geocoding

reverse_geocoding_v3

Convert coordinates to structured address

Place Search

place_v2_search

Search POI information around or within a specific area

Place Detail

place_v2_detail

Retrieve detailed information of a specific POI

Batch Routing

routematrix_v2_driving

Calculate driving distance and time for multiple origin‑destination pairs

Route Planning

directionlite_v1

Provide driving, walking, cycling, and public‑transport route planning

Weather Query

weather_v1

Get real‑time weather and forecasts for a city

IP Location

location_ip

Obtain approximate location based on IP address

Quick Start

Apply for Baidu Map API Key

百度地图开发者平台
百度地图开发者平台

Before using Baidu Map MCP Server, obtain an API key (AK) by visiting the Baidu Map Open Platform, creating a developer account, generating a server‑side AK, and saving it for later configuration.

Integrate via NPX

The simplest method is to deploy the MCP Server with the NPX command‑line tool.

Configuration Steps

Open the MCP‑compatible application settings (e.g., Claude for Desktop, Cherry).

Navigate to the Developer section.

Click the “Edit Config” button to open the configuration file.

Add the following configuration:

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

After configuration, AI applications can directly call Baidu Map functions such as route planning and place search.

Developer Integration

Java Integration Example

Add the following Maven dependency:

<code>&lt;dependency&gt;
  &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;
  &lt;artifactId&gt;langchain4j-mcp&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-beta2&lt;/version&gt;
&lt;/dependency&gt;</code>

Integration Code

<code>// Initialize AI model
ChatLanguageModel model = OpenAiChatModel.builder()
    .apiKey("YOUR_AI_MODEL_API_KEY")
    .modelName("qwen-max-latest")
    .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
    .logRequests(true)
    .logResponses(true)
    .build();

// Configure MCP transport
McpTransport transport = new StdioMcpTransport.Builder()
    .command(List.of("npx", "-y", "@baidumap/mcp-server-baidu-map"))
    .environment(Map.of("BAIDU_MAP_API_KEY", "YOUR_BAIDU_MAP_AK"))
    .build();

// Initialize MCP client
McpClient mcpClient = new DefaultMcpClient.Builder()
    .transport(transport)
    .logHandler(new DefaultMcpLogMessageHandler())
    .build();

// Set up tool provider
ToolProvider toolProvider = McpToolProvider.builder()
    .mcpClients(List.of(mcpClient))
    .build();

// Create AI service interface
Bot bot = AiServices.builder(Bot.class)
    .chatLanguageModel(model)
    .toolProvider(toolProvider)
    .build();

// Use the service
try {
    Result<String> chat = bot.chat("How do I get from Daxing Airport to the south gate of BUPT? Approximate travel time?");
    System.out.println(chat.getValue());
} finally {
    mcpClient.close(); // Ensure resources are released
}</code>

Real‑World Example

Demo in PIG AI Platform

PIG AI平台MCP配置界面
PIG AI平台MCP配置界面
PIG AI平台路线规划示例
PIG AI平台路线规划示例
JavaMCPbackend developmentAI integrationBaidu Map
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.