mcp牧场主多
支持以下功能的MCP服务器 多牧场经理 后端和公开了一个丰富的工具箱,包括 舰队(GitOps) 助手。适用于MCP主机(Claude Desktop等)的stdio。
特性
- 注册许多Rancher服务器,列出/删除它们。
- Rancher v3 API助手:列出集群、节点、项目,生成kubeconfig。
- Kubernetes代理通过Rancher(
/k8s/clusters/{id})使用原始直通工具。 - Fleet GitOps工具:列表/获取/创建/应用GitRepo、强制重新部署、列表BundleDeployment、状态摘要。
安装
来自NPM
npm install @gorizond/mcp-rancher-multi发展
npm i
npm run build
node dist/index.js码头工人
docker build -t ghcr.io//mcp-rancher-multi:0.1.16 .
docker run --rm -i \
-e RANCHER_SERVER_prod_NAME="Rancher PROD" \
-e RANCHER_SERVER_prod_BASEURL="https://rancher.prod.example.com" \
-e RANCHER_SERVER_prod_TOKEN="your_token_here" \
ghcr.io//mcp-rancher-multi:0.1.16MCP主机配置(克劳德桌面示例)
使用NPM包
{
"mcpServers": {
"rancher-multi": {
"command": "npx",
"args": ["-y", "@gorizond/mcp-rancher-multi"],
"env": {
"RANCHER_SERVER_prod_NAME": "Rancher PROD",
"RANCHER_SERVER_prod_BASEURL": "https://rancher.prod.example.com",
"RANCHER_SERVER_prod_TOKEN": "your_token_here"
}
}
}
}使用全局安装
{
"mcpServers": {
"rancher-multi": {
"command": "mcp-rancher-multi",
"args": [],
"env": {
"RANCHER_SERVER_prod_NAME": "Rancher PROD",
"RANCHER_SERVER_prod_BASEURL": "https://rancher.prod.example.com",
"RANCHER_SERVER_prod_TOKEN": "your_token_here"
}
}
}
}配置
服务器配置是通过环境变量处理的。该项目支持从以下位置加载配置 .env 便于本地开发的文件:
环境文件支持
服务器自动从以下位置加载配置 .env 文件按以下顺序排列(最高优先级优先):
.env.local-地方发展优先权.env-默认配置
复制 env.example 到 .env 并根据您的环境进行自定义:
cp env.example .env
# Edit .env with your actual values备注: .env 文件不应提交到版本控制,因为它们可能包含敏感信息。
配置方法
配置Rancher服务器有两种方法:
方法1:在单个环境变量中进行JSON配置
export RANCHER_SERVERS='{"prod":{"id":"prod","name":"Rancher PROD","baseUrl":"https://rancher.prod.example.com","token":"${ENV:RANCHER_TOKEN_prod}","insecureSkipTlsVerify":false},"lab":{"id":"lab","name":"Rancher LAB","baseUrl":"https://rancher.lab.example.com","token":"${ENV:RANCHER_TOKEN_lab}"}}'方法2:个体环境变量
格式: RANCHER_SERVER__
# Production server
export RANCHER_SERVER_prod_NAME="Rancher PROD"
export RANCHER_SERVER_prod_BASEURL="https://rancher.prod.example.com"
export RANCHER_SERVER_prod_TOKEN="${ENV:RANCHER_TOKEN_prod}"
export RANCHER_SERVER_prod_INSECURESKIPTLSVERIFY="false"
# Lab server
export RANCHER_SERVER_lab_NAME="Rancher LAB"
export RANCHER_SERVER_lab_BASEURL="https://rancher.lab.example.com"
export RANCHER_SERVER_lab_TOKEN="${ENV:RANCHER_TOKEN_lab}"
# Token values
export RANCHER_TOKEN_prod="your_production_token_here"
export RANCHER_TOKEN_lab="your_lab_token_here"看 env.example 举一个完整的例子。
安全说明
- 令牌混淆:所有令牌在日志和输出中都会自动混淆(仅显示最后4个字符
***前缀)
- 例子: secret_token_12345 成为 ***2345
- 做 不 日志令牌。定期轮换,尽量缩小范围。
- 对令牌等敏感数据使用环境变量。
- 考虑使用
.env用于本地开发的文件(未提交版本控制)。 - 对于生产,请使用您平台的秘密管理系统。
工具概述
rancher_servers_list/rancher_servers_add/rancher_servers_removerancher_healthrancher_clusters_list/rancher_cluster_get/rancher_nodes_list/rancher_projects_listrancher_clusters_kubeconfig/rancher_kubeconfigs_merge
- k8s_namespaces_list / k8s_raw - fleet_gitrepos_list|get|create|apply|redeploy / fleet_bdeploys_list / fleet_status_summary
处理大列表/紧凑视图
rancher_clusters_list默认为a 最小 视图(id+name).使用summaryFields从策划的摘要中包含更多内容(状态/提供者/工作区/舰队/kubeVersion等),或summary=false返回完整的集群对象。分页旋钮:limit,autoContinue,maxPages,maxItems,以及continueToken(使用pagination.next).rancher_cluster_get仍然接受summary=true和stripKeys放下沉重的部分,如links/actions.k8s_raw支持limit,autoContinue,maxPages,maxItems,自定义accept,stripManagedFields(默认为真),以及stripKeys(例如。['data','binaryData']删除base64有效载荷)以保持输出紧凑,同时遵循metadata.continue.- 车队列表工具(
fleet_gitrepos_list,fleet_bdeploys_list,fleet_status_summary)接受相同的分页旋钮以及可选选项continueToken恢复列表,现在默认情况下返回精简摘要。使用summary=false或summaryFields以控制输出有效载荷。
测试
该项目包括一个使用Vitest的全面测试套件:
# Run all tests
npm test
# Run tests once
npm run test:run
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch测试结构
- 单元测试 (
tests/unit/):测试单个函数和类 - 集成测试 (
tests/integration/):测试MCP服务器集成 - 夹具 (
tests/fixtures/):测试数据和样本配置
覆盖
当前测试覆盖率:
- 线条: ~75%
- 函数: ~94%
- 分支: ~94%
构建单文件二进制文件
npm run bundle
# outputs dist/mcp-rancher-multi[.exe]