mcp-ssh-manager 4.1.0 → 4.3.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/CLAUDE.md +3 -5
  3. package/Formula/ssh-manager.rb +2 -2
  4. package/INSTALLATION.md +4 -0
  5. package/README.md +31 -5
  6. package/cli/codex.js +67 -0
  7. package/cli/guard.js +69 -0
  8. package/cli/lib/config.sh +102 -37
  9. package/cli/ssh-manager +13 -0
  10. package/cli/ssh-manager.js +1 -1
  11. package/desktop/electron/electron-builder.yml +5 -0
  12. package/desktop/electron/locale.mjs +55 -0
  13. package/desktop/electron/main.js +52 -65
  14. package/desktop/electron/native-menu.mjs +44 -0
  15. package/desktop/electron/native.fr.json +58 -0
  16. package/desktop/electron/native.ja.json +58 -0
  17. package/desktop/electron/native.zh-CN.json +58 -0
  18. package/desktop/electron/package-lock.json +2 -2
  19. package/desktop/electron/package.json +1 -1
  20. package/desktop/electron/smoke-test.mjs +15 -1
  21. package/dist/ui/app.css +1 -1
  22. package/dist/ui/app.js +135 -119
  23. package/docs/MIGRATION.md +1 -1
  24. package/docs/SECURITY_MODES.md +15 -8
  25. package/docs/SEO.md +1 -1
  26. package/package.json +17 -3
  27. package/scripts/language.mjs +172 -0
  28. package/scripts/test-upgrade-from-published.mjs +24 -2
  29. package/server.json +2 -2
  30. package/src/audit.js +6 -15
  31. package/src/background-job.js +44 -0
  32. package/src/backup-manager.js +24 -29
  33. package/src/config-loader.js +5 -1
  34. package/src/control-plane.js +5 -0
  35. package/src/database-manager.js +13 -31
  36. package/src/dump-guard.js +79 -0
  37. package/src/health-monitor.js +8 -4
  38. package/src/index.js +183 -21
  39. package/src/logger.js +3 -1
  40. package/src/quiet-stderr.js +15 -0
  41. package/src/ssh-guard.js +344 -0
  42. package/src/ssh-manager.js +51 -0
  43. package/src/tunnel-manager.js +14 -4
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.1.0 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.1.0)).
3
+ **4.0 is released, on npm and as a desktop application**; the latest is 4.3.0 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.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
@@ -87,22 +87,29 @@ parity with the `.env` form.
87
87
  ## Audit log
88
88
 
89
89
  When `AUDIT_LOG` (`.env`) or `audit_log` (TOML) is set to a file path, every
90
- **gated** tool invocation appends a JSONL record:
90
+ tool that targets the server appends a JSONL record of what happened: the
91
+ outcome of each one that ran, and the reason for each one that was refused.
91
92
 
92
93
  ```json
93
94
  {"ts":"2026-05-18T15:30:00.123Z","server":"prod","tool":"ssh_execute","args":{"command":"ls /tmp"},"allowed":true,"exitCode":0,"success":true}
94
95
  {"ts":"2026-05-18T15:30:14.789Z","server":"prod","tool":"ssh_execute","args":{"command":"rm /tmp/x"},"allowed":false,"reason":"Command refused on server \"prod\" (mode: readonly): matches built-in destructive pattern /(^|[\\s;&|])rm(\\s|$)/."}
96
+ {"ts":"2026-05-18T15:31:02.004Z","server":"prod","tool":"ssh_tail","args":{"file":"/var/log/app.log","lines":5,"follow":false},"allowed":true,"success":true}
95
97
  ```
96
98
 
97
- Secrets (`password`, `passphrase`, `sudoPassword`, `token`, `secret`, `apikey`)
98
- are redacted to `***` before being written, even if a tool somehow passed them
99
- through args.
99
+ - A tool that knows its exit code (`ssh_execute`, `ssh_execute_sudo`, `ssh_upload`,
100
+ `ssh_download`, group and session commands) records `exitCode` and `success`;
101
+ every other tool records `success`, with `error` when it failed.
102
+ - Tools that only read or edit local state (`ssh_list_servers`, aliases, tunnel
103
+ lists, `ssh_history`…) leave no line: nothing reached a server.
104
+ - A value whose key looks like a secret (`password`, `dbPassword`, `passphrase`,
105
+ `sudoPassword`, `token`, `secret`, `apiKey`, `credential`, `privateKey`…) is
106
+ replaced by `***` before it is written, and in the approval request too.
107
+ - Before 4.2.0 only `ssh_execute` and `ssh_upload` (and, from 4.1.0, sudo,
108
+ downloads, group and session commands) recorded their outcome; a refusal was
109
+ recorded for every tool.
100
110
 
