mcp-ssh-manager 4.3.5 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/MIGRATION.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Upgrading from 3.8 to 4.0
2
2
 
3
- **4.0 is released, on npm and as a desktop application**; the latest is 4.3.5 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.5)).
3
+ **4.0 is released, on npm and as a desktop application**; the latest is 4.4.0 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.4.0)).
4
4
  The last 3.8 release is 3.8.7, for anyone who pins the 3.8 line.
5
5
 
6
6
  The upgrade path preserves headless npm/CLI use. The application, vault import
@@ -316,10 +316,28 @@ it; the engine never starts one.
316
316
  `SSH_MANAGER_ENV` — the CLI's variable, which 3.8.x's engine never read. A
317
317
  profile that still exports `SSH_MANAGER_ENV` towards a file that no longer
318
318
  exists is skipped with a warning, so the usual discovery (`~/.ssh-manager/.env`,
319
- then the working directory, then your home) applies as it did in 3.8.x. A missing
319
+ then your home, then the install directory) applies. A missing
320
320
  file named by `SSH_ENV_PATH` stays the choice and is reported at startup, in
321
321
  `ssh_list_servers` and in "server not found".
322
322
 
323
+ Up to 4.3.5 the discovery also read the `.env` of the working directory, second
324
+ in the list. That is the project the MCP client was started in, and a server
325
+ entry can carry a command that runs on your machine when it connects
326
+ (`PROXYCOMMAND`, or a `proxy_command` in a TOML), so it is no longer read unless
327
+ it is a file you placed or you say so
328
+ ([GHSA-wxcj-q5hp-wjrw](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-wxcj-q5hp-wjrw)).
329
+ If your servers were in a `.env` next to the project, do one of:
330
+
331
+ - move it to `~/.ssh-manager/.env` (the place `llms-install.md` and the CLI use);
332
+ - name it: `SSH_ENV_PATH=/path/to/.env` in the `env` block of the MCP client;
333
+ - trust the project's file: `SSH_MANAGER_TRUST_PROJECT_ENV=1` in the same block.
334
+ It is read from the environment of the engine only; a `.env` cannot set it.
335
+
336
+ The engine says which file it left unread: in the log at startup, in
337
+ `ssh_list_servers` and in "server not found". The `.env` of the install
338
+ directory, which is what runs from a checkout read, and your home's, are read
339
+ as before.
340
+
323
341
  ## Rolling back to 3.8.7
324
342
 
325
343
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "4.3.5",
3
+ "version": "4.4.0",
4
4
  "mcpName": "io.github.bvisible/mcp-ssh-manager",
5
5
  "description": "MCP server for SSH: let AI agents (Claude Code, Codex, any MCP client) run commands, transfer files and manage servers over SSH, with human approval, an encrypted vault and a live audit trail.",
6
6
  "main": "src/index.js",
@@ -14,7 +14,7 @@
14
14
  "setup": "npm install && pip install -r tools/requirements.txt",
15
15
  "configure": "python tools/server-manager.py",
16
16
  "test-connection": "python tools/test-connection.py",
