Pyats network

From automateyournetwork/netclaw · View interactive version

Pyats network is an AI agent skill from the GitHub repository automateyournetwork/netclaw. Network device automation via pyATS - run show commands, ping, apply config, learn config/logging, list devices, run Linux commands on Cisco IOS-XE/NX-OS devices. Use when running CLI commands on routers or switches, checking interface status, applying configuration changes, or collecting device dat

How to use this skill

Skill file

pyATS Network Device Tool

Dynamic-inventory note (Spec160): for NETCLAW_TESTBED_MODE=dynamic, use the

persistent native pyATS MCP session that composed, validated and explicitly activated

the reviewed candidate. Separate MCP_CALL processes do not share dynamic inventory.

Use scripts/pyats-testbed-session.py only for bounded preview/activate/list; it does

not perform device operations. The static examples below apply to static mode.

See docs/DYNAMIC-TESTBEDS.md; all existing device/change-control requirements apply.

Installer note: native registration and the documented MCP_CALL invocation share the installed component launcher. Check readiness.json before first use; failed discovery is not device state. Existing write approvals still apply.

Managed dynamic tools

The managed server has 35 tools: 34 pinned upstream tools and

netclaw_testbed_compose. New upstream names are pyats_testbed_sources,

pyats_testbed_source_inventories, pyats_testbed_build, pyats_testbed_validate,

pyats_testbed_activate, pyats_testbed_list, pyats_testbed_get, and

pyats_testbed_delete. Discover actual schemas before use.

Select Dynamic and explicit sources in setup first. Read source inventory with its

existing MCP (or an explicitly obtained export), record scope/completeness/freshness,

then call compose with the documented envelope. Review the preview, validate without

reachability, and explicitly activate. Only completed schema/credential validation

permits activation. Native raw fetch/static merge are disabled in the managed wrapper;

source discovery explains the equivalent composition route. Console ports, controller

status and inventory membership never prove SSH access or device health. Restart

requires rebuilding, validating and activating in the new process.

Server & Testbed

Available Devices

Devices are defined in $PYATS_TESTBED_PATH and vary per installation — run pyats_list_devices

first to see the actual device names, aliases, and platforms available in this testbed (e.g. R1

on Cisco IOS-XE). Examples below use R1 as a placeholder device name; substitute the real device

name(s) returned by pyats_list_devices.

How to Call Tools

Use the $MCP_CALL protocol handler to invoke MCP tools:

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" TOOL_NAME 'ARGS_JSON'

Selected device tools

1. `pyats_list_devices`

List all devices in the testbed with their properties: name, alias, type, OS, platform, connection types, credentials summary.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_list_devices '{}'

Use when: Starting any session — always list devices first to observe the selected inventory; this does not prove connectivity.

2. `pyats_run_show_command`

Execute any show command with automatic Genie structured parsing. Returns parsed JSON when a Genie parser exists, raw text otherwise.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_run_show_command '{"device_name":"R1","command":"show ip interface brief"}'

Validation rules:

Commands with Genie parsers (structured JSON output) on IOS-XE:

Routing:

Interfaces:

L2/Switching:

Neighbors:

FHRP:

System:

Security:

QoS:

VRF / MPLS:

Other:

3. `pyats_configure_device`

Apply configuration changes to a device. Automatically enters config mode and exits.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_configure_device '{"device_name":"R1","config_commands":["interface Loopback99","ip address 99.99.99.99 255.255.255.255","description NetClaw-Test","no shutdown"]}'

Rules:

4. `pyats_show_running_config`

Retrieve the full running configuration from a device.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_show_running_config '{"device_name":"R1"}'

Use when: Capturing configuration baselines, auditing config, pre/post change verification.

5. `pyats_show_logging`

Fetch system logs (last 250 entries) from a device.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_show_logging '{"device_name":"R1"}'

Use when: Checking for errors, tracebacks, interface flaps, protocol events after changes.