101
111
  Log rotation is not handled by `mcp-ssh-manager` — use `logrotate`, `vector`,
102
- or your log shipper of choice. v3.5.0 audits cover the gated tool set:
103
- `ssh_execute`, `ssh_upload`, `ssh_execute_sudo`, plus denials on every other
104
- mutating tool. Pure read tools (`ssh_health_check`, `ssh_db_query`, `ssh_tail`…)
105
- are not audited in v3.5.0 — open an issue if you need full coverage.
112
+ or your log shipper of choice.
106
113
 
107
114
  ## Recipes
108
115
 
package/docs/SEO.md CHANGED
@@ -57,7 +57,7 @@ Once installed, simply ask Claude Code:
57
57
 
58
58
  ```bash
59
59
  ssh-manager codex setup
60
- ssh-manager codex migrate
60
+ ssh-manager export servers.toml
61
61
  ```
62
62
 
63
63
  Configure in `~/.codex/config.toml`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "4.1.0",
3
+ "version": "4.3.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: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: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",
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: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: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",
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",
@@ -50,6 +50,13 @@
50
50
  "test:dbrowcount": "node tests/test-database-row-count.js",
51
51
  "test:dbclientcmds": "node tests/test-db-client-commands.js",
52
52
  "test:timeoutwrap": "node tests/test-timeout-wrapper.js",
53
+ "test:remotetunnel": "node tests/test-remote-tunnel.js",
54
+ "test:connsharing": "node tests/test-connection-sharing.js",
55
+ "test:auditcoverage": "node tests/test-audit-coverage.js",
56
+ "test:background": "node tests/test-background-job.js",
57
+ "test:quietstderr": "node tests/test-quiet-stderr.js",
58
+ "test:sshguard": "node tests/test-ssh-guard.js",
59
+ "test:downloadstats": "node tests/test-download-stats.js",
53
60
  "test:cli-edit": "node tests/test-cli-edit-server.js",
54
61
  "test:all": "npm test && npm run typecheck && ./scripts/validate.sh",
55
62
  "validate": "./scripts/validate.sh",
@@ -83,7 +90,14 @@
83
90
  "test:preview": "node tests/test-preview-candidate.js",
84
91
  "test:desktop-smoke": "node tests/test-desktop-smoke.js",
85
92
  "test:local-shell": "node tests/test-local-shell.js",
86
- "test:policynames": "node tests/test-policy-name-resolution.js"
93
+ "test:policynames": "node tests/test-policy-name-resolution.js",
94
+ "test:locale": "node tests/test-locale.js",
95
+ "test:langtool": "node tests/test-language-tool.js",
96
+ "lang": "node scripts/language.mjs",
97
+ "test:healthdisks": "node tests/test-health-disks.js",
98
+ "test:backupintegrity": "node tests/test-backup-integrity.js",
99
+ "test:clienvlines": "node tests/test-cli-env-lines.js",
100
+ "test:clicodex": "node tests/test-cli-codex.js"
87
101
  },
