使用说明
Netmiko MCP服务器
MCP(模型上下文协议)服务器,用于通过SSH管理网络设备,使用 Netmiko。具有连接池、多供应商支持和并发操作。
特性
- 命令执行:在单个或多个设备上运行CLI命令
- 配置管理:通过可选的保存/回滚功能推送配置更改
- 设备清单:基于YAML的设备清单,包括组和标签
- 连接池:通过健康检查实现高效的连接重用
- 多供应商支持:适用于Netmiko支持的任何设备类型
- 并发操作:在多个设备上并行执行命令
- 文本FSM解析:可选的结构化输出解析
安装
来源
git clone https://github.com/ntunes/netmiko-mcp-server.git
cd netmiko-mcp-server
pip install -e .
使用Docker
docker build -t netmiko-mcp .
配置
设备清单
创建 config/devices.yaml 文件中包含您的设备清单:
defaults:
timeout: 30
fast_cli: true
credentials:
production:
username: "${NETMIKO_USERNAME}"
password: "${NETMIKO_PASSWORD}"
secret: "${NETMIKO_SECRET}"
groups:
core_routers:
- core-rtr-01
- core-rtr-02
devices:
core-rtr-01:
host: "192.168.1.1"
device_type: "cisco_ios"
credential_profile: "production"
tags:
- core
- production
core-rtr-02:
host: "192.168.1.2"
device_type: "cisco_ios"
credential_profile: "production"
tags:
- core
- production
pool_settings:
max_connections_per_device: 3
connection_timeout: 300
health_check_interval: 60
环境变量
通过环境变量设置凭据:
export NETMIKO_USERNAME="admin"
export NETMIKO_PASSWORD="your_password"
export NETMIKO_SECRET="enable_secret"
可选择设置配置文件位置:
export NETMIKO_MCP_CONFIG="/path/to/devices.yaml"
用法
运行服务器
标准传输(适用于克劳德桌面):
python -m netmiko_mcp
可流式HTTP传输:
python -m netmiko_mcp --transport streamable-http --port 8339
使用Docker:
docker run -p 8339:8339 \
-e NETMIKO_USERNAME=admin \
-e NETMIKO_PASSWORD=secret \
-v ./config/devices.yaml:/app/config/devices.yaml:ro \
netmiko-mcp
使用Docker Compose:
# Set credentials in .env or environment
export NETMIKO_USERNAME=admin
export NETMIKO_PASSWORD=secret
docker-compose up -d
Claude桌面配置
添加到您的Claude Desktop配置中:
对于stdio传输:
{
"mcpServers": {
"netmiko": {
"command": "python",
"args": ["-m", "netmiko_mcp", "--config", "/path/to/devices.yaml"]
}
}
}
对于HTTP传输:
{
"mcpServers": {
"netmiko": {
"url": "http://localhost:8339/mcp"
}
}
}
MCP工具
命令执行
| 工具 | 说明 |
|---|---|
send_command |
在一个设备上执行单个命令 |
send_command_parallel |
在多个设备上同时执行相同的命令 |
send_commands_sequence |
在一台设备上顺序执行多个命令 |
配置
| 工具 | 说明 |
|---|---|
send_config |
将配置命令推送到一个设备 |
send_config_parallel |
同时将配置推送到多个设备 |
库存和发现
| 工具 | 说明 |
|---|---|
list_devices |
列出所有具有可选标签/类型过滤的设备 |
get_device_info |
获取详细的设备信息和连接状态 |
list_groups |
列出所有设备组及其成员 |
test_connection |
测试与设备的连接 |
get_pool_status |
获取连接池统计信息 |
get_device_types |
列出库存中的所有设备类型 |
get_tags |
列出跨设备使用的所有标签 |
例子
执行命令:
Use send_command on device "core-rtr-01" with command "show version"
在多个设备上执行:
Use send_command_parallel on devices ["@core_routers"] with command "show ip interface brief"
推送配置:
Use send_config on device "core-rtr-01" with config_commands ["interface Loopback0", "description Test"] and save_config true
支持的设备类型
Netmiko支持的任何设备类型,包括:
cisco_ios-思科IOScisco_xe-思科IOS-XEcisco_xr-思科IOS-XRcisco_nxos-思科NX-OSarista_eos-Arista EOSjuniper_junos-Juniper JunOSpaloalto_panos帕洛阿尔托 PAN-OShp_procurve-HP ProCurvelinux-Linux SSH
看 Netmiko支持的平台 查看完整列表。
发展
安装开发依赖项
pip install -e ".[dev]"
运行测试
pytest
跑林婷
ruff check src/ tests/
mypy src/
许可证
麻省理工学院
