ssh-mcp 2.0.1 → 2.0.3

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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/ssh-mcp)](https://www.npmjs.com/package/ssh-mcp)
4
4
  [![Downloads](https://img.shields.io/npm/dm/ssh-mcp)](https://www.npmjs.com/package/ssh-mcp)
5
+ [![CI](https://github.com/tufantunc/ssh-mcp/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/tufantunc/ssh-mcp/actions/workflows/ci.yml)
6
+ [![codecov](https://codecov.io/gh/tufantunc/ssh-mcp/branch/main/graph/badge.svg)](https://codecov.io/gh/tufantunc/ssh-mcp)
5
7
  [![License](https://img.shields.io/github/license/tufantunc/ssh-mcp)](./LICENSE)
6
8
  [![GitHub issues](https://img.shields.io/github/issues/tufantunc/ssh-mcp)](https://github.com/tufantunc/ssh-mcp/issues)
7
9
 
@@ -91,6 +91,16 @@ function normalizeConfig(raw) {
91
91
  export function getProfile(config, name) {
92
92
  const targetName = name || config.defaults.defaultProfile;
93
93
  if (!targetName) {
94
+ // Falling back to profiles[0] meant that with several hosts configured and
95
+ // no default chosen, a command with no profile argument ran against
96
+ // whichever host happened to be listed first — silently, and typically the
97
+ // one written down first, which tends to be production. One profile is
98
+ // unambiguous; more than one is a question the caller has to answer.
99
+ if (config.profiles.length > 1) {
100
+ const names = config.profiles.map((p) => p.name).join(', ');
101
+ throw new Error(`No profile selected and no default configured, but ${config.profiles.length} profiles exist: ${names}. ` +
102
+ `Pass a "profile" argument, or set defaults.defaultProfile in the config.`);
103
+ }
94
104
  return config.profiles[0];
95
105
  }
96
106
  const profile = config.profiles.find((p) => p.name === targetName);
@@ -28,12 +28,25 @@ export class SSHConnection {
28
28
  this.sessions = new SessionManager({
29
29
  // Live read: the profile object can be replaced after construction.
30
30
  profile: () => this.profile,
31
- openShell: () => new Promise((resolve, reject) => {
32
- this.getClient().shell({ term: 'xterm-256color', cols: 200, rows: 50 }, (err, stream) => (err ? reject(err) : resolve(stream)));
33
- }),
34
- openExec: (command) => new Promise((resolve, reject) => {
35
- this.getClient().exec(this.applyWorkdir(command), (err, stream) => (err ? reject(err) : resolve(stream)));
36
- }),
31
+ // ensureConnected inside the callback, not just before the retry: these
32
+ // run under openWithRetry, and Dropbear drops the whole connection under
33
+ // channel churn rather than merely refusing the channel. openSession does
34
+ // check the link first, but the link can die between that check and the
35
+ // channel opening — and then every retry reached getClient() on a dead
36
+ // client and threw the same "SSH connection not established", so the retry
37
+ // re-ran a corpse three times. SftpClient already did it this way.
38
+ openShell: async () => {
39
+ await this.ensureConnected();
40
+ return new Promise((resolve, reject) => {
41
+ this.getClient().shell({ term: 'xterm-256color', cols: 200, rows: 50 }, (err, stream) => (err ? reject(err) : resolve(stream)));
42
+ });
43
+ },
44
+ openExec: async (command) => {
45
+ await this.ensureConnected();
46
+ return new Promise((resolve, reject) => {
47
+ this.getClient().exec(this.applyWorkdir(command), (err, stream) => (err ? reject(err) : resolve(stream)));
48
+ });
49
+ },
37
50
  onChannelOpened: () => { this.activeChannels++; },
38
51
  onChannelClosed: () => { this.activeChannels--; },
39
52
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ssh-mcp",
3
3
  "license": "MIT",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "description": "MCP server exposing policy-gated, audited SSH access for Linux and Windows hosts via the Model Context Protocol.",
6
6
  "type": "module",
7
7
  "bin": {
@@ -43,6 +43,7 @@
43
43
  "@changesets/cli": "^2.31.0",
44
44
  "@types/node": "^24.5.2",
45
45
  "@types/ssh2": "^1.15.5",
46
+ "@vitest/coverage-v8": "^3.2.7",
46
47
  "cross-env": "^7.0.3",
47
48
  "fast-check": "^3.23.2",
48
49
  "shx": "^0.4.0",