Skip to main content
Glama

Chaos Mesh MCP Server

Chaos Mesh MCP 服务端,基于 Python FastMCP 实现,提供 Chaos Mesh 混沌实验的 MCP 工具集。

项目结构

chaosmesh-mcp/
├── src/
│   └── chaosmesh_mcp/          # 源代码 (src 布局)
│       ├── __init__.py
│       ├── __main__.py          # python -m 入口
│       ├── server.py            # FastMCP 服务启动
│       ├── tools/               # MCP 工具注册
│       │   ├── chaos.py         # list_chaos / delete_chaos
│       │   ├── cluster.py       # 集群巡检 (namespace/pod/node)
│       │   ├── httpchaos.py     # HTTP 接口级延迟注入
│       │   ├── network_chaos.py # 网络延迟/丢包/外部延迟
│       │   └── pod.py           # Pod Kill 注入
│       ├── services/            # 服务适配层
│       │   ├── kubectl.py       # kubectl 命令封装
│       │   └── chaosmesh.py     # 模板渲染与 Chaos CRD 应用
│       ├── utils/               # 工具函数
│       │   ├── generate.py      # 混沌资源名生成
│       │   ├── response.py      # 统一响应格式
│       │   └── validate.py      # 输入校验
│       └── templates/           # Chaos Mesh YAML 模板
│           ├── network_delay.yaml
│           ├── network_loss.yaml
│           ├── network_external_delay.yaml
│           ├── pod_kill.yaml
│           └── httpchaos_delay.yaml
├── tests/
│   └── __init__.py
├── deploy/k8s/                  # Kubernetes 部署清单
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── ingress.yaml
│   ├── kustomization.yaml
│   ├── kustomizeconfig.yaml
│   ├── .env.config
│   └── .env.secret.example
├── pyproject.toml
├── uv.lock
├── .python-version
├── Dockerfile
└── README.md

Related MCP server: Resilience Architect MCP

运行方式

环境准备

# 确保已安装 uv
uv --version

# 同步依赖(自动创建 .venv 并安装所有依赖)
uv sync

本地运行

# 使用 uv run 启动服务
uv run python -m chaosmesh_mcp

# 或通过 console_scripts
uv run chaosmesh-mcp

Docker

docker build -t chaos-mcp:latest .
docker run -p 8000:8000 chaos-mcp:latest

环境变量

  • MCP_HOST — 服务监听地址,默认 0.0.0.0

  • MCP_PORT — 服务监听端口,默认 8000

功能说明

集群巡检工具 (tools/cluster.py)

  • get_namespaces — 查询集群中的 namespace 列表

  • get_pods — 以 wide 格式列出目标命名空间中的 Pod

  • get_nodes — 以 wide 格式列出集群中的所有节点

  • cluster_info — 获取 Kubernetes 集群端点与服务信息

网络混沌工具 (tools/network_chaos.py)

  • resolve_namespace — 根据 K8s 服务名称查询所在的 namespace

  • network_delay — 对服务与服务之间的网络连接注入延迟

  • network_external_delay — 对发往第三方渠道域名注入响应延迟 (Workflow)

  • network_loss — 对服务间注入 NetworkChaos 丢包故障

HTTP 混沌工具 (tools/httpchaos.py)

  • httpchaos_delay — 按 HTTP 路径和端口精准注入延迟

Pod 混沌工具 (tools/pod.py)

  • pod_kill — PodChaos pod-kill 故障注入

混沌生命周期工具 (tools/chaos.py)

  • list_chaos — 列出指定命名空间中的混沌资源

  • delete_chaos — 按类型、名称和命名空间删除单个混沌资源

响应格式

所有工具返回统一的 JSON 响应:

{
  "success": true,
  "message": "操作描述",
  "data": {
    "kubectl": "kubectl 返回内容",
    "yaml": "渲染后的 YAML"
  },
  "yaml": "渲染后的 YAML (顶层)"
}

Kubernetes 部署

kubectl create namespace chaos-mcp
cp deploy/k8s/.env.secret.example deploy/k8s/.env.secret
# 编辑 deploy/k8s/.env.secret 填入真实值
kubectl apply -k deploy/k8s

Available Tools

12 tools
cluster_infoA

获取 Kubernetes 集群端点与服务信息。

Inputs: no named parameters.

delete_chaosC

按类型、名称和命名空间删除单个混沌资源。

Inputs: kind (required), name (required), namespace (required).

get_namespacesB

查询集群中的 namespace 列表。

Inputs: no named parameters.

get_nodesA

以 wide 格式列出集群中的所有节点。

Inputs: no named parameters.

get_podsB

以 wide 格式列出目标命名空间中的 Pod。

Inputs: namespace (required).

httpchaos_delayA

按 HTTP 路径和端口注入延迟(精准影响指定接口);如果只需要服务与服务之间的整体网络延迟,请使用 network_delay。

Inputs: namespace (required), app (required), path (required), port, +3 more.

list_chaosA

列出指定命名空间中的 PodChaos、NetworkChaos 和 StressChaos 资源。

Inputs: namespace (required).

network_delayB

对服务与服务之间的网络连接注入延迟(支持 to);不按 HTTP path 匹配。若需按 path 精准注入,请使用 httpchaos_delay。

Inputs: selector_value (required), target_selector_value (required), selector_namespace (required), target_namespace (required), +4 more.

network_external_delayB

创建 ChaosMesh Workflow,对 发往第三方渠道域名的出方向流量注入响应延迟混沌实验。

Inputs: selector_value (required), selector_namespace (required), external_url (required), duration, +2 more.

network_lossC

对标签选择器匹配到的 Pod 注入 NetworkChaos 丢包故障。

Inputs: selector_value (required), selector_namespace (required), target_selector_value (required), target_namespace (required), +3 more.

pod_killC

对标签选择器匹配到的 Pod 注入 PodChaos pod-kill 故障。

Inputs: namespace (required), selector_value (required), duration.

resolve_namespaceB

根据K8s服务名称,查询该服务所在的命名空间namespace

Inputs: selector_value (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 12 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose. The two delay tools are explicitly disambiguated in their descriptions, and other tools cover different fault types or informational queries without overlap.

    Naming Consistency4/5

    Most tools follow a verb_noun pattern (e.g., delete_chaos, list_chaos, pod_kill), but there are minor inconsistencies like 'httpchaos_delay' (combined prefix) and 'network_external_delay' (three-part name) which mildly deviate from the norm.

    Tool Count5/5

    With 12 tools, the server covers core chaos engineering operations (query, inject, delete) for multiple fault types, without being overwhelming or too sparse.

    Completeness3/5

    The set includes common fault types (pod kill, network delay/loss, HTTP delay) and external delay, but lacks stress chaos injection tools despite listing them, and does not support update operations, leaving notable gaps.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to perform chaos engineering and resilience testing on Kubernetes clusters through Chaos Mesh. Supports creating and managing 24 types of chaos experiments including network failures, stress tests, pod disruptions, and I/O faults through natural language conversations.
      2
      MIT