mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Bug]: a refused tray-socket connection stops the server, so `sudo mcpproxy --system <cmd>` always fails on packaged Linux installs

Open ben-foxmoore opened this issue 4 days ago • 1 comments

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 returns connection from different user (uid=…, expected=…) as an error.
  • multiplexListener.acceptLoop (internal/server/listener_mux.go) treats any Accept error as fatal: it sends it to errCh, http.Server.Serve returns it, and serve exits with Server 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

  1. sudo dnf config-manager --add-repo https://rpm.mcpproxy.app/mcpproxy.repo && sudo dnf install -y mcpproxy. The service starts automatically as mcpproxy.
  2. sudo mcpproxy --system status
  3. The command reports the service as not reachable. journalctl -u mcpproxy shows the server exiting and systemd restarting it, and systemctl show mcpproxy -p NRestarts goes 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 doctor and reviewed the output (sudo mcpproxy --system doctor hits the same crash)

ben-foxmoore avatar Dec 02 '26 13:12 ben-foxmoore

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.

Dumbris avatar Dec 03 '26 12:12 Dumbris