Flock MCP Service: flockmcpd
Overview
flockmcpd is the MCP server as a service. It serves the same tools as flockmcp, and answers them the same way, but it runs on its own and assistants connect to it over HTTP rather than starting it. Use it where the assistant cannot start a program on a host that can reach the routers: an assistant on another machine, or one that only connects to MCP servers by URL.
flockmcpd takes no options beyond --help and --version. It is configured by its configuration file only, which it reads once, when it starts.
Configuration file
flockmcpd reads /etc/flockmcpd/flockmcpd.json. FLOCKMCPD_CONF_DIR and FLOCKMCPD_CONF_FILE change where it looks. The file must exist, but every key in it is optional, so {} is a valid file.
{
"system": {
"api": {
"http": {
"bind_ip_addr": "::1",
"bind_port": 8650,
"allowed_hosts": ["mcp.example.com"]
}
}
},
"daemons": {
"r1": { "endpoint": "http://192.0.2.1:50051" },
"r2": { "endpoint": "http://[2001:db8::2]:50051", "allow_actions": true }
},
"request_timeout_secs": 10,
"connect_timeout_secs": 3
}
A key flockmcpd does not know is refused, so a mistyped key is reported rather than ignored.
system.api.http
The address and port flockmcpd serves on, modelled on flockd's own system.api.grpc. bind_ip_addr defaults to ::1 and bind_port to 8650.
allowed_hosts lists the names, in the HTTP Host header, that flockmcpd answers to. If it is left out, flockmcpd answers only to localhost, 127.0.0.1 and ::1. An entry without a port matches any port. An empty list is refused.
daemons
Each key names a router, and its endpoint gives the gRPC endpoint of its flockd, as --daemon does for flockmcp. The names and endpoints follow the same rules. A name may appear only once.
allow_actions, false by default, lets the assistant reset a BGP neighbor on that router. See Changing a Router.
With no daemons there is one daemon, named local, at http://[::1]:50051. flockmcpd does not read FLOCK_ENDPOINT. To allow actions on that daemon, list it: "daemons": { "local": { "endpoint": "http://[::1]:50051", "allow_actions": true } }.
request_timeout_secs and connect_timeout_secs
As --request-timeout and --connect-timeout for flockmcp, in seconds. They default to 10 and 3.
Serving
flockmcpd serves MCP at the path /mcp, so with the defaults an assistant on the same host connects to http://[::1]:8650/mcp. Use the address it binds, not localhost: an assistant that resolves localhost to 127.0.0.1 first finds nothing listening there. Any other path is answered with 404. See MCP Clients for how an assistant is told the URL.
Any number of assistants can be connected at once.
Security
flockmcpd has no authentication and no encryption. Anyone who can reach its address can use every tool, including resetting a BGP neighbor on a router with allow_actions.
- Keep the default loopback address unless the assistant is on another host, and then bind an address only trusted hosts can reach.
- A
bind_ip_addrthat is not loopback is logged as a warning whenflockmcpdstarts. - So is a
bind_ip_addrthat is not loopback with noallowed_hosts: such aflockmcpdanswers only requests that namelocalhost,127.0.0.1or::1as their Host, so a client that names it by its address or name is refused untilallowed_hostslists it. allowed_hostsguards against a web page reachingflockmcpdthrough DNS rebinding. It does not keep out a client that can reach the address: such a client chooses its own Host header. Only the bind address and the network limit who is served.- A request naming a Host not in
allowed_hostsis refused with 403.server_statuscounts the refusals, asrefused_hosts, and reports the rest of this: the address bound, the Host names allowed, and whether those are only the loopback names.
Running as a service
The Debian package runs flockmcpd as the systemd service flockmcpd. The service runs as an unprivileged user that systemd creates for it (DynamicUser=yes), with the system read-only, as flockmcpd needs only to read its configuration file and serve an unprivileged port.
# systemctl restart flockmcpd after changing the configuration file
$ journalctl -u flockmcpd its log
systemd restarts the service if it fails, except when its configuration file is refused (exit code 78), which a restart would not fix.
In a container
flockmcpd is also shipped as the container image ghcr.io/flocknetworks/flockmcpd:<version>, for hosts that run services under Docker. Its <version> is the package's: its major and minor version are those of the flockd release line it is for, and its patch number is its own. Write a configuration file for the container, mount it over the image's own, and publish its port on the host's loopback address:
$ docker run -d --name flockmcpd \
-p 127.0.0.1:8650:8650 \
-v /srv/flockmcpd/flockmcpd.json:/etc/flockmcpd/flockmcpd.json:ro \
ghcr.io/flocknetworks/flockmcpd:<version>
An assistant on the host then connects to http://127.0.0.1:8650/mcp.
- The configuration must bind
:::"system": {"api": {"http": {"bind_ip_addr": "::"}}}. Docker forwards a published port to the container's own network address, not to its loopback, so aflockmcpdleft at the default::1is up but no client reaches it. That makes a configuration written for the Debian package the wrong one to mount. Binding::inside the container does not expose it: who can reach it is decided by where the port is published. - The image's own configuration binds
::and names no daemons. It is only a safe default to mount a real one over. - Name each daemon by an address the container can reach. The default daemon,
localathttp://[::1]:50051, is the container's own loopback, where there is noflockd. - A configuration that leaves out
allowed_hostsserves only the loopback Host names, which is what an assistant on the host sends. An assistant that reaches the container by a name or another address needs that name or address inallowed_hosts. - The image runs
flockmcpdas the usernobody. A mounted file keeps its owner and mode from the host, so the configuration file must be readable by others (mode 0644), orflockmcpdexits with code 78. Otherwise run the container with--userset to a user that can read it. - To reach a
flockdon the same host, the container can share the host's network with--network host. Then-pis ignored andflockmcpdbinds the host's own addresses, so this is the one case wherebind_ip_addris::1, or it serves on every interface the host has. - The image sets no
RUST_LOG, sodocker logs flockmcpdholds warnings only. Pass-e RUST_LOG=infofor more, such as the line naming the address it serves on.
Stopping
flockmcpd exits on SIGTERM or SIGINT without waiting for the assistants connected to it, so systemctl stop and docker stop take effect at once.
Logging
flockmcpd logs to its standard error, at the level RUST_LOG sets. If RUST_LOG is not set, warn and above are logged, so the warnings above are seen.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Stopped by SIGTERM or SIGINT. |
| 1 | Any other failure to start. The reason is on standard error. |
| 2 | An option it does not take. |
| 69 | The address could not be bound, most often because another program is using the port. No other failure exits with 69. |
| 78 | The configuration file is missing or refused. The reason is on standard error. |