mcp_vyos
# MCP Server for VyOS
A production-ready [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that lets AI agents (**Claude Desktop**, **Claude Code**, **OpenCode**, **Antigravity**, **Codex**, and **Cursor**) inspect, configure, operate, and troubleshoot [**VyOS**](https://docs.vyos.io/en/rolling/) routers and firewalls.
---
## Architecture Overview
`mcp_vyos` drives VyOS through its [HTTPS API](https://docs.vyos.io/en/rolling/automation/vyos-api.html), with optional SSH for operational commands and fallback:
```
┌──────────────────────────────────────────────────────────────────────────────┐
│ AI Agents / MCP Clients │
│ (Claude Desktop • Claude Code • OpenCode • Antigravity • Codex • Cursor) │
└───────────────────────────────────────┬──────────────────────────────────────┘
│ MCP Protocol (stdio / sse)
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ mcp_vyos │
│ ┌────────────────────┐ ┌────────────────────┐ ┌────────────────────────┐ │
│ │ VyOS HTTPS API │ │ SSH client │ │ Safety & Redaction │ │
│ │ (key auth, form) │ │ (op-mode, paramiko)│ │ (read-only, secrets) │ │
│ └─────────┬──────────┘ └─────────┬──────────┘ └────────────────────────┘ │
└────────────┼───────────────────────┼──────────────────────────────────────────┘
│ HTTPS │ SSH (vbash)
▼ ▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ VyOS Router │
│ Single configuration tree: interfaces • firewall • nat • protocols (BGP/ │
│ OSPF/static) • service (DHCP/DNS/SSH/NTP) • vpn (WireGuard/IPsec/OpenVPN) • │
│ system • vrf • qos • container • pki • high-availability │
│ Endpoints: /configure /retrieve /show /generate /config-file /reset │
│ /reconnect /reboot /poweroff /image /info │
└──────────────────────────────────────────────────────────────────────────────┘
```
Because VyOS exposes its **entire configuration as one path tree**, a handful of generic primitives reach *every* feature. The server layers typed, validated domain wrappers on top for ergonomics, plus a raw escape hatch so nothing is ever out of reach.
---
## Complete Tools Reference
67 tools across 8 domains.
### 1. Generic configuration primitives (100% coverage)
| Tool | Arguments | Description |
|---|---|---|
| `vyos_show_config` | `path`, `include_secrets` | Retrieve the config tree or a subtree as JSON. Empty-but-valid paths return `{"configured": false}`. |
| `vyos_config_exists` | `path` | Check whether a config path exists. |
| `vyos_return_values` | `path`, `include_secrets` | Return the value(s) of a multi-valued node. |
| `vyos_show_config_commands` | `include_secrets` | Export running config as flat `set ...` commands (backup/diff). |
| `vyos_set` | `path`, `value`, `confirm_time`, `save` | Apply a single `set` and commit. |
| `vyos_delete` | `path`, `confirm_time`, `save` | Apply a single `delete` and commit. |
| `vyos_comment` | `path`, `comment`, `save` | Attach/remove a node comment. |
| `vyos_configure_batch` | `operations[]`, `confirm_time`, `save` | Apply mixed set/delete/comment ops as one transaction (use for validator-coupled fields). |
### 2. Operational & diagnostics
| Tool | Arguments | Description |
|---|---|---|
| `vyos_show` | `path`, `include_secrets` | Run any operational `show` command. |
| `vyos_generate` | `path` | Run a `generate` command (e.g. `pki wireguard key-pair`). |
| `vyos_get_info` | *none* | Public `/info`: version, hostname, banner (connectivity check). |
| `vyos_ping` | `host`, `count` | Ping from the router. |
| `vyos_traceroute` | `host` | Traceroute from the router. |
| `vyos_dns_lookup` | `host`, `nameserver` | Resolve a name from the router. |
### 3. Lifecycle & persistence
| Tool | Arguments | Description |
|---|---|---|
| `vyos_save_config` | `file` | Persist running config to disk (`/config/config.boot` by default). |
| `vyos_load_config` | `file`, `string` | Replace running config from a file or string. |
| `vyos_merge_config` | `file`, `string`, `confirm_time` | Merge config from a file or string. |
| `vyos_confirm_commit` | *none* | Confirm a pending commit-confirm (stops auto-revert). |
| `vyos_reset` | `path` | Run a `reset` command (e.g. clear a BGP session). |
| `vyos_reconnect` | `interface` | Bounce a PPPoE/WWAN interface. |
| `vyos_reboot` | `confirm`, `now` | Reboot (requires `confirm=True`). |
| `vyos_poweroff` | `confirm` | Power off (requires `confirm=True`). |
| `vyos_image_add` | `url`, `confirm` | Install a system image from a URL. |
| `vyos_image_delete` | `name`, `confirm` | Delete an installed image. |
### 4. Interfaces
`vyos_list_interfaces`, `vyos_get_interface`, `vyos_show_interfaces_status`, `vyos_set_interface_address`, `vyos_configure_interface`, `vyos_delete_interface` — ethernet, bridge, bonding, vxlan, wireguard, tunnel, dummy, loopback and more.
### 5. Firewall
`vyos_show_firewall`, `vyos_list_firewall_rules`, `vyos_add_firewall_rule` (action + protocol + ports in one commit), `vyos_delete_firewall_rule`, `vyos_set_firewall_default_action`, `vyos_configure_firewall_group` (address/network/port/interface/mac/domain groups).
### 6. NAT
`vyos_show_nat`, `vyos_add_source_nat_rule` (SNAT/masquerade), `vyos_add_destination_nat_rule` (DNAT/port-forward, translation bundled), `vyos_delete_nat_rule`.
### 7. Routing, Services, VPN, System
- **Routing**: `vyos_show_routes`, `vyos_add_static_route`, `vyos_delete_static_route`, `vyos_configure_bgp`, `vyos_configure_ospf`, `vyos_show_bgp_summary`, `vyos_show_ospf_neighbor`.
- **Services**: `vyos_list_services`, `vyos_show_dhcp_leases`, `vyos_configure_dhcp_server`, `vyos_configure_dns_forwarding`, `vyos_configure_ssh`, `vyos_configure_ntp`.
- **VPN**: `vyos_show_vpn_config`, `vyos_show_vpn_status`, `vyos_configure_wireguard`, `vyos_configure_ipsec_site_to_site`, `vyos_configure_openvpn`.
- **System**: `vyos_show_system_config`, `vyos_show_system_info`, `vyos_show_log`, `vyos_set_hostname`, `vyos_set_name_server`, `vyos_set_time_zone`, `vyos_configure_user`, `vyos_configure_task_scheduler`.
### 8. Raw escape hatch
| Tool | Arguments | Description |
|---|---|---|
| `vyos_raw_api_call` | `endpoint`, `data`, `confirm_time`, `include_secrets` | Call any VyOS endpoint directly with a raw payload. Write endpoints respect read-only mode. |
---
## Important VyOS Behavior
These are the rules the model (and you) must respect; the tool descriptions reinforce them.
1. **Commit is immediate, save is not.** Every `/configure` request commits to the running config right away but does **not** write to disk. Use `vyos_save_config` (or `save=True` on write tools) to persist across reboots.
2. **Validator-coupled fields must arrive together.** VyOS validates each request as a complete commit. A firewall rule's `action` + `protocol` + `port`, a NAT rule's `translation`, and a scheduler task's `interval`/`crontab-spec` must be sent in **one** request. Use `vyos_configure_batch` or the domain wrappers (which build complete transactions). Splitting them produces errors like *"Protocol must be defined if specifying a port"* or *"Configuration path ... is not valid"*.
3. **Commit-confirm is your safety net.** When reconfiguring a remote router, pass `confirm_time` (minutes). The change auto-reverts unless you call `vyos_confirm_commit`. Great for firewall and interface changes that could lock you out.
4. **Empty paths aren't errors.** `showConfig` on a valid-but-unconfigured path returns a clean `{"configured": false}` so desired-state comparisons work on a fresh system.
5. **Bulk applies:** prefer several moderate requests over one huge list; `geoip`/`remote-group` commits are expensive — apply one per request; the request body limit is `service https request-body-size-limit` (1 MB default).
---
## Permissions & Safety
Write operations are **enabled by default** (`VYOS_READONLY=false`).
Set `VYOS_READONLY=true` to restrict the server to inspection: all modifying tools (`vyos_set`, `vyos_delete`, `vyos_configure_batch`, every wrapper, `vyos_save_config`/`load`/`merge`, `vyos_reset`, `vyos_reconnect`, `vyos_reboot`, `vyos_poweroff`, `vyos_image_*`, and write endpoints via `vyos_raw_api_call`) are blocked with a clear error, while read tools (`vyos_show_config`, `vyos_show`, `vyos_get_info`, status tools) stay available.
High-impact tools (`vyos_reboot`, `vyos_poweroff`, `vyos_image_*`) additionally require explicit `confirm=True`.
### Secret redaction
VyOS returns secrets in clear text (PKI private keys, IPsec PSKs, WireGuard private/preshared keys, OpenVPN secrets, `service https api keys`, user password material). The server redacts them by default in both JSON config and flat `set ...` output. Pass `include_secrets=true` only when the value itself is required. `vyos_generate` is intentionally **not** redacted — generated keys are the point. Redaction is pattern-based.
---
## Enabling the VyOS HTTP API
On the router:
```
set service https api keys id MY-ID key 'MY-HTTPS-API-PLAINTEXT-KEY'
set service https api rest
commit
save
```
Useful extras:
- `set service https api rest strict` — reject deletes on non-existent paths (mirror with `VYOS_REST_STRICT=true`).
- `set service https port 8443` — custom port (put it in `VYOS_URL`).
- `set service https allow-client address 192.0.2.0/24` — restrict API clients.
- Bind a real certificate with `set service https certificates certificate <name>`; otherwise VyOS self-signs (use `VYOS_VERIFY_SSL=false`).
See the [HTTP API docs](https://docs.vyos.io/en/rolling/configuration/service/https.html).
---
## Installation & Setup
### Prerequisites
- Python 3.10+ (3.13 tested)
- Network access to the VyOS API listener (HTTPS 443 or custom), and SSH (optional)
### Local Python setup
```bash
git clone https://github.com/opentreecz/mcp-vyos.git
cd mcp-vyos
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
cp .env.example .env # edit with your router URL and API key
```
### Docker
```bash
docker compose up -d # SSE endpoint at http://localhost:8000/sse
```
---
## Configuration Variables (`.env`)
| Variable | Description | Default |
|---|---|---|
| `VYOS_URL` | Base HTTPS URL of the API listener (e.g. `https://192.168.1.1` or `https://192.168.1.1:8443`) | `https://127.0.0.1` |
| `VYOS_API_KEY` | Plaintext API key configured on VyOS | *Required* |
| `VYOS_VERIFY_SSL` | Verify TLS certificate (`false` for the self-signed default) | `false` |
| `VYOS_TIMEOUT` | HTTP timeout in seconds | `30` |
| `VYOS_READONLY` | Block all modifying operations | `false` |
| `VYOS_REST_STRICT` | Informational hint mirroring `api rest strict` | `false` |
| `VYOS_SSH_ENABLED` | Enable SSH operational fallback tools | `true` |
| `VYOS_SSH_HOST` | SSH host (defaults to the host in `VYOS_URL`) | Auto |
| `VYOS_SSH_PORT` | SSH port | `22` |
| `VYOS_SSH_USER` | SSH username | `vyos` |
| `VYOS_SSH_KEY_PATH` | Path to a private SSH key | `None` |
| `VYOS_SSH_KEY_PASSPHRASE` | Passphrase for an encrypted key | `None` |
| `VYOS_SSH_PASSWORD` | SSH password (if not using a key) | `None` |
| `VYOS_SSH_TIMEOUT` | SSH command timeout in seconds | `20` |
---
## Client Integration
### Claude Desktop
`~/.config/Claude/claude_desktop_config.json` (Linux) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):
```json
{
"mcpServers": {
"vyos": {
"command": "/path/to/mcp-vyos/.venv/bin/mcp-vyos",
"args": ["--transport", "stdio"],
"env": {
"VYOS_URL": "https://192.168.1.1",
"VYOS_API_KEY": "your_api_key_here",
"VYOS_VERIFY_SSL": "false",
"VYOS_READONLY": "false"
}
}
}
}
```
### Claude Code (CLI)
```bash
claude mcp add vyos -- /path/to/mcp-vyos/.venv/bin/mcp-vyos --transport stdio
```
### OpenCode
`~/.config/opencode/config.json`:
```json
{
"mcp": {
"vyos": {
"type": "local",
"command": [
"/path/to/mcp-vyos/.venv/bin/mcp-vyos",
"--env-file",
"/path/to/mcp-vyos/.env"
],
"enabled": true,
"timeout": 30000
}
}
}
```
### Antigravity & Cursor
```json
{
"mcpServers": {
"vyos": {
"command": "/path/to/mcp-vyos/.venv/bin/mcp-vyos",
"args": ["--env-file", "/path/to/mcp-vyos/.env"]
}
}
}
```
---
## Example: open the web/API port and a firewall rule
```python
# 1. Create an allow rule for TCP 8443 on the input hook (action + protocol + port in one commit)
vyos_add_firewall_rule(
rule=10, action="accept", family="ipv4", hook="input",
fields={"protocol": "tcp", "destination port": "8443", "state": "new"},
description="Allow VyOS API",
)
# 2. Move the API listener to 8443, with commit-confirm as a safety net
vyos_set(path="service https port", value="8443", confirm_time=2)
# 3. Verify you can still reach it, then confirm
vyos_confirm_commit()
# 4. Persist
vyos_save_config()
```
---
## Testing & Development
```bash
.venv/bin/pytest -v # unit tests
.venv/bin/ruff check . # linter
```
---
## License
MIT
TDQS
Scored across 67 tools
The specific per-resource tools (e.g. vyos_add_firewall_rule, vyos_configure_interface) coexist with generic catch-alls (vyos_set, vyos_delete, vyos_configure_batch, vyos_raw_api_call) that can accomplish the same changes, so an agent must decide which layer to use. Similarly, read tools overlap (vyos_show_config vs vyos_show vs vyos_show_system_config vs vyos_list_interfaces vs vyos_get_interface), though descriptions do clarify most boundaries.
Nearly all tools use a consistent vyos_verb_noun pattern (vyos_get_interface, vyos_add_firewall_rule, vyos_configure_bgp). A few outliers break the pattern slightly (vyos_return_values, vyos_config_exists, vyos_raw_api_call), but overall the naming is predictable and readable.
67 tools is heavy for the surface, and much of the volume comes from per-feature wrappers duplicating what vyos_set/vyos_configure_batch already do. The VyOS domain is genuinely broad, so many tools earn a place, but the redundancy pushes the count beyond what is well-scoped.
Coverage spans interfaces, firewall, NAT, static/BGP/OSPF routing, DHCP/DNS/SSH/NTP services, WireGuard/IPsec/OpenVPN, system settings, images, and operational diagnostics, with vyos_raw_api_call as an escape hatch. Some areas (QoS/traffic policy, VRRP/HA, prefix-lists/route-maps, policy-based routing) lack dedicated tools but can be reached via the generic batch/raw tools.