Skip to main content
Glama
ChipCloud MCP Server

ChipCloud MCP Server

by bystone84
README.md
# ChipCloud MCP Server (`chipcloud-mcp`)

面向 **芯片云(ChipCloud / zscheduler)** HPC 集群、作业、队列与节点管理 API 的生产级 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) Server。

基于官方 Python MCP SDK v2 (`MCPServer`)、`httpx` 异步连接池、`Pydantic v2` 强类型校验与 `cryptography` AES-CBC 加密实现,同时支持 **stdio**(本地离线直调)与 **Streamable HTTP**(内网中心化 / Docker / Kubernetes 部署),专门适配 **Claude Code、OpenCode、DeepSeek Harness (`dsh`)** 等离线 Vibe Coding Agent 与内网模型 API 环境。

> **完整文档与模板**:
> - [管理员手册(含纯离线部署、安全加固、配置参考与故障排查)](docs/ADMIN_GUIDE.md)
> - [用户手册(含 Claude Code / OpenCode / dsh 离线接入配置与状态字典)](docs/USER_GUIDE.md)
> - 客户端现成模板:[`examples/clients/`](examples/clients/)(Claude Code / OpenCode v1 & v2 / `dsh`)
> - 离线打包与安装脚本:[`scripts/build_offline_wheelhouse.sh`](scripts/build_offline_wheelhouse.sh)、[`scripts/install_offline.sh`](scripts/install_offline.sh)、[`Dockerfile.offline`](Dockerfile.offline)

---

## 核心特性

- **100% 覆盖芯片云 API 文档全部 10 个接口**(用户登录、集群列表、活动作业列表/详情、历史作业列表/详情、队列名称/资源/配置、节点资源)+ **2 个高价值 AIOps 复合诊断工具**(集群健康全景摘要、排队作业根因分析)。
- **生产级认证与 Token 生命周期管理**:
  - 完整实现文档 6.1.3 规定的 `AES/CBC/PKCS5Padding` + Base64 密码加密(与 Java JCA 逐字节一致),支持 `LOCAL` / `AD` / `LDAP` / `NIS` 登录类型。
  - 单飞锁(Single-Flight `asyncio.Lock`)防止高并发下的登录风暴;结合 JWT `exp` 与 `expireSecond` 提前刷新,并在 HTTP `401` 时自动失效重登并重放请求一次。
  - 同时支持预加密密码(`CHIPCLOUD_PASSWORD_ENCRYPTED`)或外部注入静态 Token(`CHIPCLOUD_TOKEN`)。
- **弹性网络与多端口/网关兼容**:
  - 默认支持芯片云三端口架构(`:18083` 管理/作业、`:18090` 监控服务、`:18082` 配置服务),也支持通过独立 Base URL 环境变量无缝对接 Nginx / API Gateway / K8s Ingress。
  - 连接池复用、可配置分阶段超时、指数退避 + 抖动重试(针对网络抖动与 `429/502/503/504`)、自定义企业私有 CA 证书。
- **生产安全与可观测性**:
  - 所有日志强制输出至 `stderr`(保障 `stdio` JSON-RPC 帧不被污染),支持 JSON 结构化日志,自动脱敏密码与 Bearer Token。
  - Streamable HTTP 模式内置 `/healthz`(存活探针)、`/readyz`(就绪探针,验证上游认证连通性)、无状态水平扩展模式(`MCP_STATELESS_HTTP=true`)、常时间比对的入站 Bearer Token 鉴权(`MCP_SERVER_AUTH_TOKEN`)、DNS Rebinding 防护与 CORS。
  - 所有工具均声明 MCP `ToolAnnotations(read_only_hint=True, destructive_hint=False, idempotent_hint=True)`,安全可控。

---

## 工具、资源与提示词清单

### MCP Tools(12 个)

