fix mcp-path registration, relative remote teardown, reuse existing remote listener

This commit is contained in:
Luxferre
2026-09-15 10:30:28 +03:00
parent a8f3767b90
commit 936dad0ea7
3 changed files with 46 additions and 10 deletions
+3 -3
View File
@@ -126,14 +126,14 @@ The `--daemon` option is a negatable boolean and defaults to on. `--verbose` and
gsproxy has four moving parts: the remote bring-up, the local client, the monitor, and the gateway.
- Remote bring-up downloads a gs-netcat build with `curl`, unpacks it, and runs a gs-netcat listener with `-lSD -s SECRET`. The listening process is renamed to `python` so it blends into the host.
- Remote bring-up first checks for a listener already running with the same secret and reuses it; only when none is found does it download a gs-netcat build with `curl`, unpack it, and run a gs-netcat listener with `-lSD -s SECRET`. The listening process is renamed to `python` so it blends into the host.
- The local client runs `gs-netcat -D -p PORT -s SECRET`, which opens a SOCKS listener on `127.0.0.1` at the row's port.
- The monitor performs a full SOCKS5 handshake against each local port, testing a real CONNECT to a probe host and port. A passing handshake marks the proxy alive.
- The gateway accepts SOCKS5 connections on `--bind:--gateway-port` and relays them to the first alive proxy listed in the state file.
### MCP bring-up
The remote call is an MCP JSON-RPC exchange over HTTP. The script sends an `initialize` request, captures the `Mcp-Session-Id` header, sends the `notifications/initialized` notification, then calls `tools/call` with the name `Tools_Shell_Command`. Responses may be plain JSON or server-sent events, so the body is parsed for the last `data:` line before decoding. Requests are retried up to three times on transport failures.
The remote call is an MCP JSON-RPC exchange over HTTP. The script sends an `initialize` request, captures the `Mcp-Session-Id` header, sends the `notifications/initialized` notification, then calls `tools/call` with the name `Tools_Shell_Command`. Responses may be plain JSON or server-sent events, so the body is parsed for the last `data:` line before decoding. Requests are retried up to three times on transport failures. Before downloading, the script probes for an existing listener with the same secret and reuses it when present, so restarts do not stack duplicate gs-netcat processes.
### Monitoring and state
@@ -147,7 +147,7 @@ Without `--gateway-auth` the gateway is a transparent relay. With `--gateway-aut
### Teardown
Stopping the tool cleans up both sides. Locally it scans `/proc` for gs-netcat processes that match the `-D -p PORT` shape and sends them `TERM`. Remotely it runs a shell command over MCP that scans `/proc` for processes whose environment contains `GSOCKET_ARGS=-lSD -s SECRET` and kills them.
Stopping the tool cleans up both sides. Locally it scans `/proc` for gs-netcat processes that match the `-D -p PORT` shape and sends them `TERM`. Remotely it runs a shell command over MCP that scans for processes whose environment contains `GSOCKET_ARGS=-lSD -s SECRET` and kills them. The remote scan uses paths relative to the remote workdir (the default workdir `.` is the host root), so `proc/...` addresses `/proc/...`; absolute paths are avoided because the MCP sandbox rejects them.
## Command reference