17
- "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:vault && npm run test:recovery && npm run test:upgrade && npm run test:notify && npm run test:commands && npm run test:commandlog && npm run test:portability && npm run test:approval && npm run test:controlplane && npm run test:terminal && npm run test:files && npm run test:livestream && npm run test:livefailure && npm run test:transferpaths && npm run test:skills && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:shellsegments && npm run test:policynames && npm run test:auditsuccess && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:agentkey && npm run test:certpath && npm run test:agentannounce && npm run test:autherrors && npm run test:envchoice && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:quoteprops && npm run test:backupinjection && npm run test:dbrowcount && npm run test:dbclientcmds && npm run test:migration && npm run test:security && npm run test:hostkeys && npm run test:proxy && npm run test:working-directory && npm run test:groups-persistence && npm run test:release && npm run test:cli-experience && npm run test:desktop-install && npm run test:agent-clients && npm run test:appupdate && npm run test:preview && npm run test:desktop-smoke && npm run test:local-shell && npm run test:cli-edit && npm run test:timeoutwrap && npm run test:downloadstats && npm run test:remotetunnel && npm run test:connsharing && npm run test:auditcoverage && npm run test:background && npm run test:quietstderr && npm run test:sshguard && npm run test:locale && npm run test:langtool && npm run test:healthdisks && npm run test:backupintegrity && npm run test:clienvlines && npm run test:clicodex",
17
+ "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:vault && npm run test:recovery && npm run test:upgrade && npm run test:notify && npm run test:commands && npm run test:commandlog && npm run test:portability && npm run test:approval && npm run test:controlplane && npm run test:terminal && npm run test:files && npm run test:livestream && npm run test:livefailure && npm run test:transferpaths && npm run test:skills && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:shellsegments && npm run test:policynames && npm run test:auditsuccess && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:agentkey && npm run test:certpath && npm run test:agentannounce && npm run test:autherrors && npm run test:envchoice && npm run test:projectenv && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:quoteprops && npm run test:backupinjection && npm run test:dbrowcount && npm run test:dbclientcmds && npm run test:migration && npm run test:security && npm run test:hostkeys && npm run test:proxy && npm run test:working-directory && npm run test:groups-persistence && npm run test:release && npm run test:cli-experience && npm run test:desktop-install && npm run test:agent-clients && npm run test:appupdate && npm run test:preview && npm run test:desktop-smoke && npm run test:local-shell && npm run test:windowclose && npm run test:cli-edit && npm run test:timeoutwrap && npm run test:downloadstats && npm run test:remotetunnel && npm run test:connsharing && npm run test:auditcoverage && npm run test:background && npm run test:quietstderr && npm run test:sshguard && npm run test:locale && npm run test:langtool && npm run test:healthdisks && npm run test:backupintegrity && npm run test:clienvlines && npm run test:clicodex",
18
18
  "test:lockfile": "node tests/test-lockfile.js",
19
19
  "test:sudostdin": "node tests/test-sudo-stdin.js",
20
20
  "test:vault": "node tests/test-secret-store.js",
@@ -42,6 +42,7 @@
42
42
  "test:agentannounce": "node tests/test-agent-announce.js",
43
43
  "test:autherrors": "node tests/test-auth-errors.js",
44
44
  "test:envchoice": "node tests/test-env-file-choice.js",
45
+ "test:projectenv": "node tests/test-project-env-trust.js",
45
46
  "test:lifecycle": "node tests/test-lifecycle.js",
46
47
  "test:tunnel": "node tests/test-tunnel-listen.js",
47
48
  "test:sync": "node tests/test-sync-stats.js",
@@ -93,6 +94,7 @@
93
94
  "test:preview": "node tests/test-preview-candidate.js",
94
95
  "test:desktop-smoke": "node tests/test-desktop-smoke.js",
95
96
  "test:local-shell": "node tests/test-local-shell.js",
97
+ "test:windowclose": "node tests/test-window-close.js",
96
98
  "test:policynames": "node tests/test-policy-name-resolution.js",
97
99
  "test:locale": "node tests/test-locale.js",
98
100
  "test:langtool": "node tests/test-language-tool.js",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/bvisible/mcp-ssh-manager",
7
7
  "source": "github"
8
8
  },
9
- "version": "4.3.5",
9
+ "version": "4.4.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "4.3.5",
14
+ "version": "4.4.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -31,6 +31,33 @@ export function expandHomePath(value) {
31
31
  return text;
32
32
  }
33
33
 
