google-maps-mcp
google-maps-mcp
一个 TypeScript 编写的 Model Context Protocol (MCP) 服务器,将 Google Maps Platform API 作为工具暴露给 LLM。它为 AI 助手提供真实、结构化的地图数据——方向、公交路线、地点搜索、地址验证、照片、海拔等——而不是依赖训练数据猜测。
可与 Claude Desktop 以及任何其他兼容 MCP 的客户端配合使用。
功能
三大类共 15 个工具:
分类 | 工具 |
地图 | 静态地图图片 URL、嵌入 URL(iframe)、海拔数据、街景图片 URL |
路线 | 逐向导航(驾车/步行/骑行/公交)、距离矩阵、多停靠点路线优化 |
地点 | 地理编码 / 反向地理编码、地点详情、文本搜索、附近搜索、自动补全、照片、地址验证、时区 |
传输方式:HTTP Streamable(有状态会话、SSE 保活)——现代 MCP 传输方式,兼容 mcp-remote 和所有支持 HTTP 的客户端。
极小依赖:仅有两个运行时依赖(@modelcontextprotocol/sdk、zod)。所有 Google Maps 调用均通过 Node.js 内置的 fetch 访问 REST API——无需 Google SDK。
Related MCP server: google-maps-mcp-server
先决条件
Node.js 22+(或 Docker)
mcp-remote — 全局安装一次:
npm install -g mcp-remote一个Google Maps Platform API 密钥,并启用相关 API(见下文)
一个已启用结算功能的 Google Cloud 项目
需要在 Google Cloud Console 中启用的 API
前往 APIs & Services → Library 并启用:
API | 使用方 |
Maps Static API |
|
Street View Static API |
|
Maps Embed API |
|
Elevation API |
|
Geocoding API |
|
Time Zone API |
|
Places API (New) |
|
Address Validation API |
|
Routes API |
|
Route Optimization API |
|
生产环境中,你可以将密钥限制为仅用于这些 API 以及你服务器的 IP。
快速开始
选项 A — 使用 Docker 运行(推荐)
docker run -d \
--name google-maps-mcp \
-p 127.0.0.1:3003:3003 \
-e GOOGLE_MAPS_API_KEY=your_key_here \
-e MCP_AUTH_TOKEN=your_secret_token \
ghcr.io/apurvaumredkar/google-maps-mcp:latest验证:
curl http://localhost:3003/health
# {"status":"ok","service":"google-maps-mcp"}选项 B — 通过 npm / npx
无需安装——直接使用 npx 运行:
GOOGLE_MAPS_API_KEY=your_key_here \
MCP_AUTH_TOKEN=your_secret_token \
npx mcp-server-google-maps
# google-maps-mcp listening on port 3003或全局安装:
npm install -g mcp-server-google-maps
GOOGLE_MAPS_API_KEY=your_key_here MCP_AUTH_TOKEN=your_secret_token mcp-server-google-maps设置 PORT= 可更改默认端口(3003)。
选项 C — 从源码构建
git clone https://github.com/apurvaumredkar/google-maps-mcp.git
cd google-maps-mcp
npm install
npm run build创建 .env 文件(或导出这些变量):
GOOGLE_MAPS_API_KEY=your_key_here
MCP_AUTH_TOKEN=your_secret_token
# Optional — only needed for routes_optimize:
GOOGLE_CLOUD_PROJECT_ID=your_project_id启动服务器:
GOOGLE_MAPS_API_KEY=... MCP_AUTH_TOKEN=... npm start
# google-maps-mcp listening on port 3003选项 D — Docker Compose(自托管技术栈)
添加到你的 docker-compose.yml:
services:
google-maps-mcp:
build: .
container_name: google-maps-mcp
restart: unless-stopped
ports:
- "127.0.0.1:3003:3003"
environment:
- GOOGLE_MAPS_API_KEY=${GOOGLE_MAPS_API_KEY}
- MCP_AUTH_TOKEN=${MCP_AUTH_TOKEN}
- GOOGLE_CLOUD_PROJECT_ID=${GOOGLE_CLOUD_PROJECT_ID:-}环境变量
变量 | 是否必需 | 描述 |
| 是 | 你的 Google Maps Platform API 密钥 |
| 否 | 客户端必须在 |
| 否 | HTTP 端口(默认: |
| 否 | 仅 |
连接客户端
此服务器可与任何兼容 MCP 的客户端配合使用——Claude Desktop、LM Studio、Cursor,或任何其他支持 Model Context Protocol 的工具。不同客户端的配置格式可能不同,但端点和身份验证是相同的。
服务器暴露单个端点:POST/GET http://localhost:3003/mcp
如果设置了 MCP_AUTH_TOKEN,所有请求都必须包含以下请求头:
X-Api-Key: <MCP_AUTH_TOKEN>如果未设置 MCP_AUTH_TOKEN,则无需请求头(适合仅限本地使用)。
Claude Desktop(示例)
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)或 %APPDATA%\Claude\claude_desktop_config.json(Windows):
{
"mcpServers": {
"google-maps": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:3003/mcp",
"--header",
"X-Api-Key: your_secret_token"
]
}
}
}工具参考
地图
maps_static_map — 静态地图图片
返回静态地图的直接图片 URL。
参数 | 类型 | 默认值 | 描述 |
| string | 必需 | 地址或 |
| integer |
| 缩放级别 0–21 |
| string |
| 图片尺寸,以像素为单位的 WxH |
| enum |
|
|
| string | — | 标记规格,例如 |
| string | — | 用于绘制路线的路径规格 |
| enum |
|
|
| enum |
|
|
| string | — | 用于标签的 BCP 47 语言代码 |
| string | — | ISO 3166-1 alpha-2 地区代码 |
maps_embed_url — 地图嵌入 URL
返回一个可直接用于 iframe 的嵌入 URL。
参数 | 类型 | 描述 |
| enum |
|
| string | 地点/搜索查询(place、search 模式) |
| string | view/streetview 模式下的 |
| integer | 缩放级别 |
| string | 用于 directions 模式 |
| string | 以竖线分隔的途经点 |
| enum |
|
maps_elevation — 海拔数据
返回海拔高度(米,海平面以上)。
参数 | 类型 | 描述 |
| string | 以竖线分隔的 |
| string | 以竖线分隔的 |
| integer | 路径上的采样点数量(2–512) |
maps_street_view — 街景图片
返回街景全景图的直接图片 URL。
参数 | 类型 | 默认值 | 描述 |
| string | — | 地址或 |
| string | — | 特定全景 ID(覆盖 location) |
| string |
| 图片尺寸 WxH |
| number | — | 相机朝向 0–360° |
| number | — | 相机俯仰角 -90° 到 90° |
| number |
| 视野范围 10–120° |
| enum | — |
|
路线
routes_compute — 计算路线
提供实时路况的逐向导航。
TRANSIT 限制:
TRANSIT模式不支持intermediates(途经点)或路线修饰符(avoid_tolls、avoid_highways、avoid_ferries)。在travel_mode: TRANSIT下传入这些参数会返回明确错误——请改为分别计算各路段(A→B,然后 B→C)。
Parameter | Type | Default | Description |
| string | required | 地址或 |
| string | required | 地址或 |
| enum |
|
|
| enum[] | — | 将公共交通筛选为特定车辆类型: |
| string[] | — | 起点和终点之间的途经点(不支持 |
| string | — | 用于交通感知路由的 ISO 8601 日期时间 |
| boolean |
| 避开收费道路(不支持 |
| boolean |
| 避开高速公路(不支持 |
| boolean |
| 避开渡轮(不支持 |
| enum |
|
|
| boolean |
| 最多返回 3 个备选路线 |
routes_matrix — 路线距离矩阵
同时计算多个起点和终点之间的旅行时间/距离。
Parameter | Type | Default | Description |
| string[] | required | 最多 25 个地址或 |
| string[] | required | 最多 25 个地址或 |
| enum |
|
|
| string | — | ISO 8601 日期时间 |
| enum |
|
|
routes_optimize — 优化多停靠点路线
优化停靠点顺序以最小化总行程时间。需要 GOOGLE_CLOUD_PROJECT_ID。
Parameter | Type | Description |
| string | 起始位置 — 必须为 |
| string | 结束位置(默认为起始位置) |
| object[] |
|
| enum |
|
地点
places_geocode — 地理编码 / 反向地理编码
转换地址 ↔ 坐标。
Parameter | Type | Description |
| string | 要地理编码的地址 |
| string | 用于反向地理编码的 |
| string | ISO 3166-1 alpha-2 区域偏向 |
| string | 组件过滤器,例如 |
places_details — 地点详情
获取按 Google 地点 ID 查询的完整地点详情。
Parameter | Type | Description |
| string | Google 地点 ID |
| string | 逗号分隔的字段掩码(具有合理的默认值) |
| string | 响应语言 |
places_text_search — 按文本搜索地点
查找与自然语言查询匹配的地点。
Parameter | Type | Description |
| string | 例如 |
| number | 将结果偏向此位置 |
| number | 偏置圆半径 |
| integer | 1–20,默认 10 |
| number | 最低平均星级评分(0–5) |
| boolean | 仅显示当前营业的地点 |
| string | 按地点类型筛选,例如 |
| enum[] |
|
places_nearby_search — 搜索附近地点
查找坐标半径内的地点。
Parameter | Type | Description |
| number | 搜索中心 |
| number | 搜索半径(米)(最大 50,000) |
| string[] | 地点类型筛选器 |
| string[] | 要排除的地点类型 |
| integer | 1–20,默认 10 |
| enum |
|
places_autocomplete — 地点自动补全
根据部分输入预测地点名称。
Parameter | Type | Description |
| string | 用于补全的部分文本 |
| number | 偏向此位置 |
| string[] | 类型筛选器 |
| string[] | ISO 3166-1 alpha-2 国家/地区筛选器 |
| boolean | 同时返回查询预测 |
places_photos — 地点照片
获取地点的照片 URL。
Parameter | Type | Default | Description |
| string | required | Google 地点 ID |
| integer |
| 最多返回的照片数(1–10) |
| integer |
| 最大照片宽度(像素) |
| integer |
| 最大照片高度(像素) |
places_address_validation — 验证地址
验证并标准化邮政地址。
Parameter | Type | Description |
| string[] | 地址行 |
| string | ISO 3166-1 alpha-2 国家/地区代码 |
| string | 城市/城镇 |
| string | 州/省 |
| string | 邮政编码 |
| boolean | USPS CASS 验证(仅限美国) |
places_timezone — 获取时区
获取任何坐标的 IANA 时区以及 UTC/DST 偏移量。
Parameter | Type | Description |
| number | 位置 |
| integer | 用于夏令时计算的 Unix 时间戳(默认为当前时间) |
| string | 响应语言 |
架构
src/
├── index.ts # Raw Node.js HTTP server, auth, stateful session management
├── server.ts # McpServer instantiation + tool registration
├── maps-client.ts # Typed fetch wrappers for all Google Maps REST APIs
└── tools/
├── maps.ts # 4 tools: static map, embed, elevation, street view
├── routes.ts # 3 tools: compute route, matrix, optimize
└── places.ts # 8 tools: geocode, details, text search, nearby, autocomplete,
# photos, address validation, timezone关键设计决策:
原始
node:http而非 Express — 这是与 MCP SDK 内部基于 Hono 的请求处理正确互操作所必需的。Express 会预先消费请求体流,从而破坏StreamableHTTPServerTransport。有状态会话映射 —
mcp-remote和 SSE keep-alive 需要会话在请求之间持续存在。会话以Mcp-Session-Id头为键,并在传输关闭时清理。在读取正文前进行身份验证 —
X-Api-Key检查在任何正文流被触碰之前于头部进行,因此被拒绝的请求能够干净地排空。Google API 的身份验证拆分 — 旧版 REST API(Static Maps、Geocoding、Elevation、Timezone、Street View)使用
?key=查询参数;新 API(Places v1、Routes v2、Address Validation)使用X-Goog-Api-Key头。
开发
npm run dev # TypeScript watch mode (tsc --watch)
npm run build # Compile to dist/
npm start # Run compiled server更改后重建 Docker 镜像
docker compose build google-maps-mcp
docker compose up -d google-maps-mcp测试 MCP 端点
# Health check (no auth required)
curl http://localhost:3003/health
# MCP initialize (auth required)
TOKEN=your_secret_token
curl -s -X POST http://localhost:3003/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "X-Api-Key: $TOKEN" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1"}},"id":1}'
# List tools (use session ID from Mcp-Session-Id response header)
SESSION=<Mcp-Session-Id from above>
curl -s -X POST http://localhost:3003/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "X-Api-Key: $TOKEN" \
-H "Mcp-Session-Id: $SESSION" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":2}'Windows/WSL 注意事项:如果你的
.env文件使用 Windows CRLF 行尾,请使用tr -d '\r'提取值:TOKEN=$(grep MCP_AUTH_TOKEN .env | cut -d= -f2 | tr -d '\r')
变更日志
v1.0.4
routes_compute:为 TRANSIT 模式添加了早期验证 — 传递intermediates或路线修饰符(avoid_tolls、avoid_highways、avoid_ferries)现在会返回清晰、可操作的错误,而不是来自 Google API 的难以理解的 400 错误。
v1.0.3
routes_compute:添加了transit_allowed_modes参数,用于按车辆类型(BUS、SUBWAY、TRAIN、LIGHT_RAIL、RAIL)筛选公共交通路线。
v1.0.2
初始公开发布,包含 Maps、Routes 和 Places 类别中的 15 个工具。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityAmaintenanceA Model Context Protocol server that provides Google Maps API integration, allowing users to search locations, get place details, geocode addresses, calculate distances, obtain directions, and retrieve elevation data through LLM processing capabilities.71,992428MIT
- AlicenseAqualityDmaintenanceProduction-ready MCP server for Google Maps Platform APIs, providing 11 tools for directions, places, geocoding, traffic, and road data to empower AI agents with location intelligence.114Apache 2.0
- AlicenseAqualityDmaintenanceA TypeScript-based MCP server that integrates with Swagger/OpenAPI specifications to expose API endpoints as tools for Large Language Models (LLMs), enabling natural language interaction with any OpenAPI-compliant API.49MIT
- FlicenseNot gradedqualityDmaintenanceComprehensive MCP server for Google Maps APIs, enabling geocoding, place search and details, distance matrix, elevation, and directions through natural language.6
Related MCP Connectors
Live Google Maps business search, review, and photo data for AI agents over MCP.
Google Maps MCP Pack — geocoding, places, directions, distance matrix, elevation.
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/apurvaumredkar/google-maps-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server