| 工具名 | 对应芯片云 API | 端口 | 说明 |
| --- | --- | --- | --- |
| `check_auth_status` | `GET /v1/admin/inner/login` | `18083` | 检查认证连通性、License 状态(`hasLicense`/`remainNum`)与 Token 剩余有效期 |
| `list_clusters` | `GET /manageCluster` | `18083` | 查询纳管集群列表与 `clusterId` |
| `list_active_jobs` | `GET /cluster/getJob` | `18083` | 分页查询活动作业(支持状态、队列、用户、节点、内存/时长筛选与排序) |
| `get_active_job_detail` | `GET /cluster/getJobDetail` | `18083` | 查询活动作业详情(含 `pendReason`、`suspReason`、PIDs、资源需求与峰值) |
| `list_history_jobs` | `POST /jobInfo/jobHistoryPageNew` | `18083` | 分页查询历史作业(时间范围自动兼容毫秒时间戳与 `YYYY-MM-DD HH:MM:SS` / ISO-8601) |
| `get_history_job_detail` | `GET /jobInfo/getJobHistoryDetailNew` | `18083` | 查询历史作业完整详情(退出码/退出原因/均值与峰值) |
| `list_queue_names` | `GET /monitor-service/queue/listQueueNames` | `18090` | 查询集群队列名称列表 |
| `list_queue_resources` | `POST /monitor-service/queue/listQueueResource` | `18090` | 查询队列实时资源利用率、作业槽占用与平均排队时长 |
| `list_queue_configs` | `GET /configure/queue/queueList` | `18082` | 查询队列调度策略、优先级、状态与 `QJOB/UJOB/HJOB/PJOB_LIMIT` 配额 |
| `list_node_resources` | `POST /monitor-service/node/listNodeResource` | `18090` | 查询节点资源负载、核心进程存活状态(`processList`)与节点健康状态 |
| `get_cluster_health_summary` | 复合聚合(支持部分降级) | 多服务 | 并发输出集群健康评级、异常/进程故障/高负载节点与队列排队排行 |
| `diagnose_pending_jobs` | 复合聚合(并发限流) | 多服务 | 自动抓取 `PEND` 作业详情,聚合 `pendReason` 分布并关联队列限额配置 |

### MCP Resources & Prompts

- **Resources**:
  - `chipcloud://reference/enums` — 完整状态枚举字典(登录类型、集群类型、作业/队列/节点状态及中文释义)
  - `chipcloud://clusters` — 当前纳管集群列表只读资源
- **Prompts**:
  - `cluster_inspection_report` — 标准化集群日常巡检报告模板
  - `troubleshoot_job` — 作业排队/挂起/异常退出系统化排查模板

---

## 快速开始

### 1. 本地安装(推荐 `uv`)

```bash
cd chipcloud-mcp
uv sync
cp .env.example .env
# 编辑 .env 填写 CHIPCLOUD_HOST、CHIPCLOUD_ACCOUNT、CHIPCLOUD_PASSWORD 等配置
```

### 2. stdio 模式运行(适用于 Cursor / Claude Desktop / 本地 Agent)

```bash
uv run chipcloud-mcp --transport stdio
```

#### Cursor / Claude Desktop 配置示例

```json
{
  "mcpServers": {
    "chipcloud": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/chipcloud-mcp",
        "run",
        "chipcloud-mcp",
        "--transport",
        "stdio"
      ],
      "env": {
        "CHIPCLOUD_HOST": "10.0.66.88",
        "CHIPCLOUD_ACCOUNT": "admin",
        "CHIPCLOUD_PASSWORD": "your_password",
        "CHIPCLOUD_LOGIN_TYPE": "LOCAL",
        "CHIPCLOUD_LOG_FORMAT": "text"
      }
    }
  }
}
```

### 3. Streamable HTTP 模式运行(适用于远端服务 / Docker / Kubernetes)

```bash
MCP_SERVER_AUTH_TOKEN="your-strong-mcp-token" \
uv run chipcloud-mcp --transport streamable-http --host 0.0.0.0 --port 8000 --stateless
```

服务端点:
- MCP Streamable HTTP: `POST/GET/DELETE http://<host>:8000/mcp`
- 存活探针(Liveness): `GET http://<host>:8000/healthz`
- 就绪探针(Readiness): `GET http://<host>:8000/readyz`

#### 远端 MCP 客户端配置示例

```json
{
  "mcpServers": {
    "chipcloud-prod": {
      "url": "https://chipcloud-mcp.internal.example.com/mcp",
      "headers": {
        "Authorization": "Bearer your-strong-mcp-token"
      }
    }
  }
}
```

### 4. Docker / Docker Compose 部署

```bash
cp .env.example .env
# 强烈建议在 .env 中设置 MCP_SERVER_AUTH_TOKEN
docker compose up -d --build
curl http://127.0.0.1:8000/healthz
```

---

## 环境变量说明

