fritzbox-mcp
# fritzbox-mcp
An MCP server for a FRITZ!Box router. It talks TR-064 (SOAP over HTTPS on port 49443, with digest auth) and gives a model ten tools: reads for the line, devices, mesh, Wi-Fi and port forwards, and a two-step plan and apply for changes. It runs over stdio for a local client such as Claude Code, or over streamable HTTP behind an MCP gateway.
## Tools
| Tool | What it returns |
| --- | --- |
| `fritzbox_status` | Model, firmware, uptime, internet connection, public IP, line rate, DHCP range |
| `fritzbox_hosts` | Every device the box knows: IP, MAC, name, active, LAN or Wi-Fi, guest, internet blocked |
| `fritzbox_mesh` | Mesh nodes and their links |
| `fritzbox_wifi` | Wi-Fi interfaces by index: SSID, on or off, channel, security, client count (never the keys) |
| `fritzbox_port_forwards` | Port forwards from the internet |
| `fritzbox_services` | The box's TR-064 services |
| `fritzbox_actions` | One service's actions, which of them are reads, and each input argument with its type, allowed values, range and default |
| `fritzbox_get` | Any read action, with arguments |
| `fritzbox_plan`, `fritzbox_apply` | Changes, in two steps |
Reads are actions named `Get*`, `X_AVM-DE_Get*` or `X_Get*`. Answer fields that look secret (passwords, Wi-Fi keys, PSKs, PINs) come back as `<hidden>`, and so does the configured password wherever it appears.
On fiber models, `GetCommonLinkProperties` reports the line as 1 Mbit/s. `fritzbox_status` reads the provisioned rate from `X_AVM-DE_GetOnlineMonitor` instead and falls back to the Layer 1 fields on boxes without it.
## Changes
`fritzbox_plan` writes nothing. It returns what would change and an `expect` text such as `1 change, 0 delete`. `fritzbox_apply(plan_id, expect)` makes the change once. Plans are signed with a key that lives only in the running process, expire after 15 minutes, and are refused if what they touch has changed since.
| Op | What it does |
| --- | --- |
| `port-forward` | Adds a forward to a LAN address. If the port already forwards somewhere else, the old mapping is removed first, which counts as a removal |
| `port-forward-delete` | Removes a forward |
| `wifi` | Turns a Wi-Fi interface on or off |
| `block-internet` | Cuts one device off the internet; the LAN keeps working |
| `wake` | Wake-on-LAN |
| `reconnect` | Drops and redials the line |
| `reboot` | Restarts the box; the home network is down for about 3 minutes |
| `call` | Any other TR-064 action, checked against the service's own action list. Actions named Delete or Remove count as removals |
Removals need `FRITZ_MCP_DELETE=1`. Everything else needs only the apply, which a client like Claude Code asks you to approve. The plan warns when a change can cut the model's own connection (reboot, reconnect, Wi-Fi off) or hits a device listed in `FRITZ_MCP_KEY_HOSTS`. Every plan and apply goes to an audit log in the state directory.
## FRITZ!Box user
Make a separate user in the box (System > FRITZ!Box Users) with the right to change FRITZ!Box settings, and turn on "Allow access for applications" under Home Network > Network > Network Settings. Adding port forwards through TR-064 can also need the box's setting that lets applications change port sharing.
## Settings
| Variable | Meaning |
| --- | --- |
| `FRITZ_URL` | Default `https://fritz.box:49443`. The box's certificate is self-signed, so it isn't verified; use this only on your LAN |
| `FRITZ_USER`, `FRITZ_PASSWORD` | The FRITZ!Box user. The password is never printed |
| `FRITZ_MCP_DELETE=1` | Allows removals |
| `FRITZ_MCP_TIMEOUT` | Seconds, default 30 |
| `FRITZ_MCP_NOTES` | Optional text added to the server's instructions, for what the model should know about your network ("the NAS at .20 runs the VPN; the repeater in the attic carries the office") |
| `FRITZ_MCP_KEY_HOSTS` | Optional `ip=name` pairs, comma separated. Blocking one of these devices' internet gets a warning in the plan |
| `MCP_STATE_DIR` | Where plans and the audit log go |
On Windows, a variable set with `setx` is read from the registry, so a running client picks it up without a restart.
## Running it locally
With [uv](https://docs.astral.sh/uv/), in Claude Code:
```sh
claude mcp add fritzbox --env FRITZ_USER=mcp --env FRITZ_PASSWORD=... -- uvx --from git+https://github.com/androsmeda/fritzbox-mcp fritzbox-mcp
```
Or in a client's JSON config:
```json
"fritzbox": {
"command": "uvx",
"args": ["--from", "git+https://github.com/androsmeda/fritzbox-mcp", "fritzbox-mcp"],
"env": {"FRITZ_USER": "mcp", "FRITZ_PASSWORD": "..."}
}
```
## Behind a gateway
With `MCP_TRANSPORT=http` the server listens on `MCP_HTTP_HOST:MCP_HTTP_PORT` (default `0.0.0.0:8000`) at `/mcp`. It refuses to start unless these are set:
- `MCP_HTTP_TOKEN`: at least 32 printable characters. Every request needs exactly one `Authorization: Bearer <token>` header.
- `MCP_HTTP_ALLOWED_HOSTS`: the host names the gateway uses, such as `fritzbox-mcp:8000`.
`MCP_HTTP_TOOLS=read` (the default) serves only the read tools and removes plan and apply before the server starts. `MCP_HTTP_TOOLS=all` serves all ten, and the gateway decides who reaches them. Either way, only `initialize`, `ping`, `tools/list` and `tools/call` are answered. The server speaks plain HTTP, so keep its port on the gateway's internal network.
The image is `ghcr.io/androsmeda/fritzbox-mcp`, tagged with the commit SHA:
```sh
docker run -d --name fritzbox-mcp --network gateway-net \
-e FRITZ_URL=https://192.168.178.1:49443 -e FRITZ_USER=mcp -e FRITZ_PASSWORD=... \
-e MCP_HTTP_TOKEN=... -e MCP_HTTP_ALLOWED_HOSTS=fritzbox-mcp:8000 \
-v /path/to/state:/state ghcr.io/androsmeda/fritzbox-mcp:<sha>
```
It runs as uid 99, gid 100, so the state folder must be writable by that user.
## Tests
```sh
uv run pytest
```
The tests run against a fake box (`tests/fake_fritz.py`) that speaks digest auth, the TR-064 description and SCPDs, SOAP, and the host and mesh list files, so they never call a real box.
## License
MIT
TDQS
Scored across 10 tools
Each tool targets a distinct FRITZ!Box area or phase of the plan/apply workflow, so most boundaries are clear. The only mild overlap is fritzbox_get, whose generic TR-064 read capability can duplicate specific readers like fritzbox_hosts, though the descriptions give enough guidance to choose.
All tools share the fritzbox_ prefix and use consistent snake_case, with readable noun names for readers and verb-like names for action tools. There are no mixed conventions or casing inconsistencies.
Ten tools is well-scoped for a router management server: a compact set of focused readers, three TR-064 introspection tools, and a safe plan/apply pair for writes. Nothing feels redundant or missing at the count level.
The surface covers status, hosts, mesh, Wi-Fi, port forwards, raw TR-064 discovery/read, and a broad write path via plans including port forwards, Wi-Fi, internet blocking, wake, reconnect, reboot, and arbitrary actions. This gives both targeted convenience tools and a generic escape hatch for less common operations.