6. `pyats_ping_from_network_device`

Execute ping from the network device itself (not from the MCP client).

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_ping_from_network_device '{"device_name":"R1","command":"ping 8.8.8.8"}'

Returns: Structured JSON with success rate %, RTT stats, packet loss when Genie parsing succeeds.

7. `pyats_run_linux_command`

Execute shell commands on Linux-based devices in the testbed.

Use when: The testbed includes Linux hosts (containers, VMs) for system administration tasks.

8. `pyats_run_dynamic_test`

Execute a complete pyATS AEtest validation script inline. The script runs in a sandboxed environment.

PYATS_TESTBED_PATH=$PYATS_TESTBED_PATH python3 $MCP_CALL "${PYATS_PYTHON:-python3} -u $PYATS_MCP_SCRIPT" pyats_run_dynamic_test '{"test_script_content":"import logging\nfrom pyats import aetest\n\nlogger = logging.getLogger(__name__)\n\nTEST_DATA = {\"expected_interfaces\": [\"GigabitEthernet1\", \"Loopback0\"]}\n\nclass InterfaceTest(aetest.Testcase):\n    @aetest.test\n    def verify_interfaces(self):\n        for intf in TEST_DATA[\"expected_interfaces\"]:\n            logger.info(f\"Checking interface: {intf}\")\n            assert intf.startswith(\"Gi\") or intf.startswith(\"Loop\"), f\"Unexpected interface type: {intf}\"\n\nif __name__ == \"__main__\":\n    aetest.main()"}'

Rules:

Use when: Complex pass/fail validation, multi-step assertions, compliance checks on data already collected via show commands.

Alternative: Direct Python pyATS

For operations beyond the 8 MCP tools, use pyATS directly:

from pyats.topology import loader
tb = loader.load('$PYATS_TESTBED_PATH')
device = tb.devices['R1']
device.connect(learn_hostname=True, log_stdout=False)
output = device.parse('show ip interface brief')
print(output)
device.disconnect()

Genie Learn (multi-command feature snapshots)

from genie.testbed import load
testbed = load('$PYATS_TESTBED_PATH')
dev = testbed.devices['R1']
dev.connect(learn_hostname=True, log_stdout=False)

# Learn returns an OS-agnostic normalized data model
ospf = dev.learn('ospf')       # Neighbors, interfaces, database, areas, LSAs
bgp = dev.learn('bgp')         # Neighbors, address-families, routes, state
intf = dev.learn('interface')   # All interfaces: status, IP, counters, MTU, speed
routing = dev.learn('routing')  # Full routing table from all protocols
platform = dev.learn('platform') # Hardware, modules, images, slots

print(ospf.info)
dev.disconnect()

All 34 learnable features: acl, arp, bgp, config, device, dot1x, eigrp, fdb, hsrp, igmp, interface, isis, lag, lisp, lldp, mcast, mld, msdp, nd, ntp, ospf, pim, platform, prefix_list, rip, route_policy, routing, static_routing, stp, terminal, utils, vlan, vrf, vxlan.

Genie Diff (state comparison)

from genie.utils.diff import Diff

# Capture before state
before = dev.learn('ospf')

# ... make changes ...

# Capture after state
after = dev.learn('ospf')

diff = Diff(before.info, after.info)
diff.findDiff()
print(diff)  # Shows + additions and - deletions

Failure Behavior

MCP Tasks

For eligible tools, a client declaring the current Tasks extension may receive a task handle. Retain it and poll for the terminal result; do not resubmit pending work. Ordinary clients continue receiving foreground results. A handle is not execution success or approval: preserve required baseline/change-control checks before invocation and verify the completed result afterward. Cancellation cannot undo commands already sent. Investigate unknown outcomes before retrying. pyATS retains completed results in SQLite and lets started work finish; other FastMCP tools default to ephemeral state and cooperative cancellation. See docs/MCP-TASKS.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.