GCP模型上下文协议服务器

一个为Google Cloud Platform(GCP)服务实现的全面模型上下文协议(MCP)服务器,使AI助手能够通过标准化接口与GCP资源交互和管理。

  • by enesbol
  • Python
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 enesbol/gcp-mcp

使用说明

这不是就绪的MCP服务器

GCP MCP服务器

用于Google Cloud Platform(GCP)服务的全面模型上下文协议(MCP)服务器实现,使AI助手能够通过标准化接口与GCP资源进行交互和管理。

概述

GCP MCP Server为AI助手提供以下功能:

  • 查询GCP资源:获取有关云基础架构的信息
  • 管理云资源:创建、配置和管理GCP服务
  • 获得援助:获得人工智能指导的GCP配置和最佳实践帮助

该实现遵循MCP规范,使AI系统能够以安全、可控的方式与GCP服务交互。

支持的GCP服务

此实现包括对以下GCP服务的支持:

  • 工件注册表:集装箱和包装管理
  • BigQuery 的:数据仓库和分析
  • 云审计日志:日志记录和审计跟踪分析
  • 云构建:CI/CD管道管理
  • 云计算引擎:虚拟机实例
  • 云监控:指标、警报和仪表板
  • 云运行:无服务器容器部署
  • 云存储:对象存储管理

建筑

该项目的结构如下:

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凭据(建议使用应用程序默认凭据)

安装

  1. 克隆存储库:

    git clone https://github.com/yourusername/gcp-mcp-server.git
    cd gcp-mcp-server
    
  2. 设置虚拟环境:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. 安装依赖项:

    pip install -r requirements.txt
    
  4. 配置您的GCP凭据:

    # Using gcloud
    gcloud auth application-default login
    
    # Or set GOOGLE_APPLICATION_CREDENTIALS
    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"
    
  5. 设置环境变量:

    cp .env.example .env
    # Edit .env with your configuration
    

运行服务器

启动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服务

  1. 在中创建新文件 services/ 目录
  2. 按照现有服务中的模式实现服务
  3. 在中注册服务 main.py

请参阅 服务README 以获取详细的实施指导。

安全考虑

  • 服务器使用应用程序默认凭据进行身份验证
  • 授权由经过身份验证的身份的权限决定
  • 服务实现中没有硬编码凭据
  • 考虑使用具有适当权限的服务帐户运行

贡献

欢迎投稿!请随时提交拉取请求。

  1. 分叉存储库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add some amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

致谢

  • Google Cloud Platform团队提供全面的API
  • 模型上下文协议为人工智能与服务交互提供了一种标准化的方式

使用服务器

要使用此服务器,请执行以下操作:

  1. 将您的GCP服务帐户密钥文件放置为 service-account.json 在同一目录中
  2. 安装MCP包: pip install "mcp[cli]"
  3. 安装所需的GCP包: pip install google-cloud-run
  4. 运行: 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库(工件注册表、BigQuery、Cloud Build等)
  • 环境变量:
    • GOOGLE_APPLICATION_CREDENTIALS:GCP服务帐户凭据的路径
    • GCP_PROJECT_ID:您的Google Cloud项目ID
    • GCP_LOCATION:GCP地区(美国东部1)

用法

将此配置添加到MCP配置文件中,以启用GCP Cloud Tools功能。