88
102
  "keywords": [
89
103
  "mcp",
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env node
2
+ // Languages of the interface and of the desktop application.
3
+ //
4
+ // npm run lang -- add <code> [--name "Français"] [--label "Langue"]
5
+ // Creates the three catalogues of a new language from the English text and,
6
+ // when the Windows installer has a page for it, lists that page too.
7
+ // npm run lang -- status
8
+ // Shows, per language, how many entries are still the English text.
9
+ //
10
+ // A language is three files, and nothing else names it: the interface and the desktop
11
+ // application find them by their names (ui/README.md, "Adding a language").
12
+ // ui/src/locales/<code>.json labels of the carried-over components, plus language.name / language.label
13
+ // ui/src/locales/messages.<code>.json the interface's sentences (keys are the English sentences)
14
+ // desktop/electron/native.<code>.json menus, tray and notifications of the desktop application
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+
19
+ const repository = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
20
+
21
+ /**
22
+ * The page of the Windows installer for a language, by the code the installer's
23
+ * builder uses. A language that is not here still gets its catalogues; it only has no
24
+ * page of its own in the installer, which then shows its own languages' pages.
25
+ */
26
+ const INSTALLER_LOCALES = {
27
+ cs: 'cs_CZ', da: 'da_DK', de: 'de_DE', el: 'el_GR', es: 'es_ES', fi: 'fi_FI',fr: 'fr_FR', hu: 'hu_HU',
28
+ it: 'it_IT', ja: 'ja_JP', ko: 'ko_KR', nb: 'nb_NO', nl: 'nl_NL', pl: 'pl_PL', 'pt-BR': 'pt_BR', pt: 'pt_PT',
29
+ ro: 'ro_RO', ru: 'ru_RU', sv: 'sv_SE', tr: 'tr_TR', uk: 'uk_UA', vi: 'vi_VN', 'zh-CN': 'zh_CN', 'zh-TW': 'zh_TW',
30
+ };
31
+
32
+ /** The installer page code for a language code, or undefined when none is known. */
33
+ export function installerLocaleFor(code) {
34
+ return INSTALLER_LOCALES[code] ?? INSTALLER_LOCALES[code.split('-')[0]];
35
+ }
36
+
37
+ /** Language, optional script, optional region: `fr`, `pt-BR`, `zh-Hant-TW`, `es-419`. */
38
+ const CODE = /^[a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}|[0-9]{3}))?$/;
39
+
40
+ const files = root => ({
41
+ locales: path.join(root, 'ui', 'src', 'locales'),
42
+ electron: path.join(root, 'desktop', 'electron'),
43
+ builder: path.join(root, 'desktop', 'electron', 'electron-builder.yml'),
44
+ });
45
+
46
+ /** Codes found in a folder from file names like `<prefix><code>.json`. */
47
+ function discover(folder, prefix) {
48
+ const pattern = new RegExp(`^${prefix}([A-Za-z0-9-]+)\\.json$`);
49
+ return fs.readdirSync(folder).map(name => pattern.exec(name)?.[1]).filter(Boolean).sort();
50
+ }
51
+
52
+ const readJson = file => JSON.parse(fs.readFileSync(file, 'utf8'));
53
+ /** `flag: 'wx'` creates the file and fails if it exists, in one step. */
54
+ const writeJson = (file, data, flag = 'w') => fs.writeFileSync(file, JSON.stringify(data, null, 2) + '\n', { flag });
55
+ /** The file's text, or undefined when it is not there: one read, so nothing can change between a check and the use. */
56
+ function readIfPresent(file) {
57
+ try { return fs.readFileSync(file, 'utf8'); } catch (error) { if (error.code === 'ENOENT') return undefined; throw error; }
58
+ }
59
+ const flatten = (object, prefix = '') => Object.entries(object)
60
+ .flatMap(([key, value]) => (value && typeof value === 'object' ? flatten(value, `${prefix}${key}.`) : [[`${prefix}${key}`, value]]));
61
+
62
+ /** The language written in itself ("fr" → "Français"), or the code when the platform has no name for it. */
63
+ function ownName(code) {
64
+ try {
65
+ const name = new Intl.DisplayNames([code], { type: 'language' }).of(code);
66
+ return name && name !== code ? name.charAt(0).toLocaleUpperCase(code) + name.slice(1) : code;
67
+ } catch { return code; }
68
+ }
69
+
70
+ /**
71
+ * Create the three catalogues of a new language, every value being the English text to
72
+ * translate. Returns what was written. Refuses a bad code, English, and a language that exists.
73
+ */
74
+ export function addLanguage(root, code, { name, label } = {}) {
75
+ const where = files(root);
76
+ if (code === 'en') throw new Error('English is the source language: it cannot be added');
77
+ const same = discover(where.locales, '').find(known => known.toLowerCase() === code.toLowerCase());
78
+ if (same) throw new Error(`the language ${same} already exists`);
79
+ if (!CODE.test(code)) throw new Error(`"${code}" is not a language code like fr, pt-BR or zh-Hant-TW`);
80
+
81
+ const english = readJson(path.join(where.locales, 'en.json'));
82
+ const sentences = readJson(path.join(where.locales, 'messages.en.json'));
83
+ const reference = discover(where.electron, 'native\\.')[0];
84
+ if (!reference) throw new Error('no desktop catalogue to take the menu sentences from');
85
+ const native = Object.fromEntries(Object.keys(readJson(path.join(where.electron, `native.${reference}.json`))).map(key => [key, key]));
86
+
87
+ const written = [
88
+ [path.join(where.locales, `${code}.json`), { ...english, language: { name: name || ownName(code), label: label || english.language?.label || 'Language' } }],
89
+ [path.join(where.locales, `messages.${code}.json`), sentences],
90
+ [path.join(where.electron, `native.${code}.json`), native],
91
+ ];
92
+ for (const [file, content] of written) writeJson(file, content, 'wx');
93
+
94
+ const installer = installerLocaleFor(code);
95
+ let installerAdded = false;
96
+ const text = installer ? readIfPresent(where.builder) : undefined;
97
+ if (text !== undefined) {
98
+ const line = /^(\s*installerLanguages:\s*\[)([^\]]*)(\])/m.exec(text);
99
+ if (line) {
100
+ const pages = line[2].split(',').map(page => page.trim()).filter(Boolean);
101
+ if (!pages.includes(installer)) {
102
+ fs.writeFileSync(where.builder, text.replace(line[0], `${line[1]}${[...pages, installer].join(', ')}${line[3]}`));
103
+ installerAdded = true;
104
+ }
105
+ }
106
+ }
107
+ return { files: written.map(([file]) => path.relative(root, file)), installer: installerAdded ? installer : undefined, installerKnown: Boolean(installer) };
108
+ }
109
+
110
+ /** Per language: entries (of each catalogue) that are still the English text. */
111
+ export function languageStatus(root) {
112
+ const where = files(root);
113
+ const english = Object.fromEntries(flatten(readJson(path.join(where.locales, 'en.json'))));
114
+ const result = [];
115
+ for (const code of discover(where.locales, '').filter(known => known !== 'en')) {
116
+ const labels = readJson(path.join(where.locales, `${code}.json`));
117
+ const labelEntries = flatten(labels).filter(([key]) => !key.startsWith('language.'));
118
+ const sentences = Object.entries(readJson(path.join(where.locales, `messages.${code}.json`)));
119
+ const nativeText = readIfPresent(path.join(where.electron, `native.${code}.json`));
120
+ const menus = nativeText === undefined ? [] : Object.entries(JSON.parse(nativeText));
121
+ result.push({
122
+ code,
123
+ name: labels.language?.name ?? code,
124
+ labels: { same: labelEntries.filter(([key, value]) => value === english[key]).length, total: labelEntries.length },
125
+ sentences: { same: sentences.filter(([key, value]) => value === key).length, total: sentences.length },
126
+ menus: { same: menus.filter(([key, value]) => value === key).length, total: menus.length },
127
+ });
128
+ }
129
+ return result;
130
+ }
131
+
132
+ function printStatus(rows) {
133
+ const cell = ({ same, total }) => `${same} of ${total}`;
134
+ const head = ['language', 'name', 'labels', 'sentences', 'desktop menus'];
135
+ const lines = [head, ...rows.map(row => [row.code, row.name, cell(row.labels), cell(row.sentences), cell(row.menus)])];
136
+ const widths = head.map((_, column) => Math.max(...lines.map(line => [...line[column]].length)));
137
+ console.log('Entries still identical to the English text (a few are right to be: names, "OK"):');
138
+ for (const line of lines) console.log(line.map((text, column) => text + ' '.repeat(widths[column] - [...text].length)).join(' ').trimEnd());
139
+ }
140
+
141
+ function main(argv) {
142
+ const options = {};
143
+ const rest = [];
144
+ for (let i = 0; i < argv.length; i++) {
145
+ if (['--name', '--label', '--root'].includes(argv[i])) options[argv[i].slice(2)] = argv[++i];
146
+ else rest.push(argv[i]);
147
+ }
148
+ const root = options.root ? path.resolve(options.root) : repository;
149
+ const [command, code] = rest;
150
+ try {
151
+ if (command === 'add' && code) {
152
+ const done = addLanguage(root, code, options);
153
+ console.log(`Added ${code}:`);
154
+ for (const file of done.files) console.log(` ${file}`);
155
+ if (done.installer) console.log(` desktop/electron/electron-builder.yml: installer page ${done.installer}`);
156
+ else if (!done.installerKnown) console.log(' (no Windows installer page known for this language: the catalogues work without one)');
157
+ console.log('\nEvery value starts as the English text. Translate the values; keep the keys of');
158
+ console.log('messages.<code>.json and native.<code>.json as they are, and keep every {{placeholder}}.');
159
+ console.log('Then: npm run test:locale, and npm run lang -- status.');
160
+ } else if (command === 'status') {
161
+ printStatus(languageStatus(root));
162
+ } else {
163
+ console.error('usage: npm run lang -- add <code> [--name "Français"] [--label "Langue"]\n npm run lang -- status');
164
+ process.exitCode = 2;
165
+ }
166
+ } catch (error) {
167
+ console.error(`lang: ${error.message}`);
168
+ process.exitCode = 1;
169
+ }
170
+ }
171
+
172
+ if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) main(process.argv.slice(2));
@@ -21,6 +21,27 @@ const FIELDS = ['name', 'host', 'user', 'password', 'keyPath', 'passphrase', 'po
21
21
  'proxyCommand', 'forwardAgent', 'mode', 'allowPatterns', 'denyPatterns', 'auditLog', 'source'];
