mcp-ssh-manager 3.3.0 → 3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ All notable changes to MCP SSH Manager will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.4.0] - 2026-05-07
9
+
10
+ ### Added
11
+
12
+ - **Full Windows OpenSSH command execution** ([#31](https://github.com/bvisible/mcp-ssh-manager/pull/31) — thanks @WenKingSu)
13
+ - When a server is configured with `platform = "windows"`, commands are now wrapped as `powershell -NoProfile -OutputFormat Text -EncodedCommand <utf16le-base64>`. This is the same approach used by Ansible, Chef, and Puppet for Windows remote execution. It sidesteps every `cmd.exe` quoting and OEM code page issue (CP950, CP932, CP1252…) that was causing mojibake on non-ASCII output.
14
+ - Prepends `$ProgressPreference='SilentlyContinue'` (suppresses CLIXML progress sentinels in stderr) and `[Console]::OutputEncoding=UTF8` (forces clean UTF-8 stdout).
15
+ - Working-directory prefix uses `Set-Location '${escapedDir}'; ${cmd}` (PowerShell-native, with `'` → `''` escaping) instead of `cd ${dir} && ${cmd}` which is invalid in `cmd.exe`. Applied consistently across `ssh_execute`, `ssh_execute_group`, and `ssh_execute_sudo`.
16
+ - Strictly gated behind `platform === 'windows'` — Linux/macOS targets are completely unaffected.
17
+
18
+ ### Fixed
19
+
20
+ - **`ssh_session_start` timing out on real-world shells** ([#20](https://github.com/bvisible/mcp-ssh-manager/issues/20), [#30](https://github.com/bvisible/mcp-ssh-manager/pull/30) — thanks @MakksSh)
21
+ - The previous shell-prompt detection used a fragile regex (`/[$#>]\s*$/`) that broke on custom prompts, ANSI color codes, multiline prompts, slow shells, `.bashrc`/profile script noise, and any non-standard prompt symbol. Sessions would frequently fail to initialize with `Timeout waiting for shell prompt`.
22
+ - Replaced with a marker-based protocol: the PTY is requested with `ECHO: 0`, a unique UUID v4 readiness marker is sent on session start, and every executed command is wrapped with `set +e; <cmd>; __mcp_status=$?; printf '\n<marker>:%s\n' "$__mcp_status"`. The completion marker carries the **real exit code** captured from `$?` instead of the previous `!output.includes('command not found')` heuristic.
23
+ - A shell prompt is presentation, not a protocol boundary. Marker-based sync is shell-agnostic, deterministic, and requires zero per-server configuration.
24
+ - Bonus: sessions now report accurate `success`/`exitCode` for downstream consumers.
25
+
8
26
  ## [3.3.0] - 2026-05-02
9
27
 
10
28
  ### Added
package/README.md CHANGED
@@ -6,7 +6,7 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
8
8
  [![npm downloads](https://img.shields.io/npm/dt/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
9
- [![Version](https://img.shields.io/badge/Version-3.2.2-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.2.2)
9
+ [![Version](https://img.shields.io/badge/Version-3.4.0-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.4.0)
10
10
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=for-the-badge&logo=anthropic)](https://claude.ai/code)
11
11
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=for-the-badge&logo=openai)](https://openai.com/codex)
12
12
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=for-the-badge)](https://modelcontextprotocol.io)
@@ -14,11 +14,43 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
14
14
 
15
15
  </div>
16
16
 
17
+ <p align="center">
18
+ <img src="docs/images/ssh-manager-cli-menu.png" alt="ssh-manager interactive CLI menu" width="900">
19
+ </p>
20
+
21
+ ---
22
+
23
+ ## 🎉 What's New in v3.4.0
24
+
25
+ **Full Windows OpenSSH support + shell-agnostic session sync** (Released: May 7, 2026)
26
+
27
+ - **🪟 Windows OpenSSH targets — encoding & syntax fixes** ([#31](https://github.com/bvisible/mcp-ssh-manager/pull/31))
28
+ - **Mojibake fix** — Commands on Windows hosts no longer inherit the OEM code page (CP950, CP932, CP1252…). Payloads are now wrapped as `powershell -NoProfile -OutputFormat Text -EncodedCommand <utf16le-base64>` (the same approach used by Ansible / Chef / Puppet for Windows remote execution), sidestepping every `cmd.exe` quoting and code-page issue
29
+ - **`cd && ` syntax fix** — `cd ${workingDir} && ${cmd}` is invalid in `cmd.exe`; replaced with `Set-Location '${escapedDir}'; ${cmd}` (PowerShell-native, with `'` → `''` escaping) across `ssh_execute`, `ssh_execute_group`, and `ssh_execute_sudo`
30
+ - Strictly gated behind `platform = "windows"` — Linux/macOS targets take the exact same code path as before, zero risk of regression
31
+ - Thanks [@WenKingSu](https://github.com/WenKingSu) for the clean, well-documented patch
32
+ - **🎯 Marker-based SSH session sync — replaces fragile prompt detection** ([#30](https://github.com/bvisible/mcp-ssh-manager/pull/30))
33
+ - The previous `/[$#>]\s*$/` regex broke on custom prompts, ANSI color codes, multiline prompts, slow shells, `.bashrc` noise, AIX-style login flows — `ssh_session_start` would frequently fail with "Timeout waiting for shell prompt"
34
+ - Now uses **UUID v4 markers** as protocol boundaries: each command is wrapped with a unique end marker (`set +e; <cmd>; __mcp_status=$?; printf '\n<marker>:%s\n' "$__mcp_status"`), and the PTY is opened with `ECHO: 0` so the buffer contains only command output
35
+ - **Bonus**: sessions now report **real exit codes** captured from `$?` instead of the previous `!output.includes('command not found')` heuristic
36
+ - Resolves [#20](https://github.com/bvisible/mcp-ssh-manager/issues/20) and supersedes the proposed configurable `prompt_pattern` approach by making the problem disappear entirely — no per-server config required
37
+ - Thanks [@MakksSh](https://github.com/MakksSh) for the precise root-cause analysis and the clean refactor
38
+
39
+ [Read full changelog →](CHANGELOG.md#340---2026-05-07)
40
+
17
41
  ---
18
42
 
19
- ## 🎉 What's New in v3.2.2
43
+ ## Previous Releases
44
+
45
+ ### v3.3.0 - ProxyCommand & Critical Fixes (May 2, 2026)
20
46
 
21
- **Global Install Fix & CLI Binary** (Released: April 7, 2026)
47
+ - **🔌 ProxyCommand support** for SOCKS5 / custom proxy commands ([#24](https://github.com/bvisible/mcp-ssh-manager/pull/24))
48
+ - **⏱️ `ssh_execute` timeout silently capped at 30 s** — fixed ([#28](https://github.com/bvisible/mcp-ssh-manager/issues/28), [#29](https://github.com/bvisible/mcp-ssh-manager/pull/29))
49
+ - **🪟 Windows global install `/bin/bash` shim error** — fixed ([#22](https://github.com/bvisible/mcp-ssh-manager/issues/22), [#23](https://github.com/bvisible/mcp-ssh-manager/pull/23))
50
+ - **🔧 `server add` blocked by missing `rsync`** — `rsync` now optional ([#26](https://github.com/bvisible/mcp-ssh-manager/pull/26))
51
+ - **🔡 Hyphenated server names silently dropped** — validation hardened ([#25](https://github.com/bvisible/mcp-ssh-manager/issues/25), [#27](https://github.com/bvisible/mcp-ssh-manager/pull/27))
52
+
53
+ ### v3.2.2 - Global Install Fix & CLI Binary (April 7, 2026)
22
54
 
23
55
  - **🔧 Global install fixed**: `.env` path resolution now uses a fallback chain instead of hardcoded `__dirname` — works correctly with `npm install -g` ([#16](https://github.com/bvisible/mcp-ssh-manager/issues/16), [#19](https://github.com/bvisible/mcp-ssh-manager/issues/19))
24
56
  - Fallback chain: `~/.ssh-manager/.env` → `cwd/.env` → `~/.env` → project `.env`
@@ -26,10 +58,6 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
26
58
  - **📦 `ssh-manager` CLI registered as binary**: `npm install -g` now creates both `mcp-ssh-manager` and `ssh-manager` commands ([#18](https://github.com/bvisible/mcp-ssh-manager/issues/18))
27
59
  - **⚡ Race condition fix**: Server config is now fully loaded before the MCP server accepts requests
28
60
 
29
- ---
30
-
31
- ## Previous Releases
32
-
33
61
  ### v3.2.0 - ProxyJump / Bastion Host Support (March 18, 2026)
34
62
 
35
63
  - **🔀 ProxyJump support**: Connect to servers behind bastion/jump hosts with a simple `PROXYJUMP` config field ([#15](https://github.com/bvisible/mcp-ssh-manager/issues/15))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "MCP SSH Manager: Model Context Protocol server for SSH remote server management. Control SSH connections from Claude Code and OpenAI Codex - execute commands, transfer files, database operations, backups, health monitoring, and DevOps automation. NEW: Tool activation system reduces context usage by 92%",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -268,12 +268,31 @@ function loadServerConfig() {
268
268
  // Execute command with timeout - using child_process timeout for real kill
269
269
  async function execCommandWithTimeout(ssh, command, options = {}, timeoutMs = 30000) {
270
270
  // Pass through rawCommand and platform if specified
271
- const { rawCommand, platform, ...otherOptions } = options;
272
- const isWindows = platform === 'windows';
271
+ const { rawCommand, platform = 'linux', ...otherOptions } = options;
272
+
273
+ // Windows targets: encode the command as PowerShell -EncodedCommand (UTF-16
274
+ // LE base64). This is the standard approach (used by Ansible / Chef / Puppet)
275
+ // because cmd.exe's quoting rules are inconsistent across versions and break
276
+ // commands containing $vars, $(...) subexpressions, double-quoted strings,
277
+ // pipes, etc. Base64 sidesteps all escape issues entirely.
278
+ if (platform === 'windows' && !rawCommand) {
279
+ // Suppress progress (avoids CLIXML sentinels in stderr) + force UTF-8 stdout
280
+ const prelude = `$ProgressPreference='SilentlyContinue'; [Console]::OutputEncoding=[System.Text.Encoding]::UTF8;`;
281
+ const fullPSCommand = `${prelude} ${command}`;
282
+ const utf16le = Buffer.from(fullPSCommand, 'utf16le');
283
+ const b64 = utf16le.toString('base64');
284
+ // -OutputFormat Text prevents stderr/info streams from being CLIXML-encoded
285
+ const wrappedCommand = `powershell -NoProfile -OutputFormat Text -EncodedCommand ${b64}`;
286
+ return ssh.execCommand(wrappedCommand, { ...otherOptions, execOptions: { ...(otherOptions.execOptions || {}) } });
287
+ }
273
288
 
274
- // For commands that might hang, use the system's timeout command if available
275
- // Skip for Windows hosts where the Linux timeout/sh commands don't exist
276
- const useSystemTimeout = timeoutMs > 0 && timeoutMs < 300000 && !rawCommand && !isWindows; // Max 5 minutes, not for raw/Windows commands
289
+ // For commands that might hang, use the system's timeout command if available.
290
+ // Note: the `!isWindows` guard that existed here previously is intentionally
291
+ // removed. Windows targets return early above (the `if (platform === 'windows'
292
+ // && !rawCommand)` block), so by the time execution reaches this line it is
293
+ // guaranteed to be a Linux/macOS target. The behaviour is identical; the old
294
+ // guard was made redundant by the early-return path.
295
+ const useSystemTimeout = timeoutMs > 0 && timeoutMs < 300000 && !rawCommand; // Max 5 minutes, not for raw commands
277
296
 
278
297
  if (useSystemTimeout) {
279
298
  // Wrap command with timeout command (works on Linux/Mac)
@@ -617,12 +636,25 @@ registerToolConditional(
617
636
  const servers = loadServerConfig();
618
637
  const serverConfig = servers[serverName.toLowerCase()];
619
638
  const workingDir = cwd || serverConfig?.default_dir;
620
- const fullCommand = workingDir ? `cd ${workingDir} && ${expandedCommand}` : expandedCommand;
639
+ const platform = serverConfig?.platform || 'linux';
640
+
641
+ // Build cwd-prefixed command using platform-appropriate syntax
642
+ let fullCommand;
643
+ if (workingDir) {
644
+ if (platform === 'windows') {
645
+ const escapedDir = workingDir.replace(/'/g, "''");
646
+ fullCommand = `Set-Location '${escapedDir}'; ${expandedCommand}`;
647
+ } else {
648
+ fullCommand = `cd ${workingDir} && ${expandedCommand}`;
649
+ }
650
+ } else {
651
+ fullCommand = expandedCommand;
652
+ }
621
653
 
622
654
  // Log command execution
623
655
  const startTime = logger.logCommand(serverName, fullCommand, workingDir);
624
656
 
625
- const result = await execCommandWithTimeout(ssh, fullCommand, { platform: serverConfig?.platform }, cappedTimeout);
657
+ const result = await execCommandWithTimeout(ssh, fullCommand, { platform }, cappedTimeout);
626
658
 
627
659
  // Log command result
628
660
  logger.logCommandResult(serverName, fullCommand, startTime, result);
@@ -1796,13 +1828,27 @@ registerToolConditional(
1796
1828
  async (serverName) => {
1797
1829
  const ssh = await getConnection(serverName);
1798
1830
 
1799
- // Build full command with cwd if provided
1831
+ // Build full command with cwd if provided.
1832
+ // Use platform-appropriate syntax: Set-Location for Windows (cmd.exe
1833
+ // does not support `cd && `) vs cd && for Linux/macOS.
1800
1834
  const servers = loadServerConfig();
1801
1835
  const serverConfig = servers[serverName.toLowerCase()];
1802
1836
  const workingDir = cwd || serverConfig?.default_dir;
1803
- const fullCommand = workingDir ? `cd ${workingDir} && ${command}` : command;
1837
+ const platform = serverConfig?.platform || 'linux';
1838
+ let fullCommand;
1839
+ if (workingDir) {
1840
+ if (platform === 'windows') {
1841
+ // Single-quote escaping: replace ' with '' (PowerShell convention)
1842
+ const escapedDir = workingDir.replace(/'/g, "''");
1843
+ fullCommand = `Set-Location '${escapedDir}'; ${command}`;
1844
+ } else {
1845
+ fullCommand = `cd ${workingDir} && ${command}`;
1846
+ }
1847
+ } else {
1848
+ fullCommand = command;
1849
+ }
1804
1850
 
1805
- const execResult = await execCommandWithTimeout(ssh, fullCommand, { platform: serverConfig?.platform }, 30000);
1851
+ const execResult = await execCommandWithTimeout(ssh, fullCommand, { platform }, 30000);
1806
1852
 
1807
1853
  return {
1808
1854
  stdout: execResult.stdout,
@@ -2182,13 +2228,24 @@ registerToolConditional(
2182
2228
  }
2183
2229
 
2184
2230
  // Add working directory if specified
2231
+ const platform = serverConfig?.platform || 'linux';
2185
2232
  if (cwd) {
2186
- fullCommand = `cd ${cwd} && ${fullCommand}`;
2233
+ if (platform === 'windows') {
2234
+ const escapedDir = cwd.replace(/'/g, "''");
2235
+ fullCommand = `Set-Location '${escapedDir}'; ${fullCommand}`;
2236
+ } else {
2237
+ fullCommand = `cd ${cwd} && ${fullCommand}`;
2238
+ }
2187
2239
  } else if (serverConfig?.default_dir) {
2188
- fullCommand = `cd ${serverConfig.default_dir} && ${fullCommand}`;
2240
+ if (platform === 'windows') {
2241
+ const escapedDir = serverConfig.default_dir.replace(/'/g, "''");
2242
+ fullCommand = `Set-Location '${escapedDir}'; ${fullCommand}`;
2243
+ } else {
2244
+ fullCommand = `cd ${serverConfig.default_dir} && ${fullCommand}`;
2245
+ }
2189
2246
  }
2190
2247
 
2191
- const result = await execCommandWithTimeout(ssh, fullCommand, { platform: serverConfig?.platform }, timeout);
2248
+ const result = await execCommandWithTimeout(ssh, fullCommand, { platform }, timeout);
2192
2249
 
2193
2250
  // Mask password in output for security
2194
2251
  const maskedCommand = fullCommand.replace(/echo "[^"]+" \| sudo -S/, 'sudo');
@@ -9,6 +9,10 @@ import { logger } from './logger.js';
9
9
  // Map to store active sessions
10
10
  const sessions = new Map();
11
11
 
12
+ function generateMarker(prefix) {
13
+ return `${prefix}_${uuidv4().replace(/-/g, '')}`;
14
+ }
15
+
12
16
  // Session states
13
17
  export const SESSION_STATES = {
14
18
  INITIALIZING: 'initializing',
@@ -50,7 +54,10 @@ class SSHSession {
50
54
  this.shell = await this.ssh.requestShell({
51
55
  term: 'xterm-256color',
52
56
  cols: 80,
53
- rows: 24
57
+ rows: 24,
58
+ modes: {
59
+ ECHO: 0
60
+ }
54
61
  });
55
62
 
56
63
  // Setup event handlers
@@ -79,8 +86,11 @@ class SSHSession {
79
86
  });
80
87
  });
81
88
 
82
- // Wait for shell prompt
83
- await this.waitForPrompt();
89
+ // Wait for an explicit readiness marker instead of a shell prompt
90
+ const readyMarker = generateMarker('ready');
91
+ const readyCommand = `printf '\\n${readyMarker}\\n'`;
92
+ this.shell.write(`${readyCommand}\n`);
93
+ await this.waitForMarker(readyMarker);
84
94
 
85
95
  // Allow context queries through standard execute flow
86
96
  this.state = SESSION_STATES.READY;
@@ -103,14 +113,13 @@ class SSHSession {
103
113
  }
104
114
 
105
115
  /**
106
- * Wait for shell prompt
116
+ * Wait for a marker in shell output
107
117
  */
108
- async waitForPrompt(timeout = 5000) {
118
+ async waitForMarker(marker, timeout = 5000) {
109
119
  const startTime = Date.now();
110
120
 
111
121
  while (Date.now() - startTime < timeout) {
112
- // Check if we have a prompt (ends with $ or # typically)
113
- if (this.outputBuffer.match(/[$#>]\s*$/)) {
122
+ if (this.outputBuffer.includes(marker)) {
114
123
  return true;
115
124
  }
116
125
 
@@ -118,7 +127,7 @@ class SSHSession {
118
127
  await new Promise(resolve => setTimeout(resolve, 100));
119
128
  }
120
129
 
121
- throw new Error('Timeout waiting for shell prompt');
130
+ throw new Error(`Timeout waiting for marker: ${marker}`);
122
131
  }
123
132
 
124
133
  /**
@@ -175,31 +184,23 @@ class SSHSession {
175
184
  });
176
185
  }
177
186
 
178
- // Send command
179
- this.shell.write(command + '\n');
187
+ const endMarker = generateMarker('cmd');
180
188
 
181
- // Wait for command to complete
182
- await this.waitForPrompt(options.timeout || 30000);
189
+ // Send command wrapped in an explicit completion marker
190
+ this.shell.write(`set +e\n${command}\n__mcp_status=$?\nprintf '\\n${endMarker}:%s\\n' "$__mcp_status"\n`);
183
191
 
184
- // Parse output (remove command echo and prompt)
185
- let output = this.outputBuffer;
192
+ // Wait for command completion marker
193
+ await this.waitForMarker(endMarker, options.timeout || 30000);
186
194
 
187
- // Remove the command echo (first line)
188
- const lines = output.split('\n');
189
- if (lines[0].includes(command)) {
190
- lines.shift();
195
+ const markerIndex = this.outputBuffer.indexOf(endMarker);
196
+ if (markerIndex < 0) {
197
+ throw new Error(`Command marker not found: ${endMarker}`);
191
198
  }
192
-
193
- // Remove the prompt (last line)
194
- const lastLine = lines[lines.length - 1];
195
- if (lastLine.match(/[$#>]\s*$/)) {
196
- lines.pop();
197
- }
198
-
199
- output = lines.join('\n').trim();
200
-
201
- // Check for command success (basic heuristic)
202
- const success = !this.errorBuffer && !output.includes('command not found');
199
+ const markerLine = this.outputBuffer.slice(markerIndex).split(/\r?\n/, 1)[0];
200
+ const statusMatch = markerLine.match(/:(\d+)$/);
201
+ const exitCode = statusMatch ? Number.parseInt(statusMatch[1], 10) : null;
202
+ const output = this.outputBuffer.slice(0, markerIndex).replace(/\r?\n+$/, '');
203
+ const success = exitCode === 0;
203
204
 
204
205
  // Update context if command might have changed it
205
206
  if (command.startsWith('cd ') || command.startsWith('export ')) {