automateyournetwork/pyATS_MCP
简介
核心亮点
- 实现自然语言直接驱动网络设备结构化交互
- 基于 pyATS 框架提供可靠的模型驱动能力
- 简化网络状态采集与自动化分析的工作流
- 无需重复编写脚本即可快速获取设备详情
完整文档
pyATS MCP Server

这是一个封装了 Cisco pyATS 和 Genie 的 MCP server,允许 AI agent(如 Claude, LangGraph 等)通过 JSON-RPC 2.0 经由 STDIO 运行 show 命令、应用配置以及查询网络状态。
> 所有通信均通过 STDIN/STDOUT 完成 —— 无 HTTP 端口,无 REST 接口。
---
Quick Startbash# 1. Clone and install
git clone https://github.com/automateyournetwork/pyATS_MCP
cd pyATS_MCP
pip install -r requirements.txt
2. Configure your environment
cp .env.example .env
Edit .env — see Configuration below
3. Run
python3 pyats_mcp_server.py
---
配置
# 1. Clone and install
git clone https://github.com/automateyournetwork/pyATS_MCP
cd pyATS_MCP
pip install -r requirements.txt
2. Configure your environment
cp .env.example .env
Edit .env — see Configuration below
3. Run
python3 pyats_mcp_server.py所有设备详情和凭据均存储在 .env 文件中 —— 仓库中没有任何硬编码内容。
1. 复制模板bashcp .env.example .env
### 2. 设置服务器变量dotenvPYATS_TESTBED_PATH=/absolute/path/to/your/testbed.yaml
PYATS_MCP_ARTIFACTS_DIR= # default: ~/.pyats-mcp/artifacts
PYATS_MCP_KEEP_ARTIFACTS=1 # 1 = keep, 0 = delete after each run
PYATS_MCP_TESTBED_CACHE_TTL=30 # seconds before testbed reloads from disk
PYATS_MCP_CONN_CACHE_TTL=0 # seconds to keep connections alive (0 = off)
PYATS_MCP_OP_LOG_MAX=500 # max entries in the in-memory operation log
### 3. 为每个设备添加一个区块
cp .env.example .envPYATS_TESTBED_PATH=/absolute/path/to/your/testbed.yaml
PYATS_MCP_ARTIFACTS_DIR= # default: ~/.pyats-mcp/artifacts
PYATS_MCP_KEEP_ARTIFACTS=1 # 1 = keep, 0 = delete after each run
PYATS_MCP_TESTBED_CACHE_TTL=30 # seconds before testbed reloads from disk
PYATS_MCP_CONN_CACHE_TTL=0 # seconds to keep connections alive (0 = off)
PYATS_MCP_OP_LOG_MAX=500 # max entries in the in-memory operation logtestbed.yaml 中的每个设备都使用了 %ENV{VAR} 替换,因此凭据和连接详情将在运行时从 .env 中读取。
请使用 {DEVICENAME}_{FIELD} 命名约定:
# Supported os values: iosxe | iosxr | nxos | ios | eos | junos | panos | linux | windows
Set os=generic and platform="" to let Unicon autodetect on first connect.
CORE1_IP=10.1.1.1
CORE1_PORT=22
CORE1_OS=iosxe
CORE1_PLATFORM=cat9k
CORE1_USERNAME=admin
CORE1_PASSWORD=s3cr3t
CORE1_ENABLE_PASSWORD=s3cr3t
FW1_IP=10.1.1.2
FW1_PORT=22
FW1_OS=panos
FW1_PLATFORM=
FW1_USERNAME=admin
FW1_PASSWORD=s3cr3t
(no enable password for Palo Alto)
LINUX1_IP=10.1.1.3
LINUX1_PORT=22
LINUX1_OS=linux
LINUX1_PLATFORM=ubuntu
LINUX1_USERNAME=admin
LINUX1_PASSWORD=s3cr3t
(no enable password for Linux)
SITE_A_USERNAME=netops
SITE_A_PASSWORD=s3cr3t
SITE_A_ENABLE_PASSWORD=s3cr3tdevices:
CORE1:
alias: "Core Switch 1"
type: "switch"
os: "%ENV{CORE1_OS}"
platform: "%ENV{CORE1_PLATFORM}"
credentials:
default:
username: "%ENV{CORE1_USERNAME}"
password: "%ENV{CORE1_PASSWORD}"
enable:
password: "%ENV{CORE1_ENABLE_PASSWORD}"
connections:
cli:
protocol: ssh
ip: "%ENV{CORE1_IP}"
port: "%ENV{CORE1_PORT}"
arguments:
connection_timeout: 360.env 中设置 DEVICE_OS=generic 并配置 os: "%ENV{DEVICE_OS}",> 且可选地在
arguments: 下添加 learn_os: true —— Unicon 将在首次连接后检测并缓存 OS。
---
Docker
Buildbashdocker build -t pyats-mcp-server .
### 运行(直接传递 .env)bashdocker run -i --rm \
--env-file /absolute/path/to/.env \
-v /absolute/path/to/testbed.yaml:/app/testbed.yaml \
pyats-mcp-server
### MCP 客户端配置 (Docker)json{
"mcpServers": {
"pyats": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--env-file", "/absolute/path/to/.env",
"-v", "/absolute/path/to/testbed.yaml:/app/testbed.yaml",
"pyats-mcp-server"
]
}
}
}
### MCP 客户端配置 (本地 Python)json{
"mcpServers": {
"pyats": {
"command": "python3",
"args": ["-u", "/path/to/pyats_mcp_server.py"],
"env": {
"PYATS_TESTBED_PATH": "/absolute/path/to/testbed.yaml"
}
}
}
}
---
可用工具
docker build -t pyats-mcp-server .docker run -i --rm \
--env-file /absolute/path/to/.env \
-v /absolute/path/to/testbed.yaml:/app/testbed.yaml \
pyats-mcp-server{
"mcpServers": {
"pyats": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--env-file", "/absolute/path/to/.env",
"-v", "/absolute/path/to/testbed.yaml:/app/testbed.yaml",
"pyats-mcp-server"
]
}
}
}{
"mcpServers": {
"pyats": {
"command": "python3",
"args": ["-u", "/path/to/pyats_mcp_server.py"],
"env": {
"PYATS_TESTBED_PATH": "/absolute/path/to/testbed.yaml"
}
}
}
}| 工具 | 描述 |
|------|-------------|
| pyats_list_devices | 列出 testbed 中的所有设备 |
| pyats_search_devices | 通过名称或别名模糊搜索设备 |
| pyats_run_show_command | 运行经过验证的 show 命令;返回解析后的 JSON 或原始输出 |
| pyats_run_show_command_on_multiple_devices | 在多个设备上并发运行 show 命令 |
| pyats_ping_from_network_device | 从网络设备执行 ping |
| pyats_run_linux_command | 在 Linux 主机上运行命令 |
| pyats_configure_device | 在安全防护机制下应用配置命令 |
| pyats_configure_devices_multi | 在多个设备上并发应用配置 |
| pyats_configure_with_diff | 应用配置并返回变更前后的 diff |
| pyats_rollback_config | 回滚到上一次保存的配置快照 |
| pyats_device_health | 快照 CPU、内存、接口和路由状态 |
| pyats_get_neighbors | 获取 CDP/LLDP 邻居 |
| pyats_find_interface_by_ip | 查找给定 IP 地址所属的接口 |
| pyats_run_dynamic_test | 执行沙箱化的 pyATS 测试脚本 |
| pyats_get_operation_log | 获取内存中的操作日志 |
---
安全性- Show 命令经过验证 —— 拦截管道、重定向和危险关键字
- 配置变更会检查
reload、erase、write erase、delete、format
- 动态测试脚本在受限沙箱中运行(禁用导入:
os、sys、subprocess等)
- 所有凭据均来自
.env—— 绝不存储在 testbed 文件或源代码中
---
Project Structurecode.
├── pyats_mcp_server.py # MCP server
├── test_pyats_mcp_server.py # Unit tests (85 tests)
├── Dockerfile # Container definition
├── requirements.txt # Pinned runtime dependencies
├── requirements-dev.txt # Dev/test dependencies
├── pyproject.toml # Tool config (black, isort, pytest, mypy)
├── .env.example # Configuration template — copy to .env
├── .gitignore
├── LICENSE
└── CONTRIBUTING.md
---
开发bash# Install dev dependencies with uv
uv venv .venv && uv pip install -r requirements-dev.txt
Run tests
.venv/bin/python -m pytest
Lint and format
.venv/bin/black .
.venv/bin/isort .
.venv/bin/flake8 . --max-line-length=100
.
├── pyats_mcp_server.py # MCP server
├── test_pyats_mcp_server.py # Unit tests (85 tests)
├── Dockerfile # Container definition
├── requirements.txt # Pinned runtime dependencies
├── requirements-dev.txt # Dev/test dependencies
├── pyproject.toml # Tool config (black, isort, pytest, mypy)
├── .env.example # Configuration template — copy to .env
├── .gitignore
├── LICENSE
└── CONTRIBUTING.md# Install dev dependencies with uv
uv venv .venv && uv pip install -r requirements-dev.txt
Run tests
.venv/bin/python -m pytest
Lint and format
.venv/bin/black .
.venv/bin/isort .
.venv/bin/flake8 . --max-line-length=100