# Google Cloud MCP服务
## 基本信息
- Slug: `krzko-google-cloud-mcp`
- Source: modelscope
- Publisher: @krzko/google-cloud-mcp
- Categories: cloud-platforms / databases / monitoring
- Hosted: No
- License: Apache License 2.0
- Source URL: https://www.modelscope.cn/mcp/servers/@krzko/google-cloud-mcp
## 简介
一种连接到 Google Cloud 服务的模型上下文协议服务器，允许用户通过自然语言交互查询日志、与 Spanner 数据库交互以及分析 Cloud Monitoring 指标。
## 安装提示

```bash
# Clone the repository git clone https://github.com/krzko/google-cloud-mcp.git cd google-cloud-mcp # Install dependencies pnpm install # Build pnpm build
```

## MCP Server 详情

# Google Cloud MCP 服务器

一个连接到 Google Cloud 服务的 Model Context Protocol 服务器，为与您的 Google Cloud 资源交互提供上下文和工具。

## 服务

支持的服务：

- [x] Google Cloud Logging
- [x] Google Cloud Monitoring
- [x] Google Cloud Spanner

正在开发中的服务：

- [ ] Google Cloud Trace
- [ ] Google IAM
- [ ] Google Cloud Compute
- [ ] Google Cloud Run
- [ ] Google Cloud Storage

### Google Cloud Logging

从 Google Cloud Logging 查询和过滤日志条目：

- 使用自定义过滤器查询日志
- 在特定时间范围内搜索日志
- 以可读格式格式化并显示日志条目

### Google Cloud Spanner

与 Google Cloud Spanner 数据库交互：

- 对 Spanner 数据库执行 SQL 查询
- 列出可用的数据库和表
- 探索数据库模式

### Google Cloud Monitoring

从 Google Cloud Monitoring 检索和分析指标：

- 使用自定义过滤器查询指标
- 随时间可视化指标数据
- 列出可用的指标类型

### Google Cloud Trace

从 Google Cloud Trace 分析分布式跟踪：

- 按 ID 检索跟踪
- 列出具有过滤选项的最近跟踪
- 查找与日志关联的跟踪
- 识别失败的跟踪
- 使用自然语言查询跟踪（例如，“显示过去一小时内失败的跟踪”）

## 认证

此服务器支持两种与 Google Cloud 的认证方法：

1. **服务账户密钥文件**（推荐）：将 `GOOGLE_APPLICATION_CREDENTIALS` 环境变量设置为您的服务账户密钥文件的路径。这是标准的 Google Cloud 认证方法。

2. **环境变量**：直接设置 `GOOGLE_CLIENT_EMAIL` 和 `GOOGLE_PRIVATE_KEY` 环境变量。这对于无法存储密钥文件的环境非常有用。

如果设置了 `GOOGLE_CLOUD_PROJECT` 环境变量，服务器将使用它；否则，它将尝试从认证凭据中确定项目 ID。

## 安装

```bash
# Clone the repository
git clone https://github.com/krzko/google-cloud-mcp.git
cd google-cloud-mcp

# Install dependencies
pnpm install

# Build
pnpm build
```


向 Google Cloud 进行身份验证：

```bash
gcloud auth application-default login
```


在客户端中配置 `mcpServers`：

```json
{
  "mcpServers": {
      "google-cloud-mcp": {
          "command": "node",
          "args": [
              "/Users/foo/code/google-cloud-mcp/dist/index.js"
          ],
          "env": {
              "GOOGLE_APPLICATION_CREDENTIALS": "/Users/foo/.config/gcloud/application_default_credentials.json"
          }
      }
  }
}
```


## 开发

### 启动服务器

```bash
# Build the project
pnpm build

# Start the server
pnpm start
```


### 开发模式

```bash
# Build the project
pnpm build

# Start the server and inspector
npx -y @modelcontextprotocol/inspector node dist/index.js
```


### 与 Smithery 一起使用（即将推出）

该服务器可以部署并与 Smithery 一起使用。服务器实现了认证的懒加载，这意味着它会立即启动，并推迟到实际需要时才进行认证。尽管操作仍然需要认证，但这种方法可以防止服务器初始化期间超时。

注意：Smithery 本地服务器支持目前还在开发中，可能尚未可用。

## 故障排除

### 服务器超时问题

如果您在使用 Smithery 运行服务器时遇到超时问题，请尝试以下方法：

1. 通过在配置中设置 `debug: true` 来启用调试日志
2. 确保 `lazyAuth: true` 设置为在实际需要时才进行身份验证
3. 确保证书文件可访问且有效
4. 检查日志中的任何错误消息

**重要提示**：操作仍然需要身份验证，但是启用了延迟加载后，服务器将立即启动，并在需要时进行身份验证，而不是在初始化期间。

### 身份验证问题

服务器支持两种身份验证方法：

1. **服务帐户密钥文件**：将 `GOOGLE_APPLICATION_CREDENTIALS` 环境变量设置为您的服务帐户密钥文件的路径
2. **环境变量**：设置 `GOOGLE_CLIENT_EMAIL` 和 `GOOGLE_PRIVATE_KEY` 环境变量

如果您遇到身份验证问题，请确保：
- 您的服务帐户具有必要的权限
- 密钥文件格式正确且可访问
- 环境变量已正确设置

