Skip to main content
Glama

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/sdkzod)。所有 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

maps_static_map

Street View Static API

maps_street_view

Maps Embed API

maps_embed_url

Elevation API

maps_elevation

Geocoding API

places_geocode

Time Zone API

places_timezone

Places API (New)

places_details, places_text_search, places_nearby_search, places_autocomplete, places_photos

Address Validation API

places_address_validation

Routes API

routes_compute, routes_matrix

Route Optimization API

routes_optimize (optional)

生产环境中,你可以将密钥限制为仅用于这些 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_API_KEY

你的 Google Maps Platform API 密钥

MCP_AUTH_TOKEN

客户端必须在 X-Api-Key 请求头中发送的密钥令牌。仅限本地使用时可不设置;通过网络或代理暴露服务器时应设置。使用 openssl rand -hex 32 生成

PORT

HTTP 端口(默认:3003

GOOGLE_CLOUD_PROJECT_ID

routes_optimize(Route Optimization API)需要


连接客户端

此服务器可与任何兼容 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。

参数

类型

默认值

描述

center

string

必需

地址或 lat,lng

zoom

integer

13

缩放级别 0–21

size

string

640x480

图片尺寸,以像素为单位的 WxH

maptype

enum

roadmap

roadmap | satellite | terrain | hybrid

markers

string

标记规格,例如 color:red|48.8566,2.3522

path

string

用于绘制路线的路径规格

format

enum

png

png | png8 | png32 | gif | jpg

scale

enum

1

1 = 标准,2 = HiDPI/retina

language

string

用于标签的 BCP 47 语言代码

region

string

ISO 3166-1 alpha-2 地区代码


maps_embed_url — 地图嵌入 URL

返回一个可直接用于 iframe 的嵌入 URL。

参数

类型

描述

mode

enum

place | directions | search | view | streetview

q

string

地点/搜索查询(place、search 模式)

center

string

view/streetview 模式下的 lat,lng

zoom

integer

缩放级别

origin / destination

string

用于 directions 模式

waypoints

string

以竖线分隔的途经点

maptype

enum

roadmap | satellite


maps_elevation — 海拔数据

返回海拔高度(米,海平面以上)。

参数

类型

描述

locations

string

以竖线分隔的 lat,lng 坐标对

path

string

以竖线分隔的 lat,lng 路径

samples

integer

路径上的采样点数量(2–512)


maps_street_view — 街景图片

返回街景全景图的直接图片 URL。

参数

类型

默认值

描述

location

string

地址或 lat,lng

pano

string

特定全景 ID(覆盖 location)

size

string

640x480

图片尺寸 WxH

heading

number

相机朝向 0–360°

pitch

number

相机俯仰角 -90° 到 90°

fov

number

90

视野范围 10–120°

source

enum

outdoor 以排除室内全景


路线

routes_compute — 计算路线

提供实时路况的逐向导航。

TRANSIT 限制: TRANSIT 模式不支持 intermediates(途经点)或路线修饰符(avoid_tollsavoid_highwaysavoid_ferries)。在 travel_mode: TRANSIT 下传入这些参数会返回明确错误——请改为分别计算各路段(A→B,然后 B→C)。

Parameter

Type

Default

Description

origin

string

required

地址或 lat,lng

destination

string

required

地址或 lat,lng

travel_mode

enum

DRIVE

DRIVE | WALK | BICYCLE | TRANSIT | TWO_WHEELER

transit_allowed_modes

enum[]

将公共交通筛选为特定车辆类型:BUS | SUBWAY | TRAIN | LIGHT_RAIL | RAIL。仅在 travel_modeTRANSIT 时适用

intermediates

string[]

起点和终点之间的途经点(不支持 TRANSIT

departure_time

string

用于交通感知路由的 ISO 8601 日期时间

avoid_tolls

boolean

false

避开收费道路(不支持 TRANSIT

avoid_highways

boolean

false

避开高速公路(不支持 TRANSIT

avoid_ferries

boolean

false

避开渡轮(不支持 TRANSIT

units

enum

METRIC

METRIC | IMPERIAL

compute_alternative_routes

boolean

false

最多返回 3 个备选路线


routes_matrix — 路线距离矩阵

同时计算多个起点和终点之间的旅行时间/距离。

Parameter

Type

Default

Description

origins

string[]

required

最多 25 个地址或 lat,lng 字符串

destinations

string[]

required

最多 25 个地址或 lat,lng 字符串

travel_mode

enum

DRIVE

DRIVE | WALK | BICYCLE | TRANSIT

departure_time

string

ISO 8601 日期时间

units

enum

METRIC

METRIC | IMPERIAL


routes_optimize — 优化多停靠点路线

优化停靠点顺序以最小化总行程时间。需要 GOOGLE_CLOUD_PROJECT_ID

Parameter

Type

Description

vehicle_start

string

起始位置 — 必须为 lat,lng(如有需要请先进行地理编码)

vehicle_end

string

结束位置(默认为起始位置)

visits

object[]

{ address, label?, duration_minutes? } 数组 — 地址必须为 lat,lng

travel_mode

enum

DRIVING | WALKING


地点

places_geocode — 地理编码 / 反向地理编码

转换地址 ↔ 坐标。

Parameter

Type

Description

address

string

要地理编码的地址

latlng

string

用于反向地理编码的 lat,lng

region

string

ISO 3166-1 alpha-2 区域偏向

components

string

组件过滤器,例如 country:FR|postal_code:75001


places_details — 地点详情

获取按 Google 地点 ID 查询的完整地点详情。

Parameter

Type

Description

place_id

string

Google 地点 ID

fields

string

逗号分隔的字段掩码(具有合理的默认值)

language_code

string

响应语言


查找与自然语言查询匹配的地点。

Parameter

Type

Description

query

string

例如 "best ramen in Tokyo"

location_bias_lat/lng

number

将结果偏向此位置

location_bias_radius_m

number

偏置圆半径

max_results

integer

1–20,默认 10

min_rating

number

最低平均星级评分(0–5)

open_now

boolean

仅显示当前营业的地点

included_type

string

按地点类型筛选,例如 restaurant

price_levels

enum[]

PRICE_LEVEL_FREEPRICE_LEVEL_VERY_EXPENSIVE


查找坐标半径内的地点。

Parameter

Type

Description

latitude / longitude

number

搜索中心

radius_m

number

搜索半径(米)(最大 50,000)

included_types

string[]

地点类型筛选器

excluded_types

string[]

要排除的地点类型

max_results

integer

1–20,默认 10

rank_preference

enum

DISTANCE | POPULARITY


places_autocomplete — 地点自动补全

根据部分输入预测地点名称。

Parameter

Type

Description

input

string

用于补全的部分文本

location_bias_lat/lng

number

偏向此位置

included_primary_types

string[]

类型筛选器

country_codes

string[]

ISO 3166-1 alpha-2 国家/地区筛选器

include_query_predictions

boolean

同时返回查询预测


places_photos — 地点照片

获取地点的照片 URL。

Parameter

Type

Default

Description

place_id

string

required

Google 地点 ID

max_photos

integer

3

最多返回的照片数(1–10)

max_width_px

integer

1200

最大照片宽度(像素)

max_height_px

integer

900

最大照片高度(像素)


places_address_validation — 验证地址

验证并标准化邮政地址。

Parameter

Type

Description

address_lines

string[]

地址行

region_code

string

ISO 3166-1 alpha-2 国家/地区代码

locality

string

城市/城镇

administrative_area

string

州/省

postal_code

string

邮政编码

enable_usps_cass

boolean

USPS CASS 验证(仅限美国)


places_timezone — 获取时区

获取任何坐标的 IANA 时区以及 UTC/DST 偏移量。

Parameter

Type

Description

latitude / longitude

number

位置

timestamp

integer

用于夏令时计算的 Unix 时间戳(默认为当前时间)

language

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_tollsavoid_highwaysavoid_ferries)现在会返回清晰、可操作的错误,而不是来自 Google API 的难以理解的 400 错误。

v1.0.3

  • routes_compute:添加了 transit_allowed_modes 参数,用于按车辆类型(BUSSUBWAYTRAINLIGHT_RAILRAIL)筛选公共交通路线。

v1.0.2

  • 初始公开发布,包含 Maps、Routes 和 Places 类别中的 15 个工具。

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
2wRelease cycle
3Releases (12mo)
Commit activity

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

  • A
    license
    B
    quality
    A
    maintenance
    A 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.
    7
    1,992
    428
    MIT

View all related MCP servers

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.

View all MCP Connectors

Latest Blog Posts

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