完整配置见 [`.env.example`](.env.example)。关键项如下:

| 环境变量 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `CHIPCLOUD_HOST` | 是* | — | 芯片云 IP/域名(若未设置独立 Service Base URL) |
| `CHIPCLOUD_ADMIN_BASE_URL` | 否 | `http://<host>:18083` | 覆盖管理/登录/作业服务 Base URL(反向代理场景) |
| `CHIPCLOUD_MONITOR_BASE_URL` | 否 | `http://<host>:18090` | 覆盖监控服务 Base URL |
| `CHIPCLOUD_CONFIGURE_BASE_URL` | 否 | `http://<host>:18082` | 覆盖队列配置服务 Base URL |
| `CHIPCLOUD_ACCOUNT` | 是* | — | 登录账号(与密码配合实现自动登录刷新) |
| `CHIPCLOUD_PASSWORD` | 是* | — | 明文密码(运行时自动 AES-CBC 加密,不落盘、不打日志) |
| `CHIPCLOUD_PASSWORD_ENCRYPTED` | 否 | — | 已 AES-CBC+Base64 加密的密码(与明文密码二选一) |
| `CHIPCLOUD_LOGIN_TYPE` | 否 | `LOCAL` | `LOCAL` / `AD` / `LDAP` / `NIS` |
| `CHIPCLOUD_TOKEN` | 否 | — | 静态 Bearer Token(替代账号密码登录,无自动刷新) |
| `CHIPCLOUD_DEFAULT_CLUSTER_ID` | 否 | — | 可选默认 `clusterId`,调用工具省略时自动填充 |
| `MCP_TRANSPORT` | 否 | `stdio` | `stdio` 或 `streamable-http` |
| `MCP_SERVER_AUTH_TOKEN` | 生产推荐 | — | 保护 Streamable HTTP `/mcp` 的入站 Bearer Token |
| `MCP_STATELESS_HTTP` | 否 | `true` | 无状态模式,支持 K8s 多副本负载均衡 |
| `CHIPCLOUD_VERIFY_SSL` / `CHIPCLOUD_CA_BUNDLE` | 否 | `true` / — | TLS 校验与私有 CA 证书路径 |

---

## 开发与质量验证

```bash
# 运行全部单元与集成测试
uv run pytest

# 代码静态检查
uv run ruff check src tests

# 严格类型检查
uv run mypy src tests
```

---

## 开源协议与声明

本项目采用 [Apache License 2.0](LICENSE) 开源,详见 [LICENSE](LICENSE) 与 [NOTICE](NOTICE)。

> 本协议仅适用于 `chipcloud-mcp` 集成服务本身,不包含也不授予紫芯调度器(ZScheduler)及芯片云平台本体的商业使用许可;相关产品名称与商标归各自权利人所有。

TDQS

A3.8/5.0

Scored across 12 tools

Disambiguation4/5

Most tools have clearly distinct resource/action targets: clusters, queue names, queue resources, queue configs, active jobs, history jobs, node resources, auth, and two aggregate diagnosis tools. The main overlap is between granular tools and the composite tools get_cluster_health_summary and diagnose_pending_jobs, which intentionally re-aggregate data from list_node_resources, list_queue_resources, list_queue_configs, and job detail tools. Descriptions make the intended distinction clear, but an agent may still hesitate between calling a summary tool versus the underlying detailed tools.

Naming Consistency5/5

All 12 names use consistent snake_case with predictable verb_noun phrasing: list_*, get_*, check_*, and diagnose_*. Resource nouns are consistently ordered and descriptive, such as list_active_jobs/get_active_job_detail and list_history_jobs/get_history_job_detail. No mixed casing or wildly inconsistent verb styles are present.

Tool Count5/5

Twelve tools is well within the ideal range for a monitoring-oriented cluster management server. Each tool maps to a meaningful operation, and the two aggregate tools add convenience without bloating the surface excessively. The set is scoped enough to stay navigable while covering several resource types.

Completeness4/5

For a cluster monitoring/inspection server, coverage is strong: clusters, queues, queue resources/configs, active jobs, history jobs, nodes, auth/license status, health summary, and pending-job diagnosis are all present. Minor gaps remain, such as retrieving job logs/output, node-level detail, or project/user-level quota views, and there are no job lifecycle actions like submit/cancel/hold. These gaps are workable for a monitoring-focused surface but prevent full lifecycle completeness.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues