[Bug]: a refused tray-socket connection stops the server, so `sudo mcpproxy --system <cmd>` always fails on packaged Linux installs
What happened?
On a fresh packaged install (dnf install mcpproxy, Fedora), every sudo mcpproxy --system <cmd> stops the running service, and the command then fails with:
Error: --system: the mcpproxy service is not reachable at 127.0.0.1:8080.
Start it first: sudo systemctl start mcpproxy
The service was running. As root, the CLI first tries the tray socket /var/lib/mcpproxy/mcpproxy.sock. The socket refuses uid 0 as intended (per #1800 and the installation guide), but the refusal makes the server exit. systemd restarts it about 5 seconds later, so the CLI's HTTP fallback finds nothing listening. The documented sudo mcpproxy --system status and sudo mcpproxy --system doctor therefore never work on a packaged install.
It isn't specific to root or --system: any connection to the socket from a UID other than the server's own stops mcpproxy serve. On the packaged layout (/var/lib/mcpproxy is 0700, the socket is 0600), in practice only root can reach the socket.
Cause:
unixListener.Accept(internal/server/listener_unix.go) closes a peer with the wrong UID and then returnsconnection from different user (uid=…, expected=…)as an error.multiplexListener.acceptLoop(internal/server/listener_mux.go) treats anyAccepterror as fatal: it sends it toerrCh,http.Server.Servereturns it, andserveexits withServer failed, shutting down.- Both behaviours date from the original socket implementation (a9e8869a, v0.9.17). #1800 made them easy to hit by having the CLI expect the refusal.
Expected behavior
The server rejects the foreign peer, logs it, and keeps serving. sudo mcpproxy --system status falls back to HTTP and prints the status, as the installation guide describes.
Steps to reproduce
sudo dnf config-manager --add-repo https://rpm.mcpproxy.app/mcpproxy.repo && sudo dnf install -y mcpproxy. The service starts automatically asmcpproxy.sudo mcpproxy --system status- The command reports the service as not reachable.
journalctl -u mcpproxyshows the server exiting and systemd restarting it, andsystemctl show mcpproxy -p NRestartsgoes up by one per attempt.
Repro without root or the package, using a user namespace for a foreign UID:
d=$(mktemp -d); s=$d/mcpproxy.sock
echo '{"listen":"127.0.0.1:18431","data_dir":"'$d'","api_key":"0123456789abcdef0123456789abcdef","mcpServers":[]}' > $d/mcp_config.json
mcpproxy serve --config $d/mcp_config.json --data-dir $d --tray-endpoint unix://$s & sleep 3
chmod 0711 $d; chmod 0666 $s # let the foreign UID reach the socket file
unshare --map-auto --map-root-user setpriv --reuid=1 --regid=1 --clear-groups socat -u /dev/null UNIX-CONNECT:$s
sleep 1; curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:18431/healthz # 000: serve has exited
MCPProxy version
v0.76.0 (personal) linux/amd64
Operating system
Linux
Relevant logs
# journalctl -u mcpproxy — fresh install, four `sudo mcpproxy --system …` attempts, four restarts
Dec 02 11:54:54 triton systemd[1]: Started mcpproxy.service - MCPProxy - Smart proxy for AI agents using Model Context Protocol.
Dec 02 11:55:23 triton mcpproxy[1242129]: WARN server/listener_mux.go:81 Rejected connection from different user {"peer_uid": 0, "expected_uid": 964}
Dec 02 11:55:23 triton mcpproxy[1242129]: ERROR [email protected]/command.go:1015 Server failed, shutting down {"error": "MCP Streamable HTTP server error: connection from different user (uid=0, expected=964)"}
Dec 02 11:55:23 triton systemd[1]: mcpproxy.service: Main process exited, code=exited, status=1/FAILURE
Dec 02 11:55:28 triton systemd[1]: mcpproxy.service: Scheduled restart job, restart counter is at 1.
...
Dec 02 11:59:02 triton mcpproxy[1243174]: WARN server/listener_mux.go:81 Rejected connection from different user {"peer_uid": 0, "expected_uid": 964}
Dec 02 11:59:02 triton mcpproxy[1243174]: ERROR runtime/asm_amd64.s:1771 Listener accept error {"error": "connection from different user (uid=0, expected=964)", "source": "tray", "address": "/var/lib/mcpproxy/mcpproxy.sock"}
Dec 02 11:59:02 triton mcpproxy[1243174]: ERROR [email protected]/command.go:1015 Server failed, shutting down {"error": "MCP Streamable HTTP server error: connection from different user (uid=0, expected=964)"}
Dec 02 11:59:02 triton systemd[1]: mcpproxy.service: Main process exited, code=exited, status=1/FAILURE
Dec 02 11:59:07 triton systemd[1]: mcpproxy.service: Scheduled restart job, restart counter is at 4.
Suggested fix
In unixListener.Accept, close and log a connection that fails peer verification (wrong UID, or missing peer credentials or file descriptor), then keep accepting. Return only errors from the underlying listener. Who may connect stays the same. I have a patch with a regression test and can open a PR if that approach works for you.
Workaround until fixed: read the key with sudo jq -r .api_key /etc/mcpproxy/mcp_config.json, or run commands as the service user: sudo -u mcpproxy mcpproxy --config /etc/mcpproxy/mcp_config.json --data-dir /var/lib/mcpproxy <cmd>.
Pre-submission checklist
- [x] I searched existing issues and did not find a duplicate
- [ ] I ran
mcpproxy doctorand reviewed the output (sudo mcpproxy --system doctorhits the same crash)
Thanks a lot @ben-foxmoore for the detailed report and the user-namespace repro. It made this easy to pin down.
Contributions are always welcome, and you're free to send a PR any time. Since I already had a fix ready, I opened #2130. It follows the approach you suggested: refuse the peer, log it, and keep accepting. It also includes a small related fix: peer credentials are now read through SyscallConn().Control instead of File().Fd(), which had been switching tray connections into blocking mode.
If you have some spare time, a review of #2130 would be very welcome. Please also compare it with your patch: if your regression test or approach covers something mine misses, point it out or push it, and we'll fold it in.