GCP-MCP管理工具
通过标准化的MCP接口,启用AI助手与Google Cloud Platform资源进行交互和管理,包括计算引擎、Cloud Run、存储、BigQuery和其他GCP服务。
服务介绍
这不是一个准备就绪的 MCP 服务器
GCP MCP 服务器
一个针对 Google Cloud Platform (GCP) 服务的全面 Model Context Protocol (MCP) 服务器实现,使 AI 助手能够通过标准化接口与 GCP 资源进行交互和管理。
概览
GCP MCP 服务器为 AI 助手提供了以下功能:
- 查询 GCP 资源:获取关于您的云基础设施的信息
- 管理云资源:创建、配置和管理 GCP 服务
- 获得帮助:获得有关 GCP 配置和最佳实践的 AI 指导帮助
该实现遵循 MCP 规范,以安全可控的方式让 AI 系统与 GCP 服务交互。
支持的 GCP 服务
此实现包括对以下 GCP 服务的支持:
- Artifact Registry:容器和包管理
- BigQuery:数据仓库和分析
- Cloud Audit Logs:日志记录和审计跟踪分析
- Cloud Build:CI/CD 管道管理
- Cloud Compute Engine:虚拟机实例
- Cloud Monitoring:指标、警报和仪表板
- Cloud Run:无服务器容器部署
- Cloud Storage:对象存储管理
架构
项目结构如下:
gcp-mcp-server/
├── core/ # Core MCP server functionality auth context logging_handler security
├── prompts/ # AI assistant prompts for GCP operations
├── services/ # GCP service implementations
│ ├── README.md # Service implementation details
│ └── ... # Individual service modules
├── main.py # Main server entry point
└── ...
关键组件:
- 服务模块:每个 GCP 服务都有自己的模块,包含资源、工具和提示
- 客户端实例:集中式客户端管理,用于身份验证和资源访问
- 核心组件:MCP 服务器实现的基础功能
开始使用
前提条件
- Python 3.10+
- 启用了您要使用的 API 的 GCP 项目
- 经过身份验证的 GCP 凭据(推荐使用默认应用凭据)
安装
-
克隆仓库:
git clone https://github.com/yourusername/gcp-mcp-server.git cd gcp-mcp-server -
设置虚拟环境:
python -m venv venv source venv/bin/activate # 在 Windows 上:venv\Scripts\activate -
安装依赖项:
pip install -r requirements.txt -
配置您的 GCP 凭据:
# 使用 gcloud gcloud auth application-default login # 或设置 GOOGLE_APPLICATION_CREDENTIALS export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json" -
设置环境变量:
cp .env.example .env # 编辑 .env 文件以配置您的设置
运行服务器
启动 MCP 服务器:
python main.py
对于开发和测试:
# Development mode with auto-reload
python main.py --dev
# Run with specific configuration
python main.py --config config.yaml
Docker 部署
使用 Docker 构建和运行:
# Build the image
docker build -t gcp-mcp-server .
# Run the container
docker run -p 8080:8080 -v ~/.config/gcloud:/root/.config/gcloud gcp-mcp-server
配置
可以通过环境变量或配置文件来配置服务器:
| 环境变量 | 描述 | 默认值 |
|---|---|---|
GCP_PROJECT_ID |
默认的 GCP 项目 ID | 无(必填) |
GCP_DEFAULT_LOCATION |
默认区域/区域 | us-central1 |
MCP_SERVER_PORT |
服务器端口 | 8080 |
LOG_LEVEL |
日志级别 | INFO |
请参阅 .env.example 获取完整的配置选项列表。
开发
添加新的 GCP 服务
- 在
services/目录中创建一个新文件 - 按照现有服务中的模式实现服务
- 在
main.py中注册该服务
有关详细的实现指导,请参阅 services README。
安全注意事项
- 服务器使用应用程序默认凭据进行身份验证
- 授权由已验证身份的权限决定
- 服务实现中没有硬编码任何凭据
- 考虑使用具有适当权限的服务账户运行
贡献
欢迎贡献!请随时提交 Pull Request。
- 分叉仓库
- 创建您的功能分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 打开 Pull Request
许可证
此项目根据 MIT 许可证授权 - 详情请参见 LICENSE 文件。
致谢
- Google Cloud Platform 团队提供了全面的 API
- Model Context Protocol 为 AI 与服务交互提供了一种标准化方式
使用服务器
要使用此服务器:
- 将您的 GCP 服务账户密钥文件作为
service-account.json放在同一个目录下 - 安装 MCP 包:
pip install "mcp[cli]" - 安装所需的 GCP 包:
pip install google-cloud-run - 运行:
mcp dev gcp_cloudrun_server.py
或者在 Claude Desktop 中安装:
mcp install gcp_cloudrun_server.py --name "GCP Cloud Run Manager"
MCP 服务器配置
可以将以下配置添加到您的配置文件中以用于 GCP Cloud Tools:
"mcpServers": {
"GCP Cloud Tools": {
"command": "uv",
"args": [
"run",
"--with",
"google-cloud-artifact-registry>=1.10.0",
"--with",
"google-cloud-bigquery>=3.27.0",
"--with",
"google-cloud-build>=3.0.0",
"--with",
"google-cloud-compute>=1.0.0",
"--with",
"google-cloud-logging>=3.5.0",
"--with",
"google-cloud-monitoring>=2.0.0",
"--with",
"google-cloud-run>=0.9.0",
"--with",
"google-cloud-storage>=2.10.0",
"--with",
"mcp[cli]",
"--with",
"python-dotenv>=1.0.0",
"mcp",
"run",
"C:\\Users\\enes_\\Desktop\\mcp-repo-final\\gcp-mcp\\src\\gcp-mcp-server\\main.py"
],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "C:/Users/enes_/Desktop/mcp-repo-final/gcp-mcp/service-account.json",
"GCP_PROJECT_ID": "gcp-mcp-cloud-project",
"GCP_LOCATION": "us-east1"
}
}
}
配置详细信息
此配置设置了一个用于 Google Cloud Platform 工具的 MCP 服务器,包含以下内容:
- 命令:使用
uv包管理器运行服务器 - 依赖项:包括各种 Google Cloud 库(Artifact Registry、BigQuery、Cloud Build 等)
- 环境变量:
GOOGLE_APPLICATION_CREDENTIALS: 您的 GCP 服务账户凭据路径GCP_PROJECT_ID: 您的 Google Cloud 项目 IDGCP_LOCATION: GCP 区域 (us-east1)
用法
将此配置添加到您的 MCP 配置文件中,以启用 GCP Cloud Tools 功能。