Commit 9f9df097 authored by Andrey Filippov's avatar Andrey Filippov

Implementing reverse tunnel to the remote host

parent d8f9cf01
......@@ -151,6 +151,7 @@ If you want MCP to be strictly read-only, consider removing or guarding those `m
## Troubleshooting
- If a dialog field isn’t found, check the exact label in `/mcp/dialog` output.
- If the server doesn’t respond, verify the plugin is running and the port is open.
- MCP startup log line `MCP: local-only (no reverse SSH tunnel detected; see mcp-remote-ssh-tunnel.md)` indicates a reverse tunnel is not running.
## Forward plan (single host → multi-host)
- **Single host first**: keep MCP local and use it to supervise runs and inspect outputs.
......
......@@ -33,10 +33,50 @@ public class McpServer {
McpFsAccess.ensureConfigured();
McpServer instance = new McpServer(owner, port);
instance.start();
if (hasReverseSshTunnel(port)) {
System.out.println("MCP: reverse SSH tunnel detected for port " + port);
} else {
System.out.println("MCP: local-only (no reverse SSH tunnel detected; see mcp-remote-ssh-tunnel.md)");
}
INSTANCE = instance;
return instance;
}
private static boolean hasReverseSshTunnel(int port) {
String needle = "127.0.0.1:" + port + ":127.0.0.1:" + port;
final boolean[] found = new boolean[] { false };
java.lang.ProcessHandle.allProcesses().forEach(handle -> {
if (found[0]) {
return;
}
java.lang.ProcessHandle.Info info = handle.info();
if (!info.command().isPresent()) {
return;
}
String cmd = info.command().orElse("");
if (!cmd.endsWith("ssh")) {
return;
}
String[] args = info.arguments().orElse(new String[0]);
if (args.length == 0) {
return;
}
boolean hasR = false;
boolean hasMatch = false;
for (String arg : args) {
if ("-R".equals(arg)) {
hasR = true;
} else if (arg.contains(needle)) {
hasMatch = true;
}
}
if (hasR && hasMatch) {
found[0] = true;
}
});
return found[0];
}
private McpServer(Eyesis_Correction owner, int port) {
this.owner = owner;
this.port = port;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment