谷歌地图MCP服务器
用于谷歌地图的流式HTTP MCP服务器——搜索地点、获取详细信息和规划路线。
存储库:
作者 过度
用例
此MCP服务器专为 位置感知AI代理 在Apple Watch或iPhone等移动设备上运行。您的客户提供当前位置,AI可以:
- 查找附近的地方(餐馆、商店、加油站)
- 通过逐向导航获取路线
- 比较到多个目的地的距离
- 抵达前检查开放时间和评级
它还可以与其他MCP工具很好地配合使用,例如,与 特斯拉MCP 直接在车内设置导航目的地。
通知
此repo以两种方式工作:
- 作为一个 节点/HONO服务器 用于本地工作流
- 作为一个 Cloudflare工作人员 用于远程交互
特性
- ✅ 地点 --按文本或类型搜索附近的地方、餐馆、地标
- ✅ 详情 --获取小时数、评分、评论、照片、联系信息
- ✅ 路线 --计算步行、驾驶、交通方向
- ✅ 距离矩阵 --比较到多个目的地的距离
- ✅ 感知 --所有工具都适用于您当前的职位
- ✅ 双运行时 --Node.js/Bun或Cloudflare Workers
设计原则
- LLM友好:统一的工具,而不是1:1 API镜像
- 准备观看:专为具有位置上下文的AI代理而设计
- 智能默认值:1公里半径,10个结果,步行模式
- 清晰的反馈:将ID放置在后续查询可见的位置
______________________________________________________________________
安装
0.客户端设置
您的客户需要知道当前时间和您当前的位置,因为这两个值都将用于搜索和规划。
1.获取谷歌地图API密钥
- 首选 谷歌云控制台
- 创建新项目(或选择现有项目)
- 导航至 API和服务>库
- 启用 地点API(新增) 和 路线API
- 首选 API和服务>凭据
- 点击 创建凭据>API密钥
- (推荐)限制关键地点API和路线API
2.地方发展
cd google-maps-mcp
bun install
cp .env.example .env编辑 .env:
PORT=3000
AUTH_ENABLED=true
AUTH_STRATEGY=bearer
# Generate with: openssl rand -hex 32
BEARER_TOKEN=your-random-auth-token
# Your Google Maps API key
API_KEY=your-google-maps-api-key运行:
bun dev
# MCP: http://127.0.0.1:3000/mcp3.Cloudflare Worker(部署)
- 创建KV命名空间:
wrangler kv:namespace create TOKENS- 更新
wrangler.toml使用您的KV命名空间ID
- 设置秘密:
# Auth token for clients (generate it using: openssl rand -hex 32). This makes the connection to your MCP not open to everyone, but only to those who have this API key.
wrangler secret put BEARER_TOKEN
# Your Google Maps API key
wrangler secret put API_KEY- 部署:
wrangler deploy端点: https://..workers.dev/mcp
______________________________________________________________________
客户端配置
克劳德桌面/光标(本地)
{
"mcpServers": {
"google-maps": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:3000/mcp", "--transport", "http-only"],
"env": { "NO_PROXY": "127.0.0.1,localhost" }
}
}
}克劳德桌面/光标(Cloudflare Worker)
{
"mcpServers": {
"google-maps": {
"command": "npx",
"args": ["mcp-remote", "https://your-worker.workers.dev/mcp", "--transport", "http-only"]
}
}
}爱丽丝应用程序
添加为MCP服务器:
- 网址:
https://your-worker.workers.dev/mcp - 类型:
streamable-http - 头球
Authorization: Bearer
______________________________________________________________________
工具
search_places
通过文本查询或键入位置附近的位置来查找位置。
// Input
{
query?: string; // "sushi near Central Park"
location: { // Required: your current position
latitude: number;
longitude: number;
};
types?: string[]; // ["restaurant", "cafe"]
radius?: number; // Meters (default: 1000, max: 50000)
filters?: {
open_now?: boolean;
min_rating?: number; // 0-5
price_levels?: string[]; // PRICE_LEVEL_INEXPENSIVE, etc.
};
max_results?: number; // Default: 10, max: 20
sort_by?: "distance" | "rating" | "relevance";
}
// Output
- Restaurant Name (500m) ★4.5(234) $$ 🟢 Open
123 Main St, New York
ID: ChIJN1t_tDeuEmsRUsoyG83frY4使用query用于文本搜索,或types用于基于类别的附近搜索。
get_place
获取特定地点的详细信息。
// Input
{
place_id: string; // From search_places results
fields?: string[]; // ["basic", "contact", "hours", "reviews", "photos"]
}
// Output
Name: Central Park
Address: New York, NY, USA
Rating: 4.8 (50000 reviews)
Open Now: Yes
Hours: Monday: 6:00 AM – 1:00 AM, ...
Phone: +1 212-310-6600
Website: https://centralparknyc.org
Google Maps: https://maps.google.com/?cid=...get_route
计算路线或距离矩阵。
// Single destination → detailed route
{
origin: { latitude: 40.7128, longitude: -74.0060 };
destinations: [{ latitude: 40.7580, longitude: -73.9855 }];
mode?: "walk" | "drive" | "transit"; // Default: "walk"
options?: {
departure_time?: string; // ISO 8601 or "now"
include_steps?: boolean; // Turn-by-turn instructions
include_polyline?: boolean;
};
}
// Multiple destinations → distance matrix
{
origin: { latitude: 40.7128, longitude: -74.0060 };
destinations: [
{ latitude: 40.7580, longitude: -73.9855 },
{ latitude: 40.7484, longitude: -73.9857 },
"Empire State Building" // Address or place ID also works
];
mode?: "walk";
}
// Output (single)
Route Summary: via 5th Ave
Total Distance: 5.2 km
Total Duration: 62 minutes
Steps:
1.1. Head north on Broadway
1.2. Turn right onto E 42nd St
...
// Output (matrix)
Distances from origin to 3 destinations:
- To Times Square: 4.8 km, 58 min
- To Empire State: 3.2 km, 38 min
- To Central Park: 6.1 km, 73 min______________________________________________________________________
例子
1.查找附近的咖啡店
{
"name": "search_places",
"arguments": {
"types": ["cafe"],
"location": { "latitude": 40.7128, "longitude": -74.0060 },
"filters": { "open_now": true },
"sort_by": "distance"
}
}2.按文本搜索
{
"name": "search_places",
"arguments": {
"query": "best pizza in Manhattan",
"location": { "latitude": 40.7128, "longitude": -74.0060 },
"max_results": 5
}
}3.获取地点详细信息
{
"name": "get_place",
"arguments": {
"place_id": "ChIJN1t_tDeuEmsRUsoyG83frY4",
"fields": ["basic", "hours", "reviews"]
}
}4.步行方向
{
"name": "get_route",
"arguments": {
"origin": { "latitude": 40.7128, "longitude": -74.0060 },
"destinations": [{ "latitude": 40.7580, "longitude": -73.9855 }],
"mode": "walk",
"departure_time": "now",
"include_steps": true
}
}5.比较多个地点的距离
{
"name": "get_route",
"arguments": {
"origin": { "latitude": 40.7128, "longitude": -74.0060 },
"destinations": [
"Times Square, NYC",
"Central Park, NYC",
"Brooklyn Bridge, NYC"
],
"mode": "walk"
}
}______________________________________________________________________
HTTP端点
| 端点 | 方法 | 目的 |
|---|---|---|
/mcp | 发布 | MCP JSON-RPC 2.0 |
/health | GET | 健康检查 |
______________________________________________________________________
环境变量
Node.js(.env)
| 变量 | 必填 | 描述 |
|---|---|---|
API_KEY | ✓ | 谷歌地图平台API密钥 |
BEARER_TOKEN | ✓ | MCP客户端的认证令牌 |
PORT | 服务器端口(默认值:3000) | |
AUTH_ENABLED | 启用身份验证(默认值:true) | |
AUTH_STRATEGY | bearer (默认) |
Cloudflare员工
牧马人。汤姆:
AUTH_ENABLED = "true"
AUTH_STRATEGY = "bearer"秘密(通过设置 wrangler secret put):
BEARER_TOKEN--客户端的随机身份验证令牌API_KEY-谷歌地图平台API密钥
KV命名空间:
[[kv_namespaces]]
binding = "TOKENS"
id = "your-kv-namespace-id"______________________________________________________________________
故障排除
| 问题 | 解决方案 |
|---|---|
| 401未经授权 | 检查 BEARER_TOKEN 已设置,客户端发送 Authorization: Bearer |
| “未配置API密钥” | 设置 API_KEY 秘密: wrangler secret put API_KEY |
| “Places API error 403” | 在Google云控制台中启用Places API(新增) |
| “路由API错误404” | 在Google云控制台中启用路由API |
| 地点ID无效 | 地点ID过期。再次搜索以获取新的ID |
| KV命名空间错误 | 运行 wrangler kv:namespace create TOKENS 并更新wrangler.toml |
______________________________________________________________________
发展
bun dev # Start with hot reload
bun run typecheck # TypeScript check
bun run lint # Lint code
bun run build # Production build
bun start # Run production______________________________________________________________________
建筑
src/
├── shared/
│ └── tools/
│ ├── search-places.ts # Unified place search
│ ├── get-place.ts # Place details
│ └── get-route.ts # Routes & distance matrix
├── services/
│ └── google-maps.ts # Google Maps API client
├── config/
│ └── metadata.ts # Server & tool descriptions
├── index.ts # Node.js entry
└── worker.ts # Workers entry______________________________________________________________________
许可证
麻省理工学院