22
22
  let passed = 0;
23
23
  const ok = label => console.log(`✓ ${++passed}. ${label}`);
24
+ // Optional input properties a release may ADD to an existing tool. The check
25
+ // below still fails on anything else that differs from the previous release: a
26
+ // removed or renamed property, a changed type or description, a required
27
+ // property that was not there. An old client can trip on those; it cannot on a
28
+ // property it never sends. List an addition here on purpose, with its release.
29
+ const ADDED_OPTIONAL_INPUTS = {
30
+ ssh_execute: ['background'], // 4.2.0
31
+ };
32
+ /** The schemas with the declared additions taken out, each checked to be optional. */
33
+ function withoutDeclaredAdditions(schemas) {
34
+ const copy = structuredClone(schemas);
35
+ for (const [tool, names] of Object.entries(ADDED_OPTIONAL_INPUTS)) {
36
+ for (const name of names) {
37
+ const schema = copy[tool];
38
+ if (!schema?.properties || !(name in schema.properties)) continue;
39
+ assert.ok(!(schema.required || []).includes(name), `${tool}.${name} was added as required: an old client would fail`);
40
+ delete schema.properties[name];
41
+ }
42
+ }
43
+ return copy;
44
+ }
24
45
  const canonical = value => Array.isArray(value) ? value.map(canonical)
