使用说明
GCP MCP服务器
全面 模型上下文协议(MCP)服务器 这使人工智能助手能够与您的谷歌云平台环境无缝交互。基于TypeScript构建,在8个主要的GCP服务类别中提供25多种工具。
✨ 主要特点
- 🤖 人工智能原生:所有GCP操作的自然语言界面
- 🔐 安全:使用您现有的GCP凭据(无需外部访问)
- 🌐 多项目:跨多个GCP项目和地区无缝工作
- ⚡ 全面的:25种工具,涵盖计算、存储、数据库、无服务器等
- 🛠️ 开发者友好:完整的TypeScript实现,具有出色的错误处理能力
- 🔄 可靠的:内置重试逻辑和强大的错误处理
- 📊 可观察对象:用于调试和监控的全面日志记录
🚀 快速开始
先决条件
- Node.js v18或更高版本
- 谷歌云SDK 已配置身份验证
- 克劳德桌面, 光标, 帆板运动,或任何与MCP兼容的AI助手
安装和设置
-
使用GCP进行身份验证:
gcloud auth application-default login -
通过NPX安装 (推荐):
npx gcp-mcp-server -
配置您的AI助手:
克劳德桌面 -添加到
claude_desktop_config.json:{ "mcpServers": { "gcp": { "command": "npx", "args": ["-y", "gcp-mcp-server"] } } }光标 -添加到MCP设置:
{ "gcp": { "command": "npx", "args": ["-y", "gcp-mcp-server"] } }帆板运动 -添加到
~/.windsurf/config.json:{ "mcpServers": { "gcp": { "command": "npx", "args": ["-y", "gcp-mcp-server"] } } -
重启你的AI助手 并开始与您的GCP环境聊天!
🛠️ 可用工具(共25个)
🔧 核心管理(5个工具)
| 工具 | 说明 |
|---|---|
run-gcp-code |
针对GCP API执行自定义TypeScript代码 |
list-projects |
列出所有可访问的GCP项目 |
select-project |
选择一个项目进行后续操作 |
get-billing-info |
获取账单信息和状态 |
get-cost-forecast |
获取成本预测数据 |
� 计算引擎(4个工具)
| 工具 | 说明 |
|---|---|
list-compute-instances |
列出VM实例(按区域或所有区域) |
get-compute-instance |
获取详细的实例信息 |
start-compute-instance |
启动已停止的实例 |
stop-compute-instance |
停止正在运行的实例 |
🗄️ 云存储(3个工具)
| 工具 | 说明 |
|---|---|
list-storage-buckets |
列出所有存储桶 |
list-storage-objects |
列出特定存储桶中的对象 |
get-storage-object-info |
获取特定对象的元数据 |
📊 BigQuery(3个工具)
| 工具 | 说明 |
|---|---|
list-bigquery-datasets |
列出所有BigQuery数据集 |
list-bigquery-tables |
列出数据集中的表 |
query-bigquery |
在BigQuery上执行SQL查询 |
🗃️ 云SQL(2个工具)
| 工具 | 说明 |
|---|---|
list-sql-instances |
列出所有Cloud SQL实例 |
get-sql-instance |
获取详细的实例信息 |
⚡ 云功能(2个工具)
| 工具 | 说明 |
|---|---|
list-cloud-functions |
列出所有云功能 |
get-cloud-function |
获取详细的功能信息 |
🏃 云运行(2个工具)
| 工具 | 说明 |
|---|---|
list-cloud-run-services |
列出所有Cloud Run服务 |
get-cloud-run-service |
获取详细的服务信息 |
🚢 谷歌Kubernetes引擎(2个工具)
| 工具 | 说明 |
|---|---|
list-gke-clusters |
列出所有GKE集群 |
get-gke-cluster |
获取详细的集群信息 |
📝 云日志(2个工具)
| 工具 | 说明 |
|---|---|
query-logs |
使用过滤器查询云日志 |
list-log-entries |
列出最近的日志条目 |
💡 对话示例
入门指南
User: "Show me all my GCP projects"
Assistant: [Lists all accessible projects with IDs and names]
User: "Use project my-web-app-prod"
Assistant: [Selects project and shows available regions]
基础设施管理
User: "List all running compute instances in us-west1"
Assistant: [Shows VM instances with status, machine type, and IPs]
User: "What storage buckets do I have?"
Assistant: [Lists buckets with size, location, and storage class]
User: "Show me my Cloud Run services"
Assistant: [Displays services with URLs, traffic allocation, and status]
数据与分析
User: "What BigQuery datasets are in my project?"
Assistant: [Lists datasets with creation time and location]
User: "Query my sales table for last month's revenue"
Assistant: [Executes SQL and returns results]
成本管理
User: "What's my current billing status?"
Assistant: [Shows billing account, budget alerts, and current usage]
User: "Forecast my costs for the next 3 months"
Assistant: [Displays cost predictions based on usage trends]
故障排除
User: "Show me error logs from my app in the last hour"
Assistant: [Queries Cloud Logging and displays relevant errors]
User: "Why is my Cloud Function timing out?"
Assistant: [Analyzes function configuration and recent logs]
🏗️ 建筑
服务器采用干净的模块化架构构建:
src/
├── types/ # TypeScript type definitions
├── utils/ # Utilities (logging, errors, state management)
├── tools/ # Tool definitions and handlers
│ ├── definitions.ts
│ └── handlers.ts
├── config.ts # Configuration constants
├── server.ts # MCP server implementation
└── index.ts # Application entry point
🔧 发展
地方发展设置
# Clone the repository
git clone https://github.com/startupmanch/gcp-mcp-server
cd gcp-mcp-server
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
可用脚本
npm run dev # Development mode with auto-reload
npm run build # Production build
npm run start # Start built server
npm run test # Run test suite
npm run lint # Lint code
npm run format # Format code with Prettier
npm run clean # Clean build artifacts
MCP检验员测试
# Build and test with MCP Inspector
npm run build
npx @modelcontextprotocol/inspector ./bin.js
📋 需求
- Node.js:版本18或更高版本
- 谷歌云SDK:正确配置和验证
- GCP项目:至少访问一个具有适当IAM权限的GCP项目
所需的GCP API
应在GCP项目中启用以下API:
- 云资源管理器API
- 计算引擎API
- 云存储API
- BigQuery API
- 云SQL管理API
- 云函数API
- 云运行API
- 云记录API
- 云计费API
- Kubernetes引擎API
� 安全和权限
所需IAM角色
您的GCP帐户需要以下角色(或等效的自定义角色):
roles/viewer(基本读取权限)roles/compute.viewer(计算引擎资源)roles/storage.objectViewer(云存储)roles/bigquery.user(BigQuery)roles/cloudsql.viewer(云SQL)roles/cloudfunctions.viewer(云功能)roles/run.viewer(云运行)roles/container.viewer(GKE)roles/logging.viewer(云日志)
安全功能
- 本地凭据:使用本地GCP身份验证
- 无外部访问:所有操作都在本地运行
- 最小特权原则:仅请求必要的权限
- 缺省巩固安全:未存储或传输凭据
🐛 故障排除
常见问题
身份验证错误
# Re-authenticate with GCP
gcloud auth application-default login
# Verify access
gcloud projects list
权限不足
- 验证您的IAM角色是否包括所需的权限
- 检查您的GCP项目中是否启用了API
服务器未启动
- 确保已安装Node.js v18+
- 验证是否配置了GCP凭据
- 检查服务器日志中的特定错误
调试模式
启用调试日志记录:
export LOG_LEVEL=debug
npx gcp-mcp-server
🤝 贡献
我们欢迎捐款!以下是如何开始:
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改 并添加测试
- 运行测试套件:
npm test - 提交您的更改:
git commit -m 'Add amazing feature' - 推到分支:
git push origin feature/amazing-feature - 打开拉取请求
开发指南
- 遵循TypeScript的最佳实践
- 添加新功能的测试
- 更新新功能的文档
- 遵循常规提交消息
- 提交前确保所有测试通过
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
由以下材料制成❤️ 面向人工智能和云社区
如需支持、功能请求或错误报告,请 打开一个问题 在GitHub上。