34
+ /** @param {unknown} value */
35
+ function isOn(value) {
36
+ return /^(1|true|yes|on)$/i.test(String(value ?? '').trim());
37
+ }
38
+
39
+ /**
40
+ * True when both names lead to the same file, links followed. A file that does
41
+ * not exist is the same as nothing.
42
+ * @param {string} first
43
+ * @param {string} second
44
+ */
45
+ function sameFile(first, second) {
46
+ try { return fs.realpathSync(first) === fs.realpathSync(second); } catch { return false; }
47
+ }
48
+
49
+ /**
50
+ * True when a .env sets up the SSH manager: a server, or a TOML to read. Any
51
+ * repository has a .env of its own, so only one that does is worth a word.
52
+ * @param {string} file
53
+ */
54
+ function configuresServers(file) {
55
+ try {
56
+ return Object.keys(dotenv.parse(fs.readFileSync(file)))
57
+ .some(key => key === 'SSH_CONFIG_PATH' || /^SSH_SERVER_[A-Z0-9_]+_HOST$/.test(key));
58
+ } catch { return false; }
59
+ }
60
+
34
61
  /**
35
62
  * Which .env the engine reads, and why.
36
63
  *
@@ -45,32 +72,60 @@ export function expandHomePath(value) {
45
72
  * the variable, and reported in `ignored`. SSH_ENV_PATH was always the
46
73
  * engine's own override: a missing file there stays the choice, reported as
47
74
  * `missing`, so nothing is silently read in place of what was asked for.
75
+ *
76
+ * The `.env` of the working directory is the one file in the list that nobody
77
+ * chose: it belongs to whatever project the MCP client was started in. A
78
+ * server entry can carry a command that runs on this machine when it connects
79
+ * (PROXYCOMMAND, or one in the TOML that SSH_CONFIG_PATH points to), so a
80
+ * repository that ships a `.env` could make the engine run its commands, with
81
+ * no SSH host and no approval involved. That file is therefore read only when
82
+ * it is also the file the user placed (the manager home, the home directory or
83
+ * the install directory, which is the case when the engine runs from a
84
+ * checkout), or when the process environment says SSH_MANAGER_TRUST_PROJECT_ENV.
85
+ * It is never read from a file: the project's own `.env` cannot vouch for itself.
86
+ * Otherwise it is left unread and named in `skippedProject`, and where a file is
87
+ * wanted but none exists the manager home is used, so that a `.env` an agent
88
+ * writes into the project later is not picked up by a running engine either.
48
89
  * @param {{ projectRoot?: string }} [options]
49
90
  * @returns {{path: string, variable: string|null, missing: boolean,
50
- * ignored: {variable: string, path: string}|null}}
91
+ * ignored: {variable: string, path: string}|null, skippedProject: string|null}}
51
92
  */
52
93
  export function envFileChoice({
53
94
  projectRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
54
95
  } = {}) {
55
96
  if (process.env.SSH_ENV_PATH) {
56
97
  const file = process.env.SSH_ENV_PATH;
57
- return { path: file, variable: 'SSH_ENV_PATH', missing: !fs.existsSync(file), ignored: null };
98
+ return { path: file, variable: 'SSH_ENV_PATH', missing: !fs.existsSync(file), ignored: null, skippedProject: null };
58
99
  }
59
100
  let ignored = null;
60
101
  if (process.env.SSH_MANAGER_ENV) {
61
102
  const file = process.env.SSH_MANAGER_ENV;
62
- if (fs.existsSync(file)) return { path: file, variable: 'SSH_MANAGER_ENV', missing: false, ignored: null };
103
+ if (fs.existsSync(file)) {
104
+ return { path: file, variable: 'SSH_MANAGER_ENV', missing: false, ignored: null, skippedProject: null };
105
+ }
63
106
  ignored = { variable: 'SSH_MANAGER_ENV', path: file };
64
107
  }
65
- const candidates = [
66
- path.join(managerHome(), '.env'),
67
- path.join(process.cwd(), '.env'),
68
- path.join(os.homedir(), '.env'),
69
- path.join(projectRoot, '.env'),
70
- ];
108
+ const managerEnv = path.join(managerHome(), '.env');
109
+ const homeEnv = path.join(os.homedir(), '.env');
110
+ const installEnv = path.join(projectRoot, '.env');
111
+ const projectEnv = path.join(process.cwd(), '.env');
112
+ const trustProject = isOn(process.env.SSH_MANAGER_TRUST_PROJECT_ENV)
113
+ || [managerEnv, homeEnv, installEnv].some(file => sameFile(file, projectEnv));
114
+ const candidates = [managerEnv, ...(trustProject ? [projectEnv] : []), homeEnv, installEnv];
71
115
  const found = candidates.find(candidate => fs.existsSync(candidate));
116
+ // Said only when it would have been read before: with a file in the manager home
117
+ // the project's was never looked at, and a project .env that sets up no server
118
+ // (most of them) has nothing to be missed.
119
+ const skippedProject = !trustProject && !fs.existsSync(managerEnv) && configuresServers(projectEnv)
120
+ ? projectEnv : null;
72
121
  // No file at all is a valid setup (servers from the environment or TOML).
73
- return { path: found || path.join(process.cwd(), '.env'), variable: null, missing: false, ignored };
122
+ return {
123
+ path: found || (trustProject ? projectEnv : managerEnv),
124
+ variable: null,
125
+ missing: false,
126
+ ignored,
127
+ skippedProject
128
+ };
74
129
  }