25
46
  : value && typeof value === 'object' ? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value;
26
47
 
@@ -210,8 +231,9 @@ async function main() {
210
231
  const after = { protocol: await interrogate(item, path.join(installed, 'src/index.js')), loader: loaderSnapshot(installed, item) };
211
232
  assert.deepEqual(after.loader, before[item.name].loader, `${item.name}: effective ConfigLoader field fingerprints differ`);
212
233
  assert.deepEqual(after.protocol.listing, before[item.name].protocol.listing, `${item.name}: MCP listing changed`);
213
- assert.deepEqual(after.protocol.schemas, before[item.name].protocol.schemas, `${item.name}: MCP tool names or input schemas changed`);
214
- ok(`${item.name}: effective fields, MCP listing and all 37 tool input schemas unchanged`);
234
+ assert.deepEqual(withoutDeclaredAdditions(after.protocol.schemas), withoutDeclaredAdditions(before[item.name].protocol.schemas), `${item.name}: MCP tool names or input schemas changed`);
235
+ const added = Object.entries(ADDED_OPTIONAL_INPUTS).flatMap(([tool, names]) => names.filter(name => after.protocol.schemas[tool]?.properties?.[name] && !before[item.name].protocol.schemas[tool]?.properties?.[name]).map(name => `${tool}.${name}`));
236
+ ok(`${item.name}: effective fields, MCP listing and all 37 tool input schemas unchanged${added.length ? ` (declared optional additions: ${added.join(', ')})` : ''}`);
215
237
  }
216
238
  untouched(scenarios); ok('upgrade leaves original config bytes intact and starts no UI, listener, prompt or vault');
217
239
  installPrevious(); assert.equal(packageVersion(), PREVIOUS);
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.1.0",
9
+ "version": "4.3.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "4.1.0",
14
+ "version": "4.3.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
package/src/audit.js CHANGED
@@ -12,21 +12,12 @@
12
12
 
13
13
  import fs from 'fs';
14
14
  import path from 'path';
15
- import { logger } from './logger.js';
16
-
17
- // Field names whose values should never appear in the audit log even if a tool
18
- // somehow passed them through args. Case-insensitive.
19
- const REDACT_FIELDS = new Set([
20
- 'password',
21
- 'passphrase',
22
- 'sudopassword',
23
- 'sudo_password',
24
- 'token',
25
- 'secret',
26
- 'apikey',
27
- 'api_key',
28
- ]);
15
+ import { logger, SECRET_KEY_PATTERN } from './logger.js';
29
16
 
17
+ // A value whose key looks like a secret never appears in the audit log, even if
18
+ // a tool passed it through args. The rule is the logger's (SECRET_KEY_PATTERN),
19
+ // not a list of exact names: a list missed dbPassword and db_password, so a
20
+ // database password reached the log, and the approval request, in clear text.
30
21
  const REDACTED = '***';
31
22
 
