ensp-mcp
Provides tools for creating and managing Huawei eNSP network topologies, configuring devices through their console ports, and validating, rendering, or exporting the topology for network lab simulations.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ensp-mcp Create a topology with two routers and configure OSPF between them"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
eNSP MCP
给华为 eNSP 用的一站式 MCP:搭拓扑和配设备在同一个工具集里完成。
An unofficial MCP server for building Huawei eNSP topologies and configuring lab devices through their console ports.
当前版本 1.2.0,共 16 个 MCP 工具。本版增加 eNSP/VirtualBox/镜像 启动前诊断、原生分区背景框和文字避让,并把防火墙默认选择改为 USG5500。 详见 更新记录 与 开发及验收说明。
拓扑侧全是离线的文件操作,不用开 eNSP;设备侧走 eNSP 的 console 端口, 要求 eNSP 已启动、目标设备已开机。
能干什么
按型号加设备、按接口名连线,接口序号和
.topo的 XML 细节都不用管自动分层布局,自动分配 console 端口,自动生成 MAC 和 AP 序列号
用 eNSP 原生背景矩形和文字创建分区,自动给标题、设备名和分区留出间距
交给 eNSP 之前检查拓扑结构,以及 VirtualBox、Hyper-V/VBS、模板机和镜像
可选渲染 PNG 辅助预览;拓扑创建和验收不依赖预览图
导出 Mermaid / draw.io / CSV,直接拿去写文档
telnet 进设备批量下发配置、读回实配做对比、跑 ping 和各种 display
Related MCP server: eNSP Automation MCP
安装
基本环境:Python 3.10 或更高版本。实际运行 eNSP 和连接设备需要 Windows 与 已安装的 eNSP;使用 AR、WLAN、NE/CE 或 USG6000V 时,还需要与 eNSP 版本 匹配的 VirtualBox、模板机或设备镜像。仓库不提供这些厂商软件。
git clone https://github.com/Heaxu/ensp-mcp.git
cd ensp-mcp
python -m pip install -e .也可以从 GitHub Releases 下载 wheel 后安装:
python -m pip install .\ensp_mcp-1.2.0-py3-none-any.whl在 MCP 客户端配置文件中注册:
{
"mcpServers": {
"ensp-mcp": {
"command": "ensp-mcp"
}
}
}也可以用 Python 解释器启动,便于切换虚拟环境:python -m ensp_mcp.server。
开发更新后要在客户端重启 MCP 服务,已运行的进程不会自动加载新源码。
环境自检:python -m ensp_mcp.doctor。给定拓扑并把运行前置条件作为退出状态:
python -m ensp_mcp.doctor --topo lab.topo --strict-runtime。运行测试:
python -B -m unittest discover -s tests -t . -v。
典型流程
environment_check 先检查 eNSP、VirtualBox、模板机和镜像
list_models 看型号、接口和选择建议;普通防火墙默认 USG5500
topo_create 建一个空拓扑
topo_add_devices 批量加设备
topo_connect 批量连线
topo_layout 自动摆开;需要时生成分区背景和标题
topo_validate 检查
topo_render (可选)出辅助预览图
↓ 在 eNSP 里打开,全选启动设备
device_push_config 灌配置
device_probe ping 一下验证工具
设备库
工具 | 干什么 |
| 列出 43 种型号、接口、默认选择和启动风险。给 |
没有明确型号要求时,categoryDefaults 中的防火墙默认值是 USG5500。
显式传入 USG6000V 仍会严格按该型号创建,同时返回外部镜像和启动风险提示,
不会静默换成端口结构不同的型号。
拓扑
工具 | 干什么 |
| 新建空 |
| 读出设备、链路、每台设备的空闲接口和 console 端口 |
| 批量加设备,支持 |
| 批量连线,接口可写名字也可省略让它自动挑空闲口 |
| 删设备或断连线 |
|
|
| 重名、接口越界、一口多连、console 冲突、孤立设备、图标/文字/分区碰撞和条件型号风险 |
| 可选的 Pillow PNG 辅助示意图 |
| 导出 Mermaid / draw.io / CSV |
分区示例:
{
"path": "D:/lab/campus.topo",
"zones": [
{"title": "总部核心区", "devices": ["Core1", "Core2", "FW1"], "color": "#E8F1FF"},
{"title": "办公区", "devices": ["Access1", "PC1", "PC2"], "color": "#EAF8EE"}
]
}分区布局使用 eNSP 原生 shape/txttip 字段,按设备名宽度计算单元格,并给
背景框、标题栏和相邻分区预留固定间距。未列出的设备默认进入“未分区”。
eNSP 的标注没有稳定 ID,因此拓扑已有手工图形或文字时默认拒绝覆盖;确实要
全部重建时显式传 replace_annotations=true。普通布局遇到已有标注也默认拒绝
移动设备,避免背景框留在旧坐标。
启动环境
工具 | 干什么 |
| 只读检查 eNSP、VirtualBox 版本和硬件虚拟化、Hyper-V/VBS 冲突、Host-Only 网卡、AR/WLAN 基机、SVRP 与 USG6000V 镜像 |
传入 path 后查看 readyForTopology 和每个 modelChecks[].blockers;还没建图时
也可传 models=["AR2220", "USG5500"] 预检计划型号。CLI 对应参数可重复写,
例如 python -m ensp_mcp.doctor --model AR2220 --model USG5500 --strict-runtime。
该检查不会启动虚拟机,不会关闭 Windows 功能,也不会注册或修改镜像。
eNSP 1.3.00.200T 优先使用经验证的 VirtualBox 5.2.x。VirtualBox 驱动处于
Running 并不能证明设备可启动:如果 Hyper-V/VBS 占用 AMD-V/VT-x,老版本
VirtualBox 仍会报 raw-mode 错误。诊断会把这种情况单独报为
VBOX_HYPERV_CONFLICT。
USG6000V 是条件使用型号,通常要另行安装并注册 vfw_usg.vdi;只有实验明确
要求该型号或其独有能力时再选。一般防火墙实验优先 USG5500,它使用 eNSP
自带的本地模拟器和固件。NE40E、CE6800、CE12800 还依赖已注册的
SVRP 镜像。
设备配置
target 既接受设备名(如 Core1,需要配 topo_path),也接受 console
端口号(如 2002)。
工具 | 干什么 |
| 执行任意命令并返回回显 |
| 灌整份配置,可以来自文本或 |
| 读回运行配置,可存盘,可和基线逐行对比 |
| ping / tracert / 接口状态 / ARP / MAC / 路由 / VLAN / OSPF |
| 查看和关闭保持中的 console 连接 |
四个操作设备的工具都支持 username、password、new_password。
无需认证时省略;仅密码的 console 可只给 password;new_password 仅在
设备要求首次设置或修改密码时使用,不会主动触发改密。
执行结果。 检查返回的 ok、逐条 results 和 saveStatus。
device_exec / device_push_config 默认 stop_on_error=true,遇错停止;
出错后不自动保存,也不自动回滚已生效的配置。超时或断线会关闭连接并报告
明确错误,不会自动重放命令。saveStatus.status=saved 才表示识别到保存成功。
整份配置。 device_push_config 支持以 # 分段的运行配置,每个分段
回到系统视图后再执行。device_fetch_config 的差异包含 unifiedDiff,
保留上下文、行顺序及重复项。
探测结果。 ping 结果中的 parsed.reachable 才表示是否连通;null
表示回显不足,不能判断。其他 display 查询目前返回原始回显。
几个说明
接口命名。 交换机从 1 开始(GigabitEthernet0/0/1),路由器和 AP 从 0
开始(GigabitEthernet0/0/0)。写 GE0/0/1、Gi0/0/1、
GigabitEthernet0/0/1 都认,也可以直接写扁平序号。
console 端口。 eNSP 把有 console 的设备映射到本机 2000 起的 TCP 端口。 PC、Server、STA、Cloud、HUB 这些没有 console,只能在 eNSP 界面里双击配置。
Cloud。 它的接口是在 eNSP 界面里手工添加并绑定真实网卡的,.topo 里
接口数写作 0。连线时按序号给(0、1、2……),校验会提醒你去界面里补配置。
设备开关机。 eNSP 启动部分设备时会动态克隆 VirtualBox 模板机,实例名 不固定。MCP 先做只读预检,最终启动仍在 eNSP 界面完成;预检通过也不等同于 镜像已经完成真实启动验收。
文件格式。 eNSP 写出的 .topo 声明 encoding="UNICODE" 但实际是
UTF-8、CRLF 换行。本工具按同样的形态写回,读的时候两种编码都认。
编辑已有拓扑时保留标注、扩展属性和实际板卡 XML,使用原子写入;若文件在 读取后被其他程序修改,会拒绝覆盖并要求重新读取。避免同时在 eNSP 和 MCP 中保存同一文件。读取兼容 UTF-8、UTF-16 以及官方中文样例使用的 CP936/ GB18030。接口与线型校验不替代真实设备的启动和连通性验收。
topo_render 是 Pillow 生成的示意图,并非从 eNSP 导出的截图;它不验证真实
界面、镜像或启动状态。Mermaid/draw.io/CSV 导出主要表达设备和链路,不保证
原生分区标注的视觉等价。
小规模端到端验收
python examples/e2e_lab.py create --directory ./work/e2e-lab
# 在 eNSP 中打开生成的 acceptance.topo 并启动两台交换机
python examples/e2e_lab.py run --directory ./work/e2e-lab --apply
# 手动重启两台设备后,只读复验保存和连通性
python examples/e2e_lab.py run --directory ./work/e2e-lab脚本会保留实际 MCP 结果和读回配置。自动测试的 Telnet 服务是协议测试桩, 不能替代真实 eNSP 设备测试,也不表示 43 种型号均已完成联调。
开源许可与声明
本项目代码采用 MIT License。项目是社区维护的非官方工具,与华为 及 eNSP 官方没有隶属或授权关系。Huawei、eNSP 及相关产品名称归各自权利人 所有。
仓库不包含 eNSP、VirtualBox、USG6000V/SVRP 镜像或其他厂商软件。请从合法 来源自行取得所需软件和镜像,并遵守相应许可。问题和改进建议可提交到 GitHub Issues。
Available Tools
16 toolsdevice_execA
在已启动的 eNSP 设备 console 上逐条执行命令。
target 为设备名(配 topo_path)或端口号。view 为 keep/user/system。 username/password 用于需要登录的 console,只有密码的 console 可只给 password。 new_password 仅在设备要求初次设置或修改密码时使用;不主动修改已有密码。 stop_on_error 默认遇错停止;失败时不 save。confirm 为 Y/N/YES/NO。 返回 ok、逐条 results、errorCount、stoppedEarly 和 saveStatus;超时断线不会重试命令。
Inputs: target (required), commands (required), host, save, +7 more. Returns: result
device_fetch_configA
读回运行配置;save_to 可保存 UTF-8 文件,compare_with 可与基线文件比较。
diff 同时提供 identical、onlyOnDevice、onlyInFile 和带上下文的 unifiedDiff, 保留行顺序及重复行。命令失败或超时不写出配置文件。登录参数与 device_exec 相同。
Inputs: target (required), host, save_to, password, +4 more. Returns: result
device_probeA
设备连通性和状态查询。action: ping/tracert/interfaces/arp/mac/route/vlan/ospf。
ping/tracert 需要 destination;ping count 为 1–100。ping 返回统计和 reachable, 无法解析时 reachable 为 null;其他查询返回 output 原文。ok 表示命令执行状态, ping 是否连通看 parsed.reachable。登录参数与 device_exec 相同。
Inputs: target (required), host, count, action, +5 more. Returns: result
device_push_configA
从文本或 UTF-8 .cfg 下发配置,config/config_file 必须且只能选一个。
自动进入系统视图,支持带 # 分段的 display current-configuration 配置文本, 分段时退出子视图再进入系统视图。默认遇错停止且不保存;不会自动回滚已生效配置。 username/password/new_password 与 device_exec 相同。save 默认 true。 CE 提示符标记存在未提交改动时,保存前先 commit;任何保存异常都返回失败状态。
Inputs: target (required), host, save, config, +6 more. Returns: result
device_sessionsA
查看或关闭 console 会话。action 为 list/close/close_all。
close 时 target 为端口号。后台每 30 秒回收空闲超过 5 分钟的连接; 服务退出时关闭所有连接。关闭操作等待该连接正在执行的命令结束。
Inputs: host, action, target. Returns: result
environment_checkA
只读检查 eNSP、VirtualBox、模板机和设备镜像,不启动或修改任何虚拟机。
检查结果的 readyForTopology=true 才表示这份拓扑的已知前置条件 已满足。检查会识别 VirtualBox 版本、Hyper-V/VBS 冲突、Host-Only 网卡、 AR/WLAN 基机、SVRP 镜像和 USG6000V 镜像/注册状态。
Args: path: 可选的 .topo。给出后按其中实际型号判断 readyForTopology。 models: 可选的计划型号列表;还没创建拓扑时可先检查,例如 ["AR2220", "USG5500"]。与 path 同时给出时合并检查。 ensp_home: 可选的 eNSP 安装目录;省略时从环境、注册表和常见目录查找。
Inputs: path, models, ensp_home. Returns: result
list_modelsA
列出 eNSP 支持的设备型号,以及每种型号的接口清单。
搭拓扑前先调这个,就知道有哪些型号可选、每个型号有几个口、口叫什么名字。 连线时 fromPort / toPort 填的就是这里的接口名。
Args: category: 只看某一类,可选 AR(路由器)、LSW(交换机)、WLAN(无线)、 FW(防火墙)、CLIENT(终端)、OTHER(其它)。留空看全部。 model: 只看某一个型号,例如 "S5700"。填了会连完整接口列表一起返回。 topo_path: 可选。给一份现成 .topo,会顺带核对内置型号表和这份文件 里实际写出的接口布局是否一致,用于确认 eNSP 版本差异。
Inputs: model, category, topo_path. Returns: result
topo_add_devicesA
往拓扑里批量加设备。
Args: path: .topo 文件路径。 devices: 设备列表,每项支持这些字段:
- model(必填):型号,见 list_models。
- name:设备名,省略则按 eNSP 习惯自动编号(S5700 叫 LSW1、
AR2220 叫 AR1,重名自动往后排)。
- count:一次加几台,默认 1;配合省略 name 可以批量生成。
- x / y:画布坐标,省略则先堆在原点,之后跑 topo_layout 自动摆开。
- settings:终端类设备的初始参数,PC/Server 可填
{"ip": "...", "mask": "...", "gateway": "..."},
AP 可填 {"mac": "...", "sn": "..."}。具体字段见
list_models 返回的 settingsFields。
举例:[{"model": "S5700", "name": "Core", "count": 2},
{"model": "PC", "settings": {"ip": "192.168.1.10"}}]console 端口会自动从 2000 起顺序分配,不会和已有设备冲突。
Inputs: path (required), devices (required). Returns: result
topo_connectA
批量连线。
Args: path: .topo 文件路径。 links: 链路列表,每项支持:
- from / to(必填):两端设备名。
- fromPort / toPort:接口名("GE0/0/1"、"GigabitEthernet0/0/1"
都认)或接口序号。省略则自动挑该设备第一个空闲口。
- lineType:线型,默认按接口类型自动判断(串口给 Serial,
其余给 Copper)。也可显式写 Copper / Fiber / Serial。
举例:[{"from": "Core1", "to": "Core2", "fromPort": "GE0/0/1",
"toPort": "GE0/0/1"},
{"from": "Core1", "to": "PC1"}]一个接口只能连一条线,重复占用会直接报错并指出是哪个口。
Inputs: path (required), links (required). Returns: result
topo_createB
新建一个空的 .topo 文件。
Args: path: 要写到哪,例如 "D:/work/campus.topo"。 overwrite: 目标已存在时是否覆盖,默认不覆盖。
Inputs: path (required), overwrite. Returns: result
topo_exportA
把拓扑导成写文档用得上的格式。
Args: path: .topo 文件路径。 format: mermaid(流程图源码)、drawio(可导入 draw.io)、 csv(设备表 + 接口连接表)。 out_path: 输出文件路径,省略则只把内容返回、不落盘。 csv 会写成两个文件,分别加 _devices / _links 后缀。
Inputs: path (required), format, out_path. Returns: result
topo_inspectA
读一份 .topo,返回设备清单、链路清单和每台设备的空闲接口。
每台设备会带上 consolePort,那就是 device_* 工具要用的端口号。
Inputs: path (required). Returns: result
topo_layoutA
自动排布设备坐标,不用手工填 x/y。
Args: path: .topo 文件路径。 mode: 布局方式。
- layered(默认):按连线关系自动分层,出口在上、终端在下,
最贴近常见的园区网拓扑图。
- tree:从 root 出发按层级展开。
- grid:网格铺开,适合还没连线的时候。
- ring:环形,适合环网。
groups: 只在 layered 下有效。手工指定每一层放哪些设备,
例如 [["Internet"], ["AR1"], ["Core1","Core2"]]。
没列进去的设备会自动补到最后一层。
root: 只在 tree 下有效,指定树根设备名。省略则挑连线最多的那台。
columns: 只在 grid 下有效,每行几台。省略则自动取平方根。
zones: 可选的分区列表。每项包含 title(或 name)、devices,可选
color(#RRGGBB)和 columns。给了 zones 后会使用分区布局,
mode/groups/root/columns 不再参与排布。
replace_annotations: 拓扑已有背景图形或文字时,是否明确清空并按 zones
重建。默认拒绝覆盖,因为 eNSP 标注没有稳定 ID,无法可靠区分手工项。
include_unassigned: zones 未包含的设备是否自动放入“未分区”背景框,默认是。
zone_columns: 整体画布每行放几个分区;0 表示自动。
allow_annotation_desync: 普通布局遇到已有标注时是否仍移动设备。默认否,
避免背景框和文字留在旧位置;仅在确认标注无需同步时才设为 true。
Inputs: path (required), mode, root, zones, +6 more. Returns: result
topo_removeA
删设备或删连线。
Args: path: .topo 文件路径。 devices: 要删的设备名列表,删设备会连带删掉它身上所有的线。 links: 要断开的链路,每项 {"from": "A", "to": "B"}。
Inputs: path (required), links, devices. Returns: result
topo_renderA
可选:把拓扑画成辅助 PNG,不用开 eNSP 就能粗看布局。
PNG 不是 eNSP 原生界面,也不能证明 VirtualBox、镜像或设备能启动; 正常建图和验收流程不依赖它。
Args: path: .topo 文件路径。 out_path: 图片输出路径,省略则和 .topo 同名同目录,扩展名换成 .png。 scale: 缩放比例,设备多、连线挤的时候调大到 1.5 左右。 show_ports: 是否在连线两端标出接口名,默认标。
Inputs: path (required), scale, out_path, show_ports. Returns: result
topo_validateA
检查拓扑有没有问题,建议在交给 eNSP 打开之前跑一次。
errors 会让 eNSP 打开异常或链路失效,必须改;warnings 只是提醒。 查的内容包括:设备重名、接口序号越界、一个口接了多条线、 console 端口冲突、孤立设备、图标/文字/背景框重叠,以及条件型号风险。
Inputs: path (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Each tool targets a distinct concern: topology file creation/layout/inspection/editing/validation/export versus device command/config/status/session operations. Potential overlaps like device_exec and device_push_config are clearly separated by purpose and usage.
The topo_* and device_* prefixes create a strong overall pattern, and the verbs are consistent. list_models and environment_check break the prefix convention slightly, though their names are still clear and predictable.
16 tools is slightly above the ideal range, but the count is justified by two clear subdomains: topology construction and device interaction. Every tool appears non-redundant and earns its place in the workflow.
The toolset covers the full topology lifecycle from creation to validation/export and pairs it with device command, config, query, and session management. Minor gaps like no explicit start/stop control or post-creation device setting update exist, but these fall outside the MCP's apparent scope.
Maintenance
Related MCP Connectors
AI network lab: build and validate real multi-vendor router and switch labs from a prompt.
Electronics prototyping: real parts and pinouts, wiring checks, and shareable circuit designs.
Discover cloud shapes and create, inspect, validate, patch, and review architecture diagrams.
Create, edit, validate, inspect and export parametric 3D models in your confBuild account.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceMCP server for managing Huawei eNSP network simulation experiments, enabling topology management, Telnet device interaction, configuration deployment, and verification through natural language or API.35-
- AlicenseBqualityDmaintenanceGenerates eNSP network topologies, deploys Huawei VRP configurations, and provides verification plans for lab scenarios.124MIT
- FlicenseBqualityCmaintenanceEnables AI clients to manage Huawei eNSP simulated network devices, execute CLI commands, apply configurations, and perform network diagnostics through natural language, with topology upload and visualization via a web UI.2010-
- AlicenseBqualityCmaintenanceEnables AI assistants to programmatically generate Huawei eNSP .topo files that include USG6000V firewalls and S3700 switches, and then, once devices are started in eNSP, deliver configurations, run verification, and diagnose faults over Telnet. Ships with one-click health self-checks and topology-generation skills for natural-language-driven lab setup.312MIT