icx-mcp
# icx-mcp
An [MCP](https://modelcontextprotocol.io) server that gives an AI agent live,
structured access to a **Ruckus ICX 7450 running FastIron 09.0.10k**, so it can
explain switch state and recommend configuration changes. It has no write tools:
recommended changes come back as FastIron CLI for a person to review and apply.
* **RESTCONF first** (async `httpx`), **SSH fallback** (Netmiko, allowlisted `show` commands only).
* Transports: **stdio** for local use and **streamable HTTP** for Kubernetes, plus `/health`.
* Every result includes `source: "restconf" | "ssh"` so you know which backend answered.
## Tools
| Tool | What it returns | Primary | Fallback |
|---|---|---|---|
| `list_devices` | Configured switch, enabled backends (no secrets) | local | – |
| `discover_restconf` | Reachability, auth check, YANG modules exposed | RESTCONF | – |
| `get_system_info` | Model, serial, version, hostname, uptime, CPU, memory | RESTCONF | `show version`, `show cpu-utilization`, `show memory` |
| `get_interfaces` | Admin/oper state, speed, duplex, description, errors (filterable) | RESTCONF | `show interfaces brief` |
| `get_poe_status` | PoE budget, per-port power, class, PD type, priority, faults | RESTCONF | `show inline power` |
| `get_stp_status` | STP/RSTP/MSTP per instance: root, root port, port roles and states, edge ports | RESTCONF | `show 802-1w`, `show span` |
| `get_vlans` | VLANs and tagged/untagged membership | RESTCONF | `show vlan` |
| `get_running_config` | CLI text (filter by `section`/`match`) or YANG JSON (`yang_path`), secrets redacted | SSH (cli) / RESTCONF (yang) | the other one |
| `run_show_command` | Raw output of one allowlisted `show` command | SSH | – |
## Switch preparation (FastIron)
1. Create a dedicated **privilege-0** account for the server. FastIron only lets
privilege-0 users use RESTCONF; a privilege-5 (read-only) user gets HTTP 401.
```
username mcp privilege 0 password <strong-password>
```
This is an admin account. The server itself only sends RESTCONF GETs and
allowlisted `show` commands, but anyone holding the password has full control of the
switch. Keep it in `.env` / a Kubernetes Secret and keep the MCP endpoint private.
2. Enable RESTCONF. It shares TCP 443 with the HTTPS web UI
(`aaa authentication web-server default local` must be set):
```
configure terminal
restconf enable
exit
write memory
```
Until RESTCONF is enabled, the web UI answers every `/restconf/...` URL with 200
`text/html`; `discover_restconf` then reports `restconf_detected: false`.
3. Keep SSH enabled (`aaa authentication login default local`). Some data is not in
FastIron's RESTCONF API at all (see below).
### What comes from where (verified on 09.0.10k)
| Data | RESTCONF | SSH (only what RESTCONF lacks) |
|---|---|---|
| Interfaces | `/restconf/data/interfaces`: status, speed, duplex, counters | – |
| VLANs | `.../network-instance/default-vrf/vlans` + each port's `switched-vlan` | – |
| PoE | power used and allocated (mW → W), priority | oper state, PD type, class, chassis budget (`show inline power`) |
| STP | `/restconf/data/stp`: per-VLAN priority, edge-port, BPDU guard (**config only**) | root bridge, port roles and states (`show 802-1w`) |
| System | hostname; model, temperatures, PSU and fan status (`/components`) | version, serial, uptime, CPU, memory |
| Running config | YANG config datastore (default) | CLI text when `section`, `match` or `list_sections` is used |
RESTCONF port names (`ethernet 1/1/1`, `ve 98`, `management 1`) are converted to CLI
style (`1/1/1`, `ve98`, `mgmt1`) so both backends name ports the same way. Results that
combine backends have `source: "restconf+ssh"` and list `ssh_supplemented_fields`.
Each SSH-backed call adds about 10 s (SSH login on the ICX); RESTCONF-only calls take
about 1 s.
## Run locally (stdio)
```bash
uv venv && uv pip install -e '.[dev]'
cp .env.example .env # set ICX_HOST, ICX_USERNAME, ICX_PASSWORD
.venv/bin/icx-mcp # or: python -m icx_mcp.server
```
**Claude Code:**
```bash
claude mcp add icx --env ICX_HOST=192.168.1.2 --env ICX_USERNAME=mcp \
--env ICX_PASSWORD=... --env ICX_VERIFY_TLS=false -- /path/to/.venv/bin/icx-mcp
```
**Claude Desktop** (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"icx": {
"command": "/path/to/fastiron-mcp-server/.venv/bin/icx-mcp",
"env": {"ICX_HOST": "192.168.1.2", "ICX_USERNAME": "mcp",
"ICX_PASSWORD": "...", "ICX_VERIFY_TLS": "false"}
}
}
}
```
### First connectivity test
Ask the agent to call `discover_restconf`, then `get_system_info`, then
`get_interfaces`. Or test without an agent:
```bash
npx @modelcontextprotocol/inspector .venv/bin/icx-mcp
```
If `discover_restconf` shows `auth_ok: false`, check the credentials and that the
account is privilege 0. After a 401 the server stops trying RESTCONF for 5 minutes, so
failed logins don't pile up. If a tool reports *"No RESTCONF path for 'stp'
answered 200"*, it has already fallen back to SSH. Its `restconf_errors[].attempts`
list every path it tried. Use `discover_restconf` to find the right module and pin
it, for example:
```bash
ICX_RESTCONF_PATH_STP=/restconf/data/openconfig-spanning-tree:stp
```
## Run in Kubernetes (streamable HTTP)
```bash
# released images: quay.io/carobb/fastiron-mcp-server:<version> (amd64 + arm64)
# or build your own: podman build -f docker/Dockerfile -t <registry>/fastiron-mcp-server:dev .
kubectl create secret generic icx-mcp-credentials \
--from-literal=ICX_USERNAME=mcp --from-literal=ICX_PASSWORD='...'
# edit k8s/deployment.yaml: ICX_HOST in the ConfigMap (and the image tag if needed)
kubectl apply -f k8s/deployment.yaml -f k8s/service.yaml
```
* MCP endpoint: `http://icx-mcp.<ns>.svc:8000/mcp` (stateless streamable HTTP).
* Probes: `GET /health` is cheap and does not contact the switch.
`GET /health?deep=1` also checks that RESTCONF is reachable (503 if not).
* The container runs as UID 10001 with a read-only root filesystem and all
capabilities dropped.
* **The MCP endpoint has no authentication of its own.** Keep the Service as
ClusterIP, restrict it with a NetworkPolicy, or put an authenticating proxy in
front before exposing it.
* Use 1 replica. The switch has a small session limit.
Run the HTTP transport locally: `ICX_TRANSPORT=streamable-http ICX_HTTP_HOST=127.0.0.1 icx-mcp`.
## Configuration
All settings are `ICX_*` environment variables (or a `.env` file). See
[`.env.example`](.env.example). Credentials only come from env vars or Kubernetes
Secrets. The optional YAML inventory (`ICX_INVENTORY_FILE`) is refused if it
contains secrets.
## Defaults and design decisions
| Decision | Default and reason |
|---|---|
| RESTCONF paths | FastIron exposes mostly **OpenConfig** models. Its documented examples use un-prefixed paths such as `/restconf/data/lldp`. Each resource has an ordered list of candidate paths, prefixed and un-prefixed (see `CANDIDATE_PATHS` in `restconf_client.py`). The first one that returns 200 is cached for the life of the process. Override any of them with `ICX_RESTCONF_PATH_<RESOURCE>`. |
| PoE source | RESTCONF `icx-openconfig-if-poe-aug` for per-port state, with `power-used` read as milliwatts. Fields RESTCONF lacks are added from `show inline power`; pass `include_cli_details=false` to skip that. If RESTCONF has no PoE data, everything comes from SSH. |
| STP on ICX | FastIron usually runs **802.1w per VLAN**, so results are a list of instances keyed by VLAN. |
| Running config | YANG JSON via RESTCONF by default (REST first). CLI text over SSH for `section` / `match` / `list_sections` or `format="cli"`, which is what change recommendations are written in. Secrets are always redacted, including the AAA password hashes inside `/restconf/data/system`. |
| TLS | `ICX_VERIFY_TLS=true` by default. The ICX uses a self-signed cert, so either give it a CA bundle path (preferred) or set `false`. |
| Retries | 2 retries with exponential backoff on connection errors, timeouts and 5xx. 401/403 fail fast. 400/404/405/501 move on to the next candidate path. |
| SSH | A short-lived session per call (always disconnected), calls serialized, `ruckus_fastiron` driver (it sends `skip-page-display`). Commands must match a `show` allowlist. `; \| & $` and newlines are rejected. |
| Logging | Goes to stderr (stdout is the stdio protocol). Passwords are scrubbed by a log filter. `httpx`, `paramiko` and `netmiko` are kept at WARNING unless `ICX_DEBUG=true`. |
| MCP SDK | Pinned to `mcp<2`. SDK v2 renamed `FastMCP` to `MCPServer`, so migrating is a separate, deliberate step. |
| Python | 3.12+ (the container uses 3.12). |
## Development
```bash
.venv/bin/pytest -q # RESTCONF is mocked with respx; SSH with canned CLI output
.venv/bin/ruff check src tests
```
The SSH parsers are tested against representative FastIron 09.0.x output. If your
switch prints something different, paste the real output into `tests/test_tools.py`
and adjust the regexes in `src/icx_mcp/tools/*.py`.
## Releasing
CI (`.github/workflows/ci.yml`) runs ruff, pytest (Python 3.12 and 3.13) and a container
build on every push and PR. To release:
1. Bump `version` in `pyproject.toml` and `__version__` in `src/icx_mcp/__init__.py`.
2. Commit, then `git tag v<version> && git push origin v<version>`.
`.github/workflows/release.yml` then tests, checks the tag matches the version, pushes
`quay.io/carobb/fastiron-mcp-server:<version>`, `:<major>.<minor>` and `:latest`
(amd64 + arm64), and creates a GitHub Release with the wheel and sdist. It needs the
repository secrets `QUAY_USERNAME` and `QUAY_PASSWORD` (a Quay robot account with
write access to the repository).
## Roadmap (not in v1)
`get_lldp_neighbors` and `get_logs` as structured tools (use `run_show_command`
for now). Multi-switch inventory, caching, and write tools. Write tools would only
come with dry-run and explicit human approval.
TDQS
Scored across 9 tools
Each structured getter targets a distinct domain (system, interfaces, PoE, STP, VLANs, config), and descriptions give explicit guidance on when to prefer one over another. The only real overlaps are list_devices vs discover_restconf (both framed as 'call first if unsure') and get_running_config vs run_show_command, though the latter's 'use only when no structured tool covers this' rule mitigates confusion.
Uniform snake_case with a predictable verb_noun shape: list_devices, discover_restconf, get_* family, run_show_command. No camelCase or vague bare verbs anywhere.
Nine tools for a single-switch diagnostic server is well scoped — one tool per major operational area plus two meta/escape-hatch tools, each earning its place.
Covers the core read-only surface an agent needs (identity, ports, PoE, STP, VLANs, config) plus run_show_command as a general escape hatch for LLDP, MAC tables, logs, and transceivers. No write/change tools exist, but that appears to be an intentional read-only scope rather than a gap, leaving at most minor holes like structured LAG/LLDP data.