Skip to main content
Glama
tailnet-agent-mcp
by MC-intel
README.md
# tailnet-agent-mcp

MCP servers that let an AI assistant **work with devices on Tailscale tailnets**: list them, ping them,
probe their ports and web services, and (only where a human has allowed it) run a command or copy a file.
Two servers share one safety model:

| Server | Entry point | Scope |
|---|---|---|
| `tailnet-agent-mcp` | `tailnet_agent_mcp` | The machine's one **active** Tailscale profile |
| `multi-tailnet` | `tailnet_agent_mcp.multi` | **Several tailnets at once**, one userspace `tailscaled` each, no profile switching |

## Why it exists

I use one workstation against more than one tailnet (personal, a lab, and at one point an employer's), and
Tailscale lets only one profile be *active* on a machine's daemon. Two problems came out of that:

1. **Switching the active profile silently broke things.** A health-check job that reached hosts over the
   active tailnet went blind the moment the profile was switched for something unrelated. So the first server
   *checks the active profile before every call* and refuses, printing the exact switch command for a human to
   run. It never switches by itself.
2. **I wanted the assistant to reach several tailnets without any switching.** The second server runs one
   **userspace tailscaled per tailnet** as a systemd *user* unit (own socket, own state directory, local SOCKS5
   port). It needs no root and never touches the system daemon or its active profile.

## Tools

| Tool | What it does | Access |
|---|---|---|
| `tailnets` / `tailnet_up` / `tailnet_down` | (multi) which tailnets are configured and running; start or stop a node | `tailnet_up` returns a login URL a human must approve the first time |
| `tailnet_status` / `fleet_status` | all devices: IP, OS, tags, online, direct vs relay | read-only |
| `device_info` | one device in detail: OS, versions, key expiry, routes, traffic | read-only |
| `ping_device` | path (direct or relay) and latency | read-only |
| `check_ports` | TCP connect check of a port list | read-only |
| `http_probe` | GET a service: status, headers, title, TLS certificate summary | read-only |
| `tailscale_health` | local profile, health warnings, netcheck | read-only |
| `access_config` | show per-device access settings | read-only |
| `run_command`, `push_file`, `pull_file` | ssh / scp to a device | needs `exec = true` **and** an `ssh_user` |

## Safety model

All of this is covered by offline tests in [`tests/test_config_and_gate.py`](tests/test_config_and_gate.py).

* **Remote execution is off by default and gated per device, by a human.** A device needs both `exec = true`
  and an explicit `ssh_user` in the config file. `ssh_user` alone is not enough (tested). The assistant is
  instructed never to edit that file or guess usernames; when access is missing, the error tells it exactly
  what to ask the user for.
* **One choke point.** `run_command`, `push_file` and `pull_file` all go through a single `_access()`
  function, so the gate cannot be bypassed by one tool forgetting to check.
* **ssh runs in `BatchMode`** (never prompts), with its own `known_hosts` file, and through a ProxyCommand that
  uses that tailnet's own daemon socket. No credentials are stored: auth is the Tailscale SSH identity or your
  normal keys.
* **Wrong-tailnet guard.** Each tailnet's expected name is configured; a node that logged in somewhere else is
  refused.
* **Offline devices are refused** even when enabled, with when they were last seen.
* **Config is re-read on every call**, so the human can open or close the gate without restarting the server.
* **Tailscale SSH "check" mode** is handled: the tool returns the approval URL immediately instead of hanging.

## Run it

```sh
cp config.example.toml ~/.config/tailnet-agent-mcp/config.toml          # single-profile server
cp config.multi.example.toml ~/.config/multi-tailnet/config.toml        # multi-tailnet server
uv run python tests/smoke.py my-laptop                                  # exercise the read-only tools
# register with your MCP client: command = `uv --directory <repo> run tailnet-agent-mcp` (or `multi-tailnet`)
```

Python >= 3.12, the `mcp` SDK, and the `tailscale` CLI. The multi-tailnet server needs `tailscaled`
available for userspace nodes.

## Tests

```sh
PYTHONPATH=src python -m unittest discover -s tests -p 'test_*.py'    # 10 offline tests
```

`tests/smoke*.py` are live checks against a real tailnet and are not run by the unit-test command.

TDQS

A3.5/5.0

Scored across 10 tools

Disambiguation4/5

Most tools target a distinct action+resource (ping vs port check vs HTTP probe vs file transfer) and descriptions clarify the boundaries. Minor overlap: tailnet_status (tailnet-wide listing) vs tailscale_health (local node state) vs device_info (single device) could be momentarily confused, and access info appears in both device_info and access_config.

Naming Consistency3/5

All names are snake_case, which helps, but the conventions are mixed: verb_noun forms (ping_device, check_ports, run_command, push_file, pull_file) sit alongside noun phrases (tailnet_status, device_info, tailscale_health, access_config) and an ambiguous 'http_probe'.

Tool Count5/5

Ten tools is well within the sweet spot and each one maps to a clear, non-redundant capability: discovery, inspection, connectivity, port/web probing, health, exec, and file transfer. Nothing feels padded or missing from a count perspective.

Completeness4/5

Covers the practical lifecycle for a tailnet agent: enumerate devices, inspect one, test reachability at ICMP/TCP/HTTP layers, check local health/netcheck, and perform remote exec and file copy with a config introspection tool. Gaps are minor — no tailnet administration (key expiry reauth, node removal, ACL/DNS inspection) and no traceroute or DNS resolution check, but agents can work around these.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues