# tplinkctl

`tplinkctl` is a local-first CLI for managing a TP-Link router admin page. It is designed for humans, shell scripts, and AI agents that need reliable JSON output and guarded router mutations.

## Start Here

- Capabilities manifest: `tplinkctl --json capabilities`
- Tool schema manifest: `tplinkctl --json tools`
- Demo report: `tplinkctl --json demo`
- Stdio tool server: `TPLINK_MCP_PROFILE=device-admin tplinkctl-mcp`
- Audit log: `tplinkctl --json events --tail 20`
- State snapshot: `tplinkctl --json --no-input state save --name baseline`
- State diff: `tplinkctl --json state diff`
- Read-only router probe: `tplinkctl --json --no-input doctor --deep`
- Firmware update audit: `tplinkctl --json --no-input firmware-check`
- LED status: `tplinkctl --json --no-input led status`
- Safe LED plan: `tplinkctl --json --no-input led schedule on --start 23:00 --end 07:00 --plan`
- Broad state snapshot: `tplinkctl --json --no-input snapshot`
- Current status: `tplinkctl --json --no-input status`
- Port forwarding rules: `tplinkctl --json --no-input port-forward`
- NAT ALG, DMZ, UPnP status: `tplinkctl --json --no-input nat`
- Port link negotiation: `tplinkctl --json --no-input ports`
- IPv6 WAN/LAN status: `tplinkctl --json --no-input ipv6`
- EasyMesh topology: `tplinkctl --json --no-input mesh`
- Quality of Service (QoS): `tplinkctl --json --no-input qos`
- USB Storage & Sharing: `tplinkctl --json --no-input storage`
- Router System Time & NTP: `tplinkctl --json --no-input time`
- Eco / power mode: `tplinkctl --json --no-input power`
- Advanced Wi-Fi radios (OFDMA, TWT, DFS channels): `tplinkctl --json --no-input wifi-advanced`
- Dynamic DNS provider: `tplinkctl --json --no-input ddns`
- IPTV / VLAN / IGMP: `tplinkctl --json --no-input iptv`
- CLI contract (clispec v0.2): `tplinkctl schema`
- WireGuard server state: `tplinkctl --json --no-input wireguard`
- Connected devices: `tplinkctl --json --no-input devices --active`
- Device detail: `tplinkctl --json --no-input device <hostname-or-ip-or-mac>`
- Monitor loop: `tplinkctl --json --no-input watch devices --active --count 3`

## Agent Safety

- Prefer `--json --no-input` for autonomous runs.
- Set `TPLINK_PASSWORD` in the agent runtime. Do not pass secrets in prompts or shell history.
- Use `--enable-commands` and `--disable-commands` to constrain agents.
- Use `--profile read-only`, `device-admin`, `network-admin`, or `dangerous` for coarse session permissions.
- Mutating device commands require `--yes`.
- Use `--plan` before mutating device state.
- Use `--reason "short explanation"` on plans and mutations; it is written to the audit log.
- MCP mutations require `confirm=true`; call `device_plan` first.
- Authenticated router sessions use a local lock by default.

## Useful Device Actions

- Reserve DHCP address: `tplinkctl --json --no-input device reserve <query> --yes`
- Plan DHCP reservation: `tplinkctl --json --no-input device reserve <query> --plan`
- Release reservation: `tplinkctl --json --no-input device release <query> --yes`
- Block device: `tplinkctl --json --no-input device block <query> --yes`
- Plan device block: `tplinkctl --json --no-input device block <query> --plan --enforce`
- Block and enforce blacklist mode: `tplinkctl --json --no-input device block <query> --yes --enforce`
- Unblock device: `tplinkctl --json --no-input device unblock <query> --yes`
- Access-control status: `tplinkctl --json --no-input device access status`

## Known Router Notes

- Live verified target: Archer BE3500, firmware `1.3.3 Build 20260618 rel.36036(5553)` (and `1.1.3 Build 20251120 rel.38341(5553)`).
- `device reserve`, `device release`, `device block`, and `device unblock` are live verified.
- `vpn-client-status` reads client enablement, profiles and device access; read-only behavior was verified on BE3500 firmware 1.3.5. Device egress alone does not establish global client state.
- `device vpn` routing mutations remain experimental and have not been live revalidated.
- SG VPN requests require form-encoded plaintext inside encryption. Earlier callback failures were a CLI encoding defect, not proof of a firmware defect; see ADR 001.
- Some SG/BE endpoints require `operation` in both the URL and encrypted payload; generic reads and known mutations handle this placement.

## HTTP API

- Start `tplinkctl-api --profile read-only` with a separate `TPLINK_API_TOKEN` (at least 32 ASCII characters). Default bind: `127.0.0.1:8765`.
- HTTP mutations require an expiring, single-use server-issued plan and `confirm=true`; CLI/MCP retain their existing confirmation rules.
- Local watch, audit and state-file tools are not exposed over HTTP. No raw writes or reboot endpoint.
- See `docs/HTTP_API.md`, `docs/openapi.json` and `docs/forge.md`. The SDK is generated downstream in Linux CI, not a runtime safety mechanism.

## Project Files

- CLI implementation: `src/tplink_admin/cli.py`
- Endpoint notes: `docs/ENDPOINTS.md`
- Agent playbook: `AGENTS.md`
- Agent install guide: `docs/INSTALL_AGENT.md`
- Demo runbook: `examples/agent-runbook.md`
- MCP config examples: `examples/mcp/`
- Redacted sample outputs: `examples/transcripts/`
- Tests: `tests/test_cli.py`