32
23
  /**
@@ -44,7 +35,7 @@ export function sanitize(value) {
44
35
  if (Array.isArray(value)) return value.map(sanitize);
45
36
  const out = {};
46
37
  for (const [k, v] of Object.entries(value)) {
47
- if (REDACT_FIELDS.has(k.toLowerCase())) {
38
+ if (SECRET_KEY_PATTERN.test(k)) {
48
39
  out[k] = REDACTED;
49
40
  } else {
50
41
  out[k] = sanitize(v);
@@ -0,0 +1,44 @@
1
+ // Run a command on the target fully detached from the SSH session, for the jobs
2
+ // that outlive an ssh_execute call (a training run, a long build): the call
3
+ // returns at once with the job's pid and the file its output goes to.
4
+ //
5
+ // Idea from SEU-zhc's fork, built differently on one point: the log file is
6
+ // never chosen by the caller. A free path would let a command that passes the
7
+ // readonly policy (`echo "<key>"`) overwrite any file the SSH user can write,
8
+ // ~/.ssh/authorized_keys included, so the engine creates its own private file
9
+ // with mktemp instead.
10
+ import { shellQuote } from './shell-quote.js';
11
+
12
+ // Run by `sh` with the command as $1, so the command is never spliced into this
13
+ // text. nohup keeps the job past the end of the session; stdout and stderr go to
14
+ // a fresh private file and stdin to /dev/null, so no descriptor of the SSH
15
+ // channel stays open and the call can finish while the job runs on.
16
+ const BACKGROUND_SCRIPT = 'log=$(mktemp "${TMPDIR:-/tmp}/ssh-manager-bg-XXXXXX") || exit 1;'
17
+ + ' nohup sh -c "$1" > "$log" 2>&1 < /dev/null & echo "$! $log"';
18
+
19
+ /**
20
+ * Wrap a command so it starts detached and prints "<pid> <log file>".
21
+ *
22
+ * Like withRemoteTimeout, the result is one simple command made only of
23
+ * single-quoted words: the SSH server hands it to the account's login shell,
24
+ * which may be csh or tcsh and would reject `$(...)` or `if ... fi` at the top
25
+ * level.
26
+ * @param {string} command
27
+ * @returns {string}
28
+ */
29
+ export function buildBackgroundCommand(command) {
30
+ return `sh -c ${shellQuote(BACKGROUND_SCRIPT)} sh ${shellQuote(command)}`;
31
+ }
32
+
33
+ /**
34
+ * Read what buildBackgroundCommand printed.
35
+ * @param {string} stdout
36
+ * @returns {{pid: number, logFile: string} | null} null if the job did not start
37
+ */
38
+ export function parseBackgroundStart(stdout) {
39
+ for (const line of String(stdout ?? '').split('\n').reverse()) {
40
+ const match = /^(\d+) (\/.+)$/.exec(line.trim());
41
+ if (match) return { pid: Number(match[1]), logFile: match[2] };
42
+ }
43
+ return null;
44
+ }
@@ -8,6 +8,7 @@ import path from 'path';
8
8
  import crypto from 'crypto';
9
9
  import { logger } from './logger.js';
10
10
  import { shellQuote, safeInteger } from './shell-quote.js';
11
+ import { guardedDump, guardedFeed, mongoArchivePath } from './dump-guard.js';
11
12
 
12
13
  // Backup types
