网络实验室管理工具

一个通过自然语言控制Containerlab网络的MCP服务器,支持创建、部署、检查和销毁网络实验室。

  • by giancarlo3g
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 giancarlo3g/clab-mcp

使用说明

clab mcp

一个MCP(模型上下文协议)服务器,它公开 集装箱实验室 作为一组AI可调用工具。它允许Claude和其他兼容MCP的AI代理通过自然语言创建、部署、检查和销毁网络实验室。

目前已针对诺基亚SR-SIM和SR Linux图像进行了优化。 在未来的版本中,将添加对其他节点类型的支持。

特性

  • 创建拓扑 --生成 .clab.yml 文件从头开始,由Containerlab和诺基亚SR-SIM的内置参考文档指导
  • 部署实验室 --从拓扑文件启动实验室(可选重新配置)
  • 摧毁实验室 --拆除一个正在运行的实验室
  • 检查实验室 --查询运行节点状态、管理IP和容器详细信息
  • 列出图片 --发现本地可用的Docker镜像以在拓扑中使用

先决条件

安装

git clone https://github.com/your-org/clab-mcp
cd clab-mcp
uv sync

运行服务器

uv run clab-mcp

或者直接:

uv run python -m clab_mcp.server

服务器使用stdio传输,并设计为由MCP主机(例如Claude Code、Claude Desktop)启动。

MCP客户端配置

将以下内容添加到您的 .mcp.json (或等效的MCP主机配置):

{
  "mcpServers": {
    "clab-mcp": {
      "command": "uv",
      "args": ["run", "--project", "~/clab-mcp", "clab-mcp"]
    }
  }
}

可用工具

工具 说明
clab_create_topology 生成一个 .clab.yml 拓扑文件
clab_deploy 部署实验室(containerlab deploy)
clab_destroy 拆除实验室(containerlab destroy)
clab_inspect 检查特定的运行实验室
clab_inspect_all 检查主机上所有正在运行的实验室
clab_list_images 列出可用的本地Docker镜像

所有工具都接受可选 topology_file 路径。如果省略,服务器将从当前目录向上移动以查找第一个目录 *.clab.yml 文件。

资源

服务器公开了两个参考文档,AI在构建拓扑结构时会自动参考它们:

  • clab://topology-reference --完整的Containerlab拓扑规范(节点属性、链接类型、种类标识符)
  • clab://srsim-reference --诺基亚SR-SIM(nokia_srsim)种类参考:机箱类型、线卡、MDA、接口命名、启动配置模式

提示示例

创建并部署一个双节点SR-SIM实验室

Create a containerlab topology with two nokia_srsim nodes — a spine (IXR-R6d)
and a leaf (IXR-e2c) — connected by two links. Use the locally available
srsim image and save the topology to ~/labs/spine-leaf.clab.yml. Then deploy it.

检查运行中的实验室,总结管理IP

Inspect the running containerlab lab and give me a table of each node's name,
management IPv4 address, and current state.

拆除一个实验室,确认它已经消失了

Destroy the lab defined in ~/labs/spine-leaf.clab.yml, then run inspect-all
to confirm no containers are still running.

构建多节点SR Linux结构

Create a three-node Nokia SR Linux leaf-spine topology: one spine and two leaves.
Each leaf should connect to the spine with a single link. Use kind nokia_srlinux,
auto-detect the correct image from Docker, and write the topology to ./fabric.clab.yml.

项目结构

src/clab_mcp/
  server.py          # FastMCP server entry point; registers tools and resources
  config.py          # topology file discovery and YAML parsing helpers
  tools/
    create_topology.py  # clab_create_topology
    deploy.py           # clab_deploy
    destroy.py          # clab_destroy
    inspect.py          # clab_inspect, clab_inspect_all
    images.py           # clab_list_images
docs/
  containerlab-topology-reference.md  # embedded topology reference (resource)
  nokia-srsim-reference.md            # embedded SR-SIM reference (resource)
topo.clab.yml        # example two-node SR-SIM lab (IXR-R6d + IXR-e2c)

支持的节点类型

种类 状态
nokia_srsim 支持-包括完整的参考指南
nokia_srlinux 支持
其他 即将推出

许可证

麻省理工学院