用于云运行的Google Maps MCP服务器
一种谷歌地图模型上下文协议(MCP)服务器,专为在谷歌云运行上部署而设计,可供公众访问。该服务器通过一个安全的、有费率限制的API为Claude Desktop客户端提供谷歌地图功能。
特性
- 路线计算:具有实时交通数据的最佳驾驶路线
- 路线比较:比较具有不同选项的多个路由备选方案
- 路况:当前交通状况和旅行时间分析
- 成本估算:行程成本计算,包括燃料和通行费估算
- 公共访问:无需身份验证即可轻松共享
- 速率限制:每个IP地址每小时50个请求
- 云运行优化:专为GCP上的无服务器部署而设计
先决条件
- 启用计费的Google Cloud Platform帐户
- 谷歌云CLI(
gcloud)已安装并配置 - Node.js 18+用于本地开发
- 启用了所需API的Google Maps API密钥
所需的谷歌地图API
在部署之前,请在GCP项目中启用这些API:
- API指南 -用于路线计算
- 地理编码API -用于地址解析
- 映射JavaScript API -用于折线编码(可选)
通过以下方式启用API 谷歌云控制台 或CLI:
gcloud services enable directions-backend.googleapis.com
gcloud services enable geocoding-backend.googleapis.com
gcloud services enable maps-backend.googleapis.com快速开始
1.获取谷歌地图API密钥
- 首选 谷歌云控制台>凭据
- 新建API密钥或使用现有密钥
- 将密钥限制为上面列出的所需API
- 注意API密钥以进行部署
2.部署到云端运行
# Clone the repository
git clone
cd google-maps-mcp-cloudrun
# Set your Google Maps API key
export GOOGLE_MAPS_API_KEY="your-api-key-here"
# Deploy using the provided script
./simple-deploy.sh your-gcp-project-id us-central13.提取服务URL
部署后,提取您的服务URL:
# Get the service URL
SERVICE_URL=$(gcloud run services describe google-maps-mcp \
--region us-central1 \
--format="value(status.url)")
echo "Your MCP Server URL: $SERVICE_URL/sse"手动部署
如果您更喜欢手动部署:
# Set your project
gcloud config set project YOUR_PROJECT_ID
# Enable required services
gcloud services enable run.googleapis.com cloudbuild.googleapis.com
# Deploy
gcloud run deploy google-maps-mcp \
--source . \
--region us-central1 \
--platform managed \
--allow-unauthenticated \
--set-env-vars GOOGLE_MAPS_API_KEY="your-api-key-here" \
--memory 1Gi \
--cpu 1 \
--max-instances 10 \
--timeout 300 \
--port 8080Claude桌面配置
将此配置添加到您的Claude Desktop设置中:
{
"mcpServers": {
"google-maps": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://YOUR-SERVICE-URL.run.app/sse"
]
}
}
}替换 YOUR-SERVICE-URL.run.app 使用您的实际Cloud Run服务URL。
查找您的Claude桌面配置
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%/Claude/claude_desktop_config.json
可用工具
MCP服务器为Claude提供以下工具:
- 计算路由 -根据交通量计算最佳驾驶路线
- 比较路线 -比较多条路线备选方案
- get_live_traft -获取当前交通状况
- 估算成本 -计算行程成本(燃料+通行费)
服务端点
- MCP端点:
https://your-service.run.app/sse - 健康检查:
https://your-service.run.app/health - 使用情况统计:
https://your-service.run.app/stats
地方发展
# Install dependencies
npm install
# Copy environment template
cp .env.example .env
# Edit .env with your API key
# GOOGLE_MAPS_API_KEY=your-api-key-here
# Start development server
npm run dev
# Test locally
npm test故障排除
常见部署问题
1.拒绝许可
# Error: Permission denied
gcloud auth login
gcloud config set project YOUR_PROJECT_ID2.API未启用
# Error: API not enabled
gcloud services enable run.googleapis.com
gcloud services enable cloudbuild.googleapis.com3.未启用计费
- 访问 GCP计费控制台
- 为您的项目启用计费
4.API密钥无效
# Check API key restrictions in Console
# Ensure Directions API and Geocoding API are enabled5.服务无法启动
# Check logs for errors
gcloud run services logs read google-maps-mcp --region us-central1 --limit 50常见运行时问题
速率限制
- 每个IP每小时限制为50个请求
- 检查
/stats当前使用的端点 - 考虑实施更高限制的用户身份验证
超过API配额
- 在中监控您的Google Maps API使用情况 GCP控制台
- 必要时增加配额
- 考虑为重复请求实现缓存
测试您的部署
# Test health endpoint
curl "https://your-service.run.app/health"
# Test stats endpoint
curl "https://your-service.run.app/stats"
# Test with Claude Desktop
# Add the configuration and try asking Claude to calculate a route安全考虑
- API密钥存储为环境变量(安全)
- 服务允许公众访问(无需身份验证)
- 速率限制可防止滥用(每个IP每小时50个请求)
- 没有记录或存储敏感数据
成本管理
- 云运行:按请求付费定价
- 谷歌地图API:每个API-呼叫付费定价
- 监控:使用GCP计费警报来跟踪成本
设置账单提醒:
# Set up billing budget alerts in GCP Console
# Billing > Budgets & Alerts文档链接
支持和故障排除资源
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 彻底测试
- 提交拉取请求
______________________________________________________________________
备注:此服务器专为开发和测试目的而设计。对于高流量的生产使用,考虑实施额外的安全措施和监控。
