Google Cloud Documentation Agent - Google Cloud 文档查询工具
功能: - search_google_cloud_docs: 搜索 Google Cloud 文档 - get_google_cloud_doc: 获取完整文档内容 - list_google_cloud_mcp_tools: 列出 MCP 工具 - call_google_cloud_mcp_tool: 调用 MCP 工具 特性: - 支持 Google Cloud MCP API (BigQuery, Compute Engine, GKE, Maps) - 集成 Pydantic AI 进行结果整理和解释 - 提供 REST API 和 MCP 协议端点 - 支持 API Key 验证
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
# Google Cloud Documentation Agent
|
||||
|
||||
基于 **Pydantic AI** 和 **FastMCP** 的 Google Cloud 文档查询 Agent。
|
||||
|
||||
## 功能概述
|
||||
|
||||
Google Cloud Documentation Agent 提供以下功能:
|
||||
|
||||
- **搜索 Google Cloud 文档** - 在 Google Cloud 官方文档中搜索服务指南、API 参考、教程等
|
||||
- **获取文档内容** - 根据 URL 获取完整的文档内容
|
||||
- **列出 MCP 工具** - 查看 Google Cloud MCP 服务器提供的所有工具
|
||||
- **调用 MCP 工具** - 直接调用 Google Cloud MCP 服务器的工具
|
||||
|
||||
## 支持的 Google Cloud MCP 服务器
|
||||
|
||||
- **BigQuery**: `https://bigquery.googleapis.com/mcp`
|
||||
- **Compute Engine**: `https://compute.googleapis.com/mcp`
|
||||
- **GKE**: `https://container.googleapis.com/mcp`
|
||||
- **Maps Grounding Lite**: `https://mapstools.googleapis.com/mcp`
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 环境变量配置
|
||||
|
||||
```bash
|
||||
# LiteLLM Gateway 配置
|
||||
export LITELLM_GATEWAY_URL="https://litellm.graystone-fb459c5d.southeastasia.azurecontainerapps.io/v1"
|
||||
export OPENAI_API_KEY="your-api-key"
|
||||
|
||||
# Google Cloud MCP 服务器 URL(可选,使用默认值)
|
||||
export BIGQUERY_MCP_URL="https://bigquery.googleapis.com/mcp"
|
||||
export COMPUTE_MCP_URL="https://compute.googleapis.com/mcp"
|
||||
export GKE_MCP_URL="https://container.googleapis.com/mcp"
|
||||
export MAPS_MCP_URL="https://mapstools.googleapis.com/mcp"
|
||||
|
||||
# 服务端口(可选,默认 8000)
|
||||
export API_PORT=8000
|
||||
```
|
||||
|
||||
### 2. 本地测试
|
||||
|
||||
```bash
|
||||
cd google-cloud-docs
|
||||
pip install -r requirements.txt
|
||||
python run_api_server.py
|
||||
```
|
||||
|
||||
### 3. 构建镜像
|
||||
|
||||
```bash
|
||||
docker build -t google-cloud-docs:latest .
|
||||
```
|
||||
|
||||
### 4. 运行容器
|
||||
|
||||
```bash
|
||||
docker run -d -p 8000:8000 \
|
||||
-e LITELLM_GATEWAY_URL="https://..." \
|
||||
-e OPENAI_API_KEY="your-key" \
|
||||
google-cloud-docs:latest
|
||||
```
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
google-cloud-docs/
|
||||
├── Dockerfile
|
||||
├── requirements.txt
|
||||
├── run_api_server.py # 启动脚本
|
||||
└── src/
|
||||
├── __init__.py
|
||||
└── server/
|
||||
├── __init__.py
|
||||
├── api_server.py # FastAPI + MCP HTTP
|
||||
└── mcp_server.py # MCP 工具定义
|
||||
```
|
||||
|
||||
## API 端点
|
||||
|
||||
### REST API
|
||||
|
||||
- `GET /` - 服务信息
|
||||
- `GET /health` - 健康检查
|
||||
- `POST /api/v1/search` - 搜索文档(需要 API Key)
|
||||
- `POST /api/v1/doc` - 获取文档内容(需要 API Key)
|
||||
- `POST /api/v1/mcp-tools` - 列出 MCP 工具(需要 API Key)
|
||||
- `POST /api/v1/mcp-call` - 调用 MCP 工具(需要 API Key)
|
||||
|
||||
### MCP 端点
|
||||
|
||||
- `POST /mcp` - MCP HTTP 端点
|
||||
- `GET /mcp/sse` - MCP SSE 端点
|
||||
- `POST /mcp/sse` - MCP SSE POST 端点
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 搜索文档
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/v1/search \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: your-api-key" \
|
||||
-d '{
|
||||
"query": "BigQuery SQL",
|
||||
"service": "bigquery"
|
||||
}'
|
||||
```
|
||||
|
||||
### 获取文档内容
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/v1/doc \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: your-api-key" \
|
||||
-d '{
|
||||
"doc_url": "https://cloud.google.com/bigquery/docs/..."
|
||||
}'
|
||||
```
|
||||
|
||||
### 列出 MCP 工具
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/v1/mcp-tools?service=bigquery \
|
||||
-H "api-key: your-api-key"
|
||||
```
|
||||
|
||||
### 调用 MCP 工具
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/v1/mcp-call \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: your-api-key" \
|
||||
-d '{
|
||||
"service": "bigquery",
|
||||
"tool_name": "query",
|
||||
"arguments": {
|
||||
"query": "SELECT * FROM dataset.table LIMIT 10"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### MCP 调用
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: your-api-key" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/call",
|
||||
"params": {
|
||||
"name": "search_google_cloud_docs",
|
||||
"arguments": {
|
||||
"query": "Compute Engine VM",
|
||||
"service": "compute"
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 必需 | 说明 |
|
||||
|------|------|------|
|
||||
| LITELLM_GATEWAY_URL | 是 | LiteLLM Gateway URL |
|
||||
| OPENAI_API_KEY | 是 | LLM API Key |
|
||||
| BIGQUERY_MCP_URL | 否 | BigQuery MCP 服务器地址,默认 https://bigquery.googleapis.com/mcp |
|
||||
| COMPUTE_MCP_URL | 否 | Compute Engine MCP 服务器地址,默认 https://compute.googleapis.com/mcp |
|
||||
| GKE_MCP_URL | 否 | GKE MCP 服务器地址,默认 https://container.googleapis.com/mcp |
|
||||
| MAPS_MCP_URL | 否 | Maps MCP 服务器地址,默认 https://mapstools.googleapis.com/mcp |
|
||||
| API_PORT | 否 | 服务端口,默认 8000 |
|
||||
|
||||
## 工具说明
|
||||
|
||||
### search_google_cloud_docs
|
||||
|
||||
搜索 Google Cloud 文档。
|
||||
|
||||
**参数:**
|
||||
- `query` (string, 必需): 搜索关键词
|
||||
- `service` (string, 可选): 指定服务(bigquery, compute, gke, maps)
|
||||
|
||||
### get_google_cloud_doc
|
||||
|
||||
获取 Google Cloud 文档内容。
|
||||
|
||||
**参数:**
|
||||
- `doc_url` (string, 必需): Google Cloud 文档 URL
|
||||
|
||||
### list_google_cloud_mcp_tools
|
||||
|
||||
列出 Google Cloud MCP 服务器可用的工具。
|
||||
|
||||
**参数:**
|
||||
- `service` (string, 可选): MCP 服务器名称(bigquery, compute, gke, maps)
|
||||
|
||||
### call_google_cloud_mcp_tool
|
||||
|
||||
调用 Google Cloud MCP 服务器的工具。
|
||||
|
||||
**参数:**
|
||||
- `service` (string, 必需): MCP 服务器名称
|
||||
- `tool_name` (string, 必需): 工具名称
|
||||
- `arguments` (dict, 必需): 工具参数
|
||||
|
||||
## 注册到 Agent Manager
|
||||
|
||||
在 `k8s_manager.py` 中添加:
|
||||
|
||||
```python
|
||||
# TEMPLATE_PORTS
|
||||
"google-cloud-docs": 8000,
|
||||
|
||||
# image_map
|
||||
"google-cloud-docs": "agnettaiji.azurecr.io/ai-agents/google-cloud-docs:latest",
|
||||
```
|
||||
|
||||
在 `app.py` 的 `valid_templates` 中添加 `"google-cloud-docs"`。
|
||||
Reference in New Issue
Block a user