75
130
 
76
131
  /**
@@ -92,10 +147,26 @@ export function envFileProblem(choice) {
92
147
  if (choice.missing) {
93
148
  return `${choice.variable} names ${choice.path}, which does not exist: no server is loaded from a .env file`;
94
149
  }
150
+ const problems = [];
95
151
  if (choice.ignored) {
96
- return `${choice.ignored.variable} names ${choice.ignored.path}, which does not exist; using ${choice.path} instead`;
152
+ problems.push(`${choice.ignored.variable} names ${choice.ignored.path}, which does not exist; using ${choice.path} instead`);
97
153
  }
98
- return null;
154
+ if (choice.skippedProject) {
155
+ problems.push(projectEnvNotice(choice.skippedProject));
156
+ }
157
+ return problems.length ? problems.join('; ') : null;
158
+ }
159
+
160
+ /**
161
+ * What to tell the operator when the .env of the working directory was left
162
+ * unread, and the three ways to have it read.
163
+ * @param {string} file
164
+ * @returns {string}
165
+ */
166
+ export function projectEnvNotice(file) {
167
+ return `${file} was not read: a project file is not trusted to start commands on this machine. `
168
+ + `Move it to ${path.join(managerHome(), '.env')}, name it with SSH_ENV_PATH, `
169
+ + 'or set SSH_MANAGER_TRUST_PROJECT_ENV=1 in the environment of the MCP server';
99
170
  }
100
171
 
101
172
  /** Read file-selected TOML settings just as the MCP entry point does.
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ import path from 'path';
13
13
  import crypto from 'node:crypto';
14
14
  import { AsyncLocalStorage } from 'node:async_hooks';
15
15
  import { isDeepStrictEqual } from 'node:util';
16
- import { envFileChoice, envFileProblem, expandHomePath } from './config-paths.js';
16
+ import { envFileChoice, envFileProblem, expandHomePath, projectEnvNotice } from './config-paths.js';
17
17
  import { fileURLToPath } from 'url';
18
18
  import { ServerConfigManager } from './server-config-manager.js';
19
19
  import {
@@ -272,7 +272,8 @@ async function getServerConfig(serverName) {
272
272
  const servers = await loadServerConfig();
273
273
  const name = serverName && resolveServerName(String(serverName), servers);
274
274
  if (!name) {
275
- throw new Error(`Server "${serverName}" not found${envProblem && !Object.keys(servers).length ? ` (${envProblem})` : ''}`);
275
+ // A project .env left unread is named even when other servers loaded: the one asked for may be in it.
276
+ throw new Error(`Server "${serverName}" not found${envProblem && (!Object.keys(servers).length || envChoice.skippedProject) ? ` (${envProblem})` : ''}`);
276
277
  }
277
278
  return servers[name];
278
279
  }
@@ -2419,6 +2420,7 @@ registerToolConditional(
2419
2420
  ];
2420
2421
  // The list stays the first item, unchanged, for anything that parses it.
2421
2422
  if (envProblem && !serverInfo.length) content.push({ type: 'text', text: `No server loaded: ${envProblem}.` });
2423
+ else if (envChoice.skippedProject) content.push({ type: 'text', text: `Note: ${projectEnvNotice(envChoice.skippedProject)}.` });
2422
2424
  return { content };
2423
2425
  }
2424
2426
  );