Skip to main content
Glama
multivendor-netconf-mcp

multivendor-netconf-mcp

by Jitter00
README.md
# multivendor-netconf-mcp

An [MCP](https://modelcontextprotocol.io) server that lets an AI agent read and change
routers over NETCONF, with the same five tools on every platform. A change is checked by
the router before it is committed, the agent is shown what would change as a list of
configuration paths, and a commit is one the router undoes by itself unless it is
confirmed.

| Platform | Tried on | Notes |
|---|---|---|
| Juniper Junos | vSRX, Junos 20.4R1 | [docs/junos.md](docs/junos.md) |
| Cisco IOS XE | Catalyst 8000V, IOS XE 17.13.1 | [docs/cisco.md](docs/cisco.md) |
| Cisco IOS XR | IOS XRv 9000, IOS XR 7.11.1 | [docs/cisco.md](docs/cisco.md) |

> **Status: early.** Each platform was tried on one release, on virtual routers, and on
> nothing else. It is not a server for any NETCONF device: every vendor's NETCONF differs
> enough to need code of its own, and a fourth platform means writing that code. The
> server applies no rules of its own: it commits whatever it is given. Whoever puts it in
> front of real routers is responsible for validating it there first, with their own
> tests. Not affiliated with Juniper or Cisco.

## Why this exists

The MCP servers that exist for routers are mostly one per vendor, and return what the
command line prints. Juniper publishes
[junos-mcp-server](https://github.com/Juniper/junos-mcp-server), and for a person steering
an agent it does the job: it runs commands, loads configuration, has a
dry run and a confirmed commit. This project started from building a change firewall,
[Holddown](https://github.com/Jitter00/holddown), in front of it. A program that has to
judge an agent's change, and not only a person reading along, ran into four limits there.
They were seen at commit `2fb721a` of junos-mcp-server, against vSRX on Junos 20.4.

| | junos-mcp-server | multivendor-netconf-mcp |
|---|---|---|
| What a dry run returns | The text of `show \| compare`. A program has to parse indentation, braces and quoted names to know what changed. | One line per changed leaf, as its path with list keys: `+ interfaces interface[ge-0/0/0] description = to vsrx1`. The same lines whether the change was written as XML or as set commands. |
| Pipes in a show command | Passed to the router, which honours `display` and `compare` and drops `match`, `except`, `count`, `last` and the rest without saying so. The agent gets the whole output. (PyEZ's `cli()` documents this.) | Refused, with the reason. The server filters the output itself: `include`, `exclude`, `head`, `tail` and `count` parameters, the same on every platform. |
| A confirmed commit that is still pending | Told by `<commit-confirmed>` in the commit history, which Junos 20.4 does not have. On that release a pending commit is not seen without a patch. | Told the same way, with a documented fallback for releases without the element (`"legacy_pending": true`). |
| Vendors | Junos. | Junos, Cisco IOS XE and Cisco IOS XR, with the same tools and the same change lines. |

Where this server differs by design (on Junos; the Cisco platforms are in
[docs/cisco.md](docs/cisco.md)):

- **The change list is worked out from the configuration, not from text.** The server
  loads the change into the candidate, has the router check it (`commit check`), then
  compares the candidate with the committed configuration as XML.
- **List keys come from the router's own YANG modules**, read over NETCONF, so an entry is
  named by all of its keys: `security policies policy[trust,untrust]`.
- **A statement that is switched off shows** (`deactivate`): a line ending in `inactive`.
- **Somebody else's work is left alone.** The candidate on Junos is shared. If it already
  holds uncommitted changes, the server loads nothing and says so.
- **A commit while a confirmed commit is pending is refused.** On Junos any later commit
  makes the pending one permanent.
- **One login.** Show commands go over the NETCONF session too.

What junos-mcp-server has and this does not: Jinja2 templates, batch commands across
routers, device facts, PFE commands, an HTTP transport with tokens, and Juniper behind it.

## Install and run

Needs Python 3.11 or later and [uv](https://docs.astral.sh/uv/). NETCONF has to be on:
`set system services netconf ssh` on Junos, and see [docs/cisco.md](docs/cisco.md) for
IOS XE and IOS XR.

    git clone https://github.com/Jitter00/multivendor-netconf-mcp
    cd multivendor-netconf-mcp
    cp devices.example.json devices.json        # then put in your routers

    uv run multivendor-netconf-mcp -f devices.json --models
    uv run multivendor-netconf-mcp -f devices.json

The first command reads the routers' YANG modules once, for the keys of their lists. It
takes about a minute per software release and is kept under
`~/.local/state/multivendor-netconf-mcp` (or `$NETCONF_MCP_STATE`). Run it again after a
software upgrade. The second command is the MCP server, on stdio. For an MCP client:

    {"mcpServers": {"netconf": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/multivendor-netconf-mcp",
               "multivendor-netconf-mcp", "-f", "/path/to/devices.json"]}}}

`devices.json`:

    {"vsrx1": {"host": "192.0.2.11", "platform": "junos", "username": "netconf"}}

| Field | Meaning |
|---|---|
| `host`, `username` | where and as whom to log in |
| `platform` | `junos`, `iosxe` or `iosxr` |
| `password` | optional on Junos: without it the login is by SSH key, from your agent or your own keys. Needed on the Cisco platforms |
| `port` | NETCONF port, 830 by default |
| `legacy_pending` | `true` for Junos releases whose commit history has no `<commit-confirmed>` element (20.4). Without it the server finds nothing pending there and refuses to confirm |

## Tools

| Tool | What it does |
|---|---|
| `get_router_list` | the routers in `devices.json` |
| `get_config` | the configuration as XML, whole or limited by a subtree filter. On Junos also as set commands or in braces (`format`), or as the diff against a rollback (`compare_rollback`) |
| `execute_command` | one exec command, for example `show bgp summary`, with the output filtered by the server. On Junos also as XML or JSON (`format`) |
| `load_and_commit_config` | a dry run, a commit, or a commit the router undoes unless confirmed |
| `confirm_commit` | makes a pending confirmed commit permanent |

On Junos a change is `<configuration>` XML as `get_config` returns it, or lines of set
commands (on the Cisco platforms, XML in the router's own model):

    set interfaces ge-0/0/0 description "to vsrx1"
    delete protocols bgp group EBGP neighbor 10.0.1.1 shutdown
    deactivate interfaces lo0 unit 0 family inet address 10.255.0.2/32

A command may not hold a pipe. In its place:

    execute_command(router_name="vsrx1", command="show bgp summary", include="establ")
    execute_command(router_name="vsrx1", command="show interfaces terse", exclude="down", count=true)
    execute_command(router_name="vsrx1", command="show log messages", tail=20)

`include` and `exclude` are regular expressions and ignore case; then `head` or `tail`
keep that many lines, or `count` gives their number. The router sends the whole output
and the server cuts it down, so a filter saves the agent's reading, not the router's work.

For a change:

- `dry_run=true` loads it, has the router check it, returns what would change and discards
  it.
- `confirm_timeout_secs` makes it a confirmed commit. Junos counts in minutes, so give
  whole minutes (120); anything else is rounded up.
- `comment` goes into the router's commit log.

## Limits

- **No rules.** Any change the login may make is committed, and any exec command without
  a pipe is passed to the router as it comes, `request system reboot` included. Give the login a Junos class
  that fits, and put a policy in front: [Holddown](https://github.com/Jitter00/holddown)
  has adapters for this server (`junos_netconf`, `iosxe`, `iosxr`).
- **One release per platform, on virtual routers.** Nothing else was tried.
- **Groups are compared as written.** What a group changes where it is applied does not
  show under the places it applies to.
- **Secrets are returned.** `get_config` gives the configuration as the router holds it,
  password hashes included, and a dry run prints the hash of a secret it sets.
- **Host keys are not checked.**
- **Element names are printed without their module.**

## Development

    uv sync
    uv run ruff check
    uv run pytest

The tests need no router. Branches and pull requests only.

## Licence

MIT. See [LICENSE](LICENSE).