router-session-mcp
by yichase
README.md
# router-session-mcp
Use an MCP client to run commands on a router CLI over SSH, Telnet, or a simulator console on a Linux host. Each session keeps its own terminal and configuration view. An agent can disconnect, reconnect, and pick up where it left off.
## Quick start
Install Git, Python 3.12 or later, and [uv](https://docs.astral.sh/uv/getting-started/installation/). To start the server from source, run:
```sh
git clone https://github.com/yichase/router-session-mcp.git
cd router-session-mcp
uv run --frozen router-session-mcp
```
Select **Streamable HTTP** in your MCP client and enter `http://127.0.0.1:8765/mcp`. Use `--port` to change the port. The server listens on the loopback interface. Local clients that connect to it share the same device sessions.
## Connect to a device
| Mode | Arguments for `open_session` |
|---|---|
| `ssh` | Router `ip`, `username`, and `password`. The default port is 22. |
| `telnet` | Router `ip`, `username`, and `password`. The default port is 23. Telnet transmits credentials and commands in cleartext. |
| `ssh_connect` | SSH login details in `server_ssh` and a positive integer `router_number`. Each simulator session gets a separate SSH login. |
The CLI driver recognizes prompts such as `<Router3>` and `[Router3]`. Direct connections work without a configuration file. For SSH, the server verifies device and host keys against `~/.ssh/known_hosts` by default.
For simulator access, copy the [example configuration](config.example.toml), set `attach_command` to the console command on your Linux host, and start the server with that file:
```sh
cp config.example.toml config.toml
uv run --frozen router-session-mcp --config config.toml
```
For example, `attach_command = "connect"` and `router_number = 3` run `connect 3` on the host.
## Session tools
| Tool | Purpose |
|---|---|
| `open_session` | Log in and return a `session_id` and the device prompt. |
| `run_command` | Run one query or configuration command in the existing terminal and return its output and prompt. |
| `reply` | Use the current `interaction_id` to answer a device question. |
| `list_sessions` | Find sessions after reconnecting and inspect their targets, states, and pending questions. |
| `close_session` | Close a single device session. |
Device sessions stay open when an agent disconnects. Press Ctrl+C to stop the server and release all connections. If a command returns `outcome="unknown"`, check the device state before deciding whether to retry.
[Design and tool examples (Chinese)](docs/DESIGN.md) · [Contributing](CONTRIBUTING.md)
## License
This project is distributed under the [MIT License](LICENSE).