13
14
  export const BACKUP_TYPES = {
@@ -90,6 +91,18 @@ export function getBackupFilePath(backupId, backupDir = DEFAULT_BACKUP_DIR, exte
90
91
  return path.join(backupDir, `${backupId}${extension}`);
91
92
  }
92
93
 
94
+ /**
95
+ * The extension of the file (or directory) a backup of this kind is stored as.
96
+ * MongoDB is the one that differs: a compressed dump is the archive mongoArchivePath()
97
+ * names, <id>.tar.gz, and an uncompressed one is the dump directory itself.
98
+ * @param {string} type
99
+ * @param {boolean} [compressed]
100
+ */
101
+ export function backupExtension(type, compressed = true) {
102
+ if (type !== BACKUP_TYPES.MONGODB) return '.gz';
103
+ return compressed ? '.tar.gz' : '';
104
+ }
105
+
93
106
  /**
94
107
  * Build MySQL dump command
95
108
  */
@@ -121,13 +134,8 @@ export function buildMySQLDumpCommand(options) {
121
134
  command += ` ${shellQuote(database)}`;
122
135
 
123
136
  // Output handling
124
- if (compress) {
125
- command += ` | gzip > ${shellQuote(outputFile)}`;
126
- } else {
127
- command += ` > ${shellQuote(outputFile)}`;
128
- }
129
-
130
- return command;
137
+ // A producer that fails must fail the whole command and leave no file: see dump-guard.js.
138
+ return guardedDump(command, outputFile, compress);
131
139
  }
132
140
 
133
141
  /**
@@ -164,13 +172,8 @@ export function buildPostgreSQLDumpCommand(options) {
164
172
  command += ` ${shellQuote(database)}`;
165
173
 
166
174
  // Output handling
167
- if (compress) {
168
- command += ` | gzip > ${shellQuote(outputFile)}`;
169
- } else {
170
- command += ` > ${shellQuote(outputFile)}`;
171
- }
172
-
173
- return command;
175
+ // A producer that fails must fail the whole command and leave no file: see dump-guard.js.
176
+ return guardedDump(command, outputFile, compress);
174
177
  }
175
178
 
176
179
  /**
@@ -203,7 +206,7 @@ export function buildMongoDBDumpCommand(options) {
203
206
 
204
207
  // Compress the output directory
205
208
  if (compress) {
206
- const archiveName = `${outputDir}.tar.gz`;
209
+ const archiveName = mongoArchivePath(outputDir);
207
210
  // dirname/basename receive the quoted value, so the substitution itself
208
211
  // cannot be steered by the caller.
209
212
  command += ` && tar -czf ${shellQuote(archiveName)} -C "$(dirname ${shellQuote(outputDir)})" "$(basename ${shellQuote(outputDir)})"`;
@@ -283,14 +286,7 @@ function buildMySQLRestoreCommand(backupFile, options) {
283
286
 
284
287
  let command = '';
285
288
 
286
- // Decompress if needed
287
- if (backupFile.endsWith('.gz')) {
288
- command = `gunzip -c ${shellQuote(backupFile)} | `;
289
- } else {
290
- command = `cat ${shellQuote(backupFile)} | `;
291
- }
292
-
293
- command += 'mysql';
289
+ command = 'mysql';
294
290
 
295
291
  // Connection parameters
296
292
  if (user) command += ` -u${shellQuote(user)}`;
@@ -299,7 +295,9 @@ function buildMySQLRestoreCommand(backupFile, options) {
299
295
  if (port) command += ` -P ${safeInteger(port, 3306)}`;
300
296
  if (database) command += ` ${shellQuote(database)}`;
301
297
 
302
- return command;
298
+ // A gzip file is verified whole before mysql reads a byte of it (dump-guard.js).
299
+ if (backupFile.endsWith('.gz')) return guardedFeed(backupFile, command);
300
+ return `cat ${shellQuote(backupFile)} | ${command}`;
303
301
  }
304
302
 
305
303
  /**
@@ -331,11 +329,8 @@ function buildPostgreSQLRestoreCommand(backupFile, options) {
331
329
  command += ' --clean --if-exists';
332
330
 
333
331
  // Handle compressed files
334
- if (backupFile.endsWith('.gz')) {
335
- command = `gunzip -c ${shellQuote(backupFile)} | ${command}`;
336
- } else {
337
- command += ` ${shellQuote(backupFile)}`;
338
- }
332
+ if (backupFile.endsWith('.gz')) return guardedFeed(backupFile, command);
333
+ command += ` ${shellQuote(backupFile)}`;
339
334
 
340
335
  return command;
341
336
  }
@@ -3,6 +3,7 @@ import TOML from '@iarna/toml';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import os from 'os';
6
+ import { fileURLToPath } from 'url';
6
7
  import { logger } from './logger.js';
7
8
  import { VALID_MODES } from './policy.js';
8
9
  import { SecretStore, defaultVaultPath } from './secret-store.js';
@@ -537,7 +538,10 @@ export class ConfigLoader {
537
538
 
538
539
  config.mcp_servers['ssh-manager'] = {
539
540
  command: 'node',
540
- args: [path.join(process.cwd(), 'src', 'index.js')],
541
+ // This module's own folder, not the working directory: the entry has to name an
542
+ // engine that exists wherever the command is run from (an npm install has no
543
+ // src/ under the current directory).
544
+ args: [path.join(path.dirname(fileURLToPath(import.meta.url)), 'index.js')],
541
545
  env: {
542
546
  SSH_CONFIG_PATH: path.join(os.homedir(), '.codex', 'ssh-config.toml')
543
547
  },
@@ -2325,6 +2325,11 @@ export class ControlPlane {
2325
2325
  localShell: Boolean(this.localShell),
2326
2326
  // Whether /api/desktop exists: true only under `ssh-manager control`.
2327
2327
  offerDesktop: Boolean(this.offerDesktop),
2328
+ // Whether this process can see an SSH agent. A server that names an agent key
2329
+ // (agentPublicKeyPath) needs one; the form says so when there is none. It is
2330
+ // this process's environment, which is the engine's inside the desktop
2331
+ // application and a good hint for an engine started by an AI tool.
2332
+ agentSocket: Boolean(process.env.SSH_AUTH_SOCK),
2328
2333
  });
2329
2334
  }
2330
2335
 
@@ -13,7 +13,8 @@ export const DB_TYPES = {
13
13
  // A single quote character as a constant, so shellQuote()'s escaping stays
14
14
  // readable under the repo's single-quote lint style.
15
15
  import { shellQuote } from './shell-quote.js';
16
- export { shellQuote };
16
+ import { guardedDump, guardedFeed, mongoArchivePath } from './dump-guard.js';
17
+ export { shellQuote, mongoArchivePath };
17
18
 
18
19
  /**
19
20
  * Build MySQL dump command
@@ -44,13 +45,8 @@ export function buildMySQLDumpCommand(options) {
44
45
  command += ` ${tables.map(shellQuote).join(' ')}`;
45
46
  }
46
47
 
47
- if (compress) {
48
- command += ` | gzip > ${shellQuote(outputFile)}`;
49
- } else {
50
- command += ` > ${shellQuote(outputFile)}`;
51
- }
52
-
53
- return command;
48
+ // A producer that fails must fail the whole command and leave no file: see dump-guard.js.
49
+ return guardedDump(command, outputFile, compress);
54
50
  }
55
51
 
56
52
  /**
@@ -87,13 +83,8 @@ export function buildPostgreSQLDumpCommand(options) {
87
83
 
88
84
  command += ` ${shellQuote(database)}`;
89
85
 
90
- if (compress) {
91
- command += ` | gzip > ${shellQuote(outputFile)}`;
92
- } else {
93
- command += ` > ${shellQuote(outputFile)}`;
94
- }
95
-
96
- return command;
86
+ // A producer that fails must fail the whole command and leave no file: see dump-guard.js.
87
+ return guardedDump(command, outputFile, compress);
97
88
  }
98
89
 
99
90
  /**
@@ -127,7 +118,7 @@ export function buildMongoDBDumpCommand(options) {
127
118
  command += ` --out ${shellQuote(outputDir)}`;
128
119
 
129
120
  if (compress) {
130
- command += ` && tar -czf ${shellQuote(outputDir + '.tar.gz')} -C "$(dirname ${shellQuote(outputDir)})" "$(basename ${shellQuote(outputDir)})"`;
121
+ command += ` && tar -czf ${shellQuote(mongoArchivePath(outputDir))} -C "$(dirname ${shellQuote(outputDir)})" "$(basename ${shellQuote(outputDir)})"`;
131
122
  command += ` && rm -rf ${shellQuote(outputDir)}`;
132
123
  }
133
124
 
@@ -147,22 +138,16 @@ export function buildMySQLImportCommand(options) {
147
138
  inputFile
148
139
  } = options;
149
140
 
150
- let command = '';
151
-
152
- if (inputFile.endsWith('.gz')) {
153
- command = `gunzip -c ${shellQuote(inputFile)} | `;
154
- } else {
155
- command = `cat ${shellQuote(inputFile)} | `;
156
- }
157
-
158
- command += 'mysql';
141
+ let command = 'mysql';
159
142
  if (user) command += ` -u${shellQuote(user)}`;
160
143
  if (password) command += ` -p${shellQuote(password)}`;
161
144
  if (host) command += ` -h ${shellQuote(host)}`;
162
145
  if (port) command += ` -P ${shellQuote(port)}`;
163
146
  command += ` ${shellQuote(database)}`;
164
147
 
165
- return command;
148
+ // A gzip file is verified whole before mysql reads a byte of it (dump-guard.js).
149
+ if (inputFile.endsWith('.gz')) return guardedFeed(inputFile, command);
150
+ return `cat ${shellQuote(inputFile)} | ${command}`;
166
151
  }
167
152
 
168
153
  /**
@@ -190,11 +175,8 @@ export function buildPostgreSQLImportCommand(options) {
190
175
  command += ' --clean --if-exists';
191
176
  command += ` -d ${shellQuote(database)}`;
192
177
 
193
- if (inputFile.endsWith('.gz')) {
194
- command = `gunzip -c ${shellQuote(inputFile)} | ${command}`;
195
- } else {
196
- command += ` ${shellQuote(inputFile)}`;
197
- }
178
+ if (inputFile.endsWith('.gz')) return guardedFeed(inputFile, command);
179
+ command += ` ${shellQuote(inputFile)}`;
198
180
 
199
181
  return command;
200
182
  }