mcp-ssh-manager 3.6.7 → 3.8.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,11 +5,54 @@ 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.8.0] - 2026-08-14
9
+
10
+ ### Security
11
+
12
+ - **`@modelcontextprotocol/sdk` floor raised to `^1.30.0`** — the declared range (`^1.17.2`) still allowed versions carrying three published advisories, one of them high: cross-client data leak through shared server/transport instance reuse, DNS rebinding protection off by default, and a ReDoS. It also dragged in vulnerable transitive express packages (`body-parser`, `path-to-regexp`, `qs`, `ajv`). `npm audit --omit=dev` now reports **0 vulnerabilities**. Behaviour verified against the real MCP stdio protocol: identical to 1.17.5 (37 tools registered, same negotiation, clean shutdown).
13
+
14
+ ### Added
15
+
16
+ - **Optional `group` field on server config** ([#56](https://github.com/bvisible/mcp-ssh-manager/pull/56) — contributed by [@ice616](https://github.com/ice616), requested in [#55](https://github.com/bvisible/mcp-ssh-manager/issues/55))
17
+ - A free-form label (`SSH_SERVER_<NAME>_GROUP` in `.env`, `group = "..."` in TOML) carried on the server entry itself, so a server's group membership can be read straight off its config when exporting to — or importing from — another tool, with no second file to ship. It round-trips through `exportToToml`/`exportToEnv` and is returned by `ssh_list_servers`.
18
+ - **The label is not just descriptive: it makes the group usable.** `ssh_execute_group` and `ssh_group_manage list` now resolve members from the `group` field as well, so tagging servers is enough to run a command across them — `.server-groups.json` is no longer required to have a working group.
19
+ - Membership is the **union** of both sources: the explicit list stored by `ssh_group_manage` (which keeps carrying strategy, delay and stop-on-error) plus every server tagged with that name. Group names are case-insensitive. Config-derived members are resolved at read time and never written to `.server-groups.json`, so they cannot go stale.
20
+ - A group that exists only through the config is read-only for `ssh_group_manage`; attempting to edit it now returns an error pointing at the server config instead of a bare "not found".
21
+ - The `ssh-manager` add-server wizard asks for an optional group.
22
+ - Tests: new `tests/test-server-groups.js` (14 checks) covers config-derived groups, the union with stored groups, case-insensitivity, read-only enforcement, persistence isolation, the dynamic-group reload regression and group execution; `tests/test-config-field-names.js` gains `group` coverage across the `.env` loader, the TOML loader, the forbidden-field guard and the export round-trip.
23
+ - **Static type-checking over the existing JavaScript** (`npm run typecheck`) — a `tsconfig.json` in `checkJs`/`noEmit` mode runs TypeScript as a linter over JSDoc annotations. **Nothing is compiled and nothing changes for users**: the package still ships plain JS straight from `src/`, with no build step and no `dist/`. Added as a hard gate in the Code Quality workflow.
24
+ - A `ServerConfig` typedef in `src/config-loader.js` documents the resolved server shape and makes its camelCase contract enforceable: reading `serverConfig.default_dir` — the exact issue #49 regression — is now a type error (*"Property 'default_dir' does not exist on type 'ServerConfig'. Did you mean 'defaultDir'?"*) instead of a silent `undefined`. `tests/test-config-field-names.js` keeps guarding the same contract at runtime.
25
+
26
+ ### Fixed
27
+
28
+ - **A tunnel on an already-used local port crashed the entire MCP server** — `net.Server#listen` never passes an error to its callback (a failed bind is emitted as an `'error'` event), yet `ssh_tunnel_create` used `listen(port, host, (err) => ...)` and registered no `'error'` listener. On `EADDRINUSE` — the everyday tunnel failure — Node rethrew the unhandled event and killed the process, taking every pooled SSH connection and session with it, while the awaited promise never settled. Binding now rejects properly and the tool returns an error. Guarded by `tests/test-tunnel-listen.js`.
29
+ - **`ssh_sync` always passed an explicit `-p 22` to rsync** — the guard read `serverConfig.port !== '22'`, comparing a number against a string, so it never matched. Harmless in effect, but the intent (omit the flag on the default port) never applied. Found by the new typecheck, along with a matching `parseInt(serverConfig.port || '22')` in `ssh_known_hosts` that only worked because `parseInt` stringifies its argument first.
30
+ - **`ssh_sync` treated native Windows local paths as remote rsync specifications** — a path such as `C:\project` was passed unchanged to MSYS2 rsync, which parsed `C:` as a remote host and attempted an SSH connection to `c`. Windows drive-letter, rooted, UNC, and extended-length paths are now resolved and converted only for the spawned rsync argument while Node keeps the native path for local filesystem checks and logging; relative paths keep their existing semantics with normalized separators. Trailing separators retain rsync's directory-content semantics. A path already written in MSYS2 form (`/c/project`, `//server/share`) — the shape Windows users adopted to work around this very bug — is passed through untouched instead of being mounted twice into `/c/c/project`. Guarded by `tests/test-rsync-path.js` (24 checks: conversion table, pass-through, invariants over every input, platform isolation, failure modes, and a static guard on the `ssh_sync` wiring) plus a real MSYS2 rsync dry run.
31
+ - **The MCP server announced itself as version `1.2.0`** — the `serverInfo` version sent to Claude Code / Codex was a hardcoded literal the release process never bumped, so it had drifted far behind the real package version (3.7.0). It is now derived from `package.json`, the same treatment the CLI banner got in 3.7.0. This matters more under the MCP `2026-07-28` spec, where servers identify themselves in the `_meta` of every result.
32
+ - **`exportToEnv` no longer truncates a `group` containing `#`** — the value is now quoted like `DESCRIPTION`, so a label such as `prod #eu west` survives an export/re-import instead of coming back as `prod`.
33
+ - **The dynamic `all` group now sees TOML-defined servers** — it enumerated `process.env` only, so `ssh_execute_group all` silently skipped every server declared in a TOML config. The group layer now reads the configuration actually loaded by `ConfigLoader`.
34
+ - **The `all` group no longer disappears after the first group edit** — dynamic groups are deliberately never persisted, so every `.server-groups.json` written by `ssh_group_manage` lacked `all`, and the next start loaded that file as the complete set: `ssh_execute_group all` then failed with `Group 'all' not found`. Dynamic groups are now re-injected when the file is read.
35
+
36
+ ### Changed
37
+
38
+ - **Dropped the `uuid` dependency** in favour of Node's built-in `crypto.randomUUID()` — available since Node 14.17, and this package already requires Node >= 18. Removes one runtime dependency and the last remaining advisory. Session and tunnel ID formats are unchanged.
39
+
40
+ ## [3.7.0] - 2026-07-13
41
+
42
+ ### Added
43
+
44
+ - **Per-server SSH agent forwarding (`ForwardAgent`)** ([#53](https://github.com/bvisible/mcp-ssh-manager/pull/53) — requested by [@raphaelbahat](https://github.com/raphaelbahat) in [#52](https://github.com/bvisible/mcp-ssh-manager/issues/52))
45
+ - New opt-in option, `SSH_SERVER_<NAME>_FORWARD_AGENT=true` (`.env`) or `forward_agent = true` (TOML), enabling the equivalent of OpenSSH's `ForwardAgent yes` on a per-server basis. Processes on the remote host can then authenticate to other SSH hosts using the keys held in the operator's local `ssh-agent` (e.g. `git` over SSH), without copying any private key to the server.
46
+ - Requires a running local agent (`SSH_AUTH_SOCK`); the flag is ignored when no agent is present. `ForwardAgent` is set only alongside a valid agent, since `ssh2` throws otherwise. Because `ssh2`'s connection-level `agentForward` forwards on every exec/shell channel, no per-command change is needed.
47
+ - A `parseBool()` helper coerces the `.env` string value so `FORWARD_AGENT=false` is not treated as truthy; only `true`/`1`/`yes`/`on` enable it.
48
+ - **Defaults to `false`.** Documented in the README (*SSH Agent Forwarding*) and CLAUDE.md with the standard security warning (a root user on the remote host can use the forwarded agent for the life of the connection).
49
+ - Tests: `tests/test-agent-forward.js` verifies the `connect()` wiring across the on/off/absent/no-agent states; `tests/test-config-field-names.js` gains `forwardAgent` coverage including `.env` boolean coercion and a TOML export round-trip.
50
+
8
51
  ## [3.6.7] - 2026-07-11
9
52
 
10
53
  ### Security
11
54
 
12
- - **Command injection in the database command builders** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer / AI Risk Management**, see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48))
55
+ - **Command injection in the database command builders** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer, Aeon AI Risk Management** (http://airiskmanagement.ca), see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48))
13
56
  - Every `ssh_db_*` tool argument — `database`, `table`, `collection`, output/input file paths, and the `user` / `host` / `port` / `password` connection fields — arrives from tool-call parameters and was interpolated straight into a **shell-evaluated** command string in `src/database-manager.js`. A crafted value (`$(…)`, backticks, `; cmd`, `| cmd`, `&& cmd`, bare `> file`) executed arbitrary commands on the configured SSH target, under the account the MCP server uses.
14
57
  - The strongest path is **`ssh_db_list`**: it is classified read-only, so it stayed **allowed in the `readonly` and `restricted`** per-server security modes while still reaching an injectable builder — bypassing the boundary those modes promise.
15
58
  - The v3.6.5 heredoc fix (#44) only hardened `ssh_db_query`'s query **text**; the `list` / `dump` / `import` / `restore` builders and the query builders' **connection flags** were untouched.
@@ -409,4 +452,4 @@ None. All existing tools remain fully compatible.
409
452
  - Interactive server configuration tool
410
453
  - Connection testing utility
411
454
  - Pre-commit hooks for code quality
412
- - GitHub Actions workflow for CI/CD
455
+ - GitHub Actions workflow for CI/CD
package/CLAUDE.md CHANGED
@@ -70,11 +70,20 @@ See [docs/TOOL_MANAGEMENT.md](docs/TOOL_MANAGEMENT.md) for complete guide.
70
70
  ### Development and Testing
71
71
  ```bash
72
72
  npm start # Start MCP server (requires stdin)
73
+ npm test # Run the full test suite
74
+ npm run typecheck # Type-check JSDoc with tsc (no build, nothing emitted)
75
+ npm run test:all # Tests + typecheck + validation
73
76
  ./scripts/validate.sh # Run all validation checks
74
77
  node --check src/index.js # Check JavaScript syntax
75
78
  python -m py_compile tools/*.py # Check Python syntax
76
79
  ```
77
80
 
81
+ **Typecheck**: `tsconfig.json` runs TypeScript in `checkJs`/`noEmit` mode over the plain JS —
82
+ this project ships JavaScript straight from `src/` with no build step, and that must stay true.
83
+ The baseline is 0 errors and CI enforces it, so add JSDoc annotations (or a narrow
84
+ `/** @type {...} */` cast) rather than leaving new errors. `typescript` is pinned to `^6`
85
+ because knip 5 declares `peer typescript ">=5.0.4 <7"` — bumping one requires bumping the other.
86
+
78
87
  ### Debug Tools (in `debug/` directory)
79
88
  ```bash
80
89
  ./debug/test-claude-code.sh # Test Claude Code integration
@@ -154,9 +163,11 @@ SSH_SERVER_[NAME]_PASSPHRASE=passphrase # Optional, for passphrase-protected
154
163
  SSH_SERVER_[NAME]_PORT=22 # Optional
155
164
  SSH_SERVER_[NAME]_DEFAULT_DIR=/path # Optional default working directory
156
165
  SSH_SERVER_[NAME]_SUDO_PASSWORD=pass # Optional for automated sudo
166
+ SSH_SERVER_[NAME]_GROUP=production # Optional, free-form label for grouping/import-export
157
167
  SSH_SERVER_[NAME]_PLATFORM=windows # Optional: "linux" (default) or "windows"
158
168
  SSH_SERVER_[NAME]_PROXYJUMP=bastion # Optional: name of another server to use as jump host
159
169
  SSH_SERVER_[NAME]_PROXYCOMMAND=command # Optional: custom proxy command (ncat, ssh -W, etc.)
170
+ SSH_SERVER_[NAME]_FORWARD_AGENT=true # Optional: forward local ssh-agent to remote (needs SSH_AUTH_SOCK; security risk)
160
171
  ```
161
172
 
162
173
  ### TOML Format
@@ -170,9 +181,11 @@ passphrase = "key_passphrase" # Optional, for passphrase-protected
170
181
  port = 22 # Optional
171
182
  default_dir = "/path" # Optional default working directory
172
183
  sudo_password = "pass" # Optional for automated sudo
184
+ group = "production" # Optional, free-form label for grouping/import-export
173
185
  platform = "windows" # Optional: "linux" (default) or "windows"
174
186
  proxy_jump = "bastion" # Optional: name of another server to use as jump host
175
187
  proxy_command = "command" # Optional: custom proxy command (ncat, ssh -W, etc.)
188
+ forward_agent = true # Optional: forward local ssh-agent to remote (needs SSH_AUTH_SOCK; security risk)
176
189
  ```
177
190
 
178
191
  ## Key Implementation Details
@@ -189,6 +202,8 @@ proxy_command = "command" # Optional: custom proxy command (nc
189
202
 
190
203
  6. **Proxy Command Support**: Custom proxy commands (SOCKS5, ssh -W, etc.) are executed locally to establish connections, with proper error handling and timeout management (src/index.js:389-432)
191
204
 
205
+ 7. **Server Groups**: Membership is the union of two sources — the explicit lists in `.server-groups.json` (created via `ssh_group_manage`, which also hold strategy/delay/stopOnError) and the per-server `group` field of the SSH config. Config-derived groups are resolved at read time, never written to `.server-groups.json`, and are read-only for `ssh_group_manage`. `src/index.js` injects the loaded config into the group layer via `setServerConfigProvider()`; without it the module can only see `.env` servers (src/server-groups.js)
206
+
192
207
  ## Security Considerations
193
208
 
194
209
  - Never commit `.env` files (included in .gitignore)
package/README.md CHANGED
@@ -6,12 +6,14 @@ 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.6.7-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.6.7)
9
+ [![Version](https://img.shields.io/badge/Version-3.8.0-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.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)
13
13
  [![License](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)](LICENSE)
14
14
 
15
+ [![MCP Toplist](https://mcptoplist.com/badge/glama%2Fbvisible%2Fmcp-ssh-manager.svg)](https://mcptoplist.com/server/glama%2Fbvisible%2Fmcp-ssh-manager)
16
+
15
17
  </div>
16
18
 
17
19
  <p align="center">
@@ -20,23 +22,37 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
20
22
 
21
23
  ---
22
24
 
23
- ## 🎉 What's New in v3.6.7
25
+ ## 🎉 What's New in v3.8.0
24
26
 
25
- **🔒 Security fix: command injection in the database helpers (`ssh_db_list` / `ssh_db_dump` / `ssh_db_import`)** (Released: July 11, 2026)
27
+ **👥 Groups that live in your config, `ssh_sync` fixed on Windows, and a crash that took the whole server down** (Released: August 14, 2026)
26
28
 
27
- - **Every `ssh_db_*` argument is now shell-quoted** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer / AI Risk Management**, see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48)) — the database, table, collection, file-path and connection values passed to the database command builders were interpolated straight into a shell-evaluated string, so a crafted value (`$(…)`, backticks, `; cmd`) executed arbitrary commands on the SSH target. The strongest path was **`ssh_db_list`**, which is read-only-classified and therefore stayed allowed in the `readonly` and `restricted` security modes. The v3.6.5 heredoc fix (#44) only covered `ssh_db_query`'s query *text*; this hardens the list/dump/import/restore builders and the query builders' connection flags too.
28
- - **🧪 Regression-proofed** — a new test drives every builder × every caller-controlled parameter × an injection-payload battery (648 combinations) through a real shell with fake DB binaries and asserts nothing executes.
29
- - **🔐 `SECURITY.md` added** — documents private vulnerability reporting (GitHub Security tab + security email).
30
- - **No configuration or API change** — shell-quoting is transparent for normal database/table/file names.
29
+ - **New optional `group` field per server** ([#56](https://github.com/bvisible/mcp-ssh-manager/pull/56) — contributed by [@ice616](https://github.com/ice616), requested in [#55](https://github.com/bvisible/mcp-ssh-manager/issues/55)) — tag a server with `group = "production"` and it *is* in that group: `ssh_execute_group` and `ssh_group_manage list` resolve members straight from your `.env`/TOML, so there is no `.server-groups.json` to maintain and the grouping travels with the config when you export it to another tool. Membership is the **union** of both sources, so groups you already store keep working untouched.
30
+ - **🪟 `ssh_sync` works from a Windows host** ([#59](https://github.com/bvisible/mcp-ssh-manager/pull/59) — contributed by [@2836603852](https://github.com/2836603852)) — a local path like `C:\project` reached MSYS2 rsync unchanged, which read `C:` as a remote host and tried to SSH into a machine named `c`. Drive-letter, UNC and extended-length paths are now converted for the rsync argument only, while Node keeps the native path for its filesystem checks.
31
+ - **💥 A tunnel on a busy port no longer kills the MCP server** — `ssh_tunnel_create` on an already-bound port hit an unhandled `'error'` event and took the entire process down with it, dropping every pooled SSH connection and open session. It now returns a normal error.
32
+ - **🔒 Security: `@modelcontextprotocol/sdk` floor raised to `^1.30.0`** — the previous range still allowed versions carrying three published advisories, one of them high. `npm audit` is clean, and the `uuid` dependency is gone in favour of Node's built-in `crypto.randomUUID()`.
33
+ - **🧪 JSDoc type-checking in CI** (`npm run typecheck`) — TypeScript now runs as a static checker over the plain JavaScript. **No build step, no `dist/`, nothing changes for users**; it found two of the bugs above on the day it landed.
31
34
 
32
- ⚠️ **Upgrade recommended for anyone exposing the database tools**, especially operators relying on `readonly` / `restricted` modes as a security boundary.
35
+ ```env
36
+ SSH_SERVER_WEB1_GROUP=production
37
+ ```
33
38
 
34
- [Read full changelog →](CHANGELOG.md#367---2026-07-11)
39
+ [Read full changelog →](CHANGELOG.md#380---2026-08-14)
35
40
 
36
41
  ---
37
42
 
38
43
  ## Previous Releases
39
44
 
45
+ <details>
46
+ <summary><b>📜 Release history — v3.7.0 down to v1.0.0</b> (click to expand)</summary>
47
+
48
+ ### v3.7.0 - Per-server SSH agent forwarding (July 13, 2026)
49
+
50
+ - **🔗 New opt-in `FORWARD_AGENT` / `forward_agent` option** ([#53](https://github.com/bvisible/mcp-ssh-manager/pull/53) — requested by [@raphaelbahat](https://github.com/raphaelbahat) in [#52](https://github.com/bvisible/mcp-ssh-manager/issues/52)) — the equivalent of OpenSSH's `ForwardAgent yes`, per server: processes on the remote host authenticate to *other* SSH hosts with the keys in your local `ssh-agent`, without copying any private key. Requires a running agent and defaults to `false`. [Full changelog →](CHANGELOG.md#370---2026-07-13)
51
+
52
+ ### v3.6.7 - Security: command injection fix in the database helpers (July 11, 2026)
53
+
54
+ - **🔒 Every `ssh_db_*` argument is now shell-quoted** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer, Aeon AI Risk Management** (http://airiskmanagement.ca), see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48)) — caller-controlled values (`ssh_db_list` most notably, which stayed allowed in `readonly`/`restricted` modes) were interpolated into shell-evaluated strings, allowing arbitrary command execution on the SSH target. A centralized `shellQuote()` now wraps every value across all 15 builders, guarded by a 648-combination injection test. [Full changelog →](CHANGELOG.md#367---2026-07-11)
55
+
40
56
  ### v3.6.6 - `SUDO_PASSWORD` / `DEFAULT_DIR` / `ssh_sync` key auth work again (July 11, 2026)
41
57
 
42
58
  - **🔑 camelCase config field reads** ([#50](https://github.com/bvisible/mcp-ssh-manager/pull/50) — thanks [@egoan82](https://github.com/egoan82)) — since the v3.0.0 ConfigLoader refactor, `ssh_execute_sudo` ignored `SUDO_PASSWORD`, `DEFAULT_DIR` was ignored by `ssh_execute`/`ssh_group_execute`/`ssh_list_servers`, and `ssh_sync` never passed the configured SSH key to rsync. All aligned with the loader's camelCase fields, with a regression test locking the loader output shape. [Full changelog →](CHANGELOG.md#366---2026-07-11)
@@ -173,6 +189,8 @@ This release adds **12 new MCP tools** transforming SSH Manager into a comprehen
173
189
 
174
190
  [Read Full Changelog →](CHANGELOG.md#300---2025-10-01)
175
191
 
192
+ </details>
193
+
176
194
  ---
177
195
 
178
196
  ## 📑 Table of Contents
@@ -442,6 +460,7 @@ key_path = "~/.ssh/id_rsa" # for SSH key auth (recommended)
442
460
  passphrase = "key_passphrase" # optional, for passphrase-protected keys
443
461
  port = 22
444
462
  default_dir = "/var/www"
463
+ group = "production" # optional, free-form label for grouping/import-export
445
464
  description = "Production server"
446
465
 
447
466
  [ssh_servers.staging]
@@ -671,9 +690,11 @@ SSH_SERVER_[NAME]_PASSPHRASE=key_passphrase # Optional, for passphrase-protecte
671
690
  SSH_SERVER_[NAME]_PORT=22 # Optional, defaults to 22
672
691
  SSH_SERVER_[NAME]_DEFAULT_DIR=/path/to/dir # Optional, default working directory
673
692
  SSH_SERVER_[NAME]_DESCRIPTION=Description # Optional
693
+ SSH_SERVER_[NAME]_GROUP=production # Optional, free-form label for grouping/import-export
674
694
  SSH_SERVER_[NAME]_PLATFORM=windows # Optional: "linux" (default) or "windows"
675
695
  SSH_SERVER_[NAME]_PROXYJUMP=bastion # Optional: name of another server to use as jump host
676
696
  SSH_SERVER_[NAME]_PROXYCOMMAND=command # Optional: custom proxy command (ncat, ssh -W, etc.)
697
+ SSH_SERVER_[NAME]_FORWARD_AGENT=true # Optional: forward local ssh-agent to remote (needs SSH_AUTH_SOCK; security risk — see SSH Agent section)
677
698
 
678
699
  # Example: Linux server
679
700
  SSH_SERVER_PRODUCTION_HOST=prod.example.com
@@ -804,6 +825,25 @@ passphrase = "your_passphrase"
804
825
 
805
826
  > **Note:** SSH Agent is preferred over storing passphrases in config files for better security.
806
827
 
828
+ ### 🔗 SSH Agent Forwarding
829
+
830
+ Enable per-server agent forwarding (the equivalent of OpenSSH's `ForwardAgent yes`) so processes on the remote host can authenticate to *other* SSH hosts using the keys in your **local** `ssh-agent` — e.g. `git clone` over SSH on a remote server using your local GitHub key, without copying any private key to the server.
831
+
832
+ It is **opt-in per server** and defaults to `false`. It requires a running local agent (`SSH_AUTH_SOCK` present); when the agent is unavailable the flag is simply ignored.
833
+
834
+ `.env` format:
835
+ ```env
836
+ SSH_SERVER_MYSERVER_FORWARD_AGENT=true
837
+ ```
838
+
839
+ TOML format:
840
+ ```toml
841
+ [ssh_servers.myserver]
842
+ forward_agent = true
843
+ ```
844
+
845
+ > ⚠️ **Security warning:** agent forwarding lets any process that can read the forwarded agent socket on the remote host — including anyone with **root** there — use your loaded keys to impersonate you against other hosts *for the life of the connection*. Only enable it for servers you trust, mirroring the same caution `ssh_config(5)` advises for `ForwardAgent`.
846
+
807
847
  ## 📚 Advanced Usage
808
848
 
809
849
  ### ProxyJump / Bastion Host
@@ -868,6 +908,41 @@ proxy_command = "C:\\Windows\\System32\\OpenSSH\\ssh.exe -W %h:%p user@jump-host
868
908
 
869
909
  The proxy command must be a valid command that reads from stdin and writes to stdout, accepting `%h` and `%p` placeholders for host and port.
870
910
 
911
+ ### Server Groups
912
+
913
+ Tag a server with `group` and it becomes part of that group — no extra file to maintain. The label is free-form and travels with the server definition, so it survives an export to (or import from) another tool.
914
+
915
+ ```env
916
+ SSH_SERVER_WEB1_HOST=10.0.0.1
917
+ SSH_SERVER_WEB1_USER=deploy
918
+ SSH_SERVER_WEB1_GROUP=production
919
+
920
+ SSH_SERVER_WEB2_HOST=10.0.0.2
921
+ SSH_SERVER_WEB2_USER=deploy
922
+ SSH_SERVER_WEB2_GROUP=production
923
+ ```
924
+
925
+ Or in TOML:
926
+ ```toml
927
+ [ssh_servers.web1]
928
+ host = "10.0.0.1"
929
+ user = "deploy"
930
+ group = "production"
931
+ ```
932
+
933
+ Both servers are then reachable as a group:
934
+
935
+ ```
936
+ Run "uptime" on the production group → ssh_execute_group
937
+ List my server groups → ssh_group_manage (action: list)
938
+ ```
939
+
940
+ `ssh_list_servers` also reports the group of each server, so you can see membership without opening the config.
941
+
942
+ **How it combines with `ssh_group_manage`:** groups you create with `ssh_group_manage` live in `.server-groups.json` and carry execution settings (strategy, delay, stop-on-error). Groups implied by the `group` field carry membership only. When a name exists on both sides, **membership is the union** — the stored list plus every server tagged with that name — and the stored execution settings apply. Group names are case-insensitive.
943
+
944
+ A group that exists only through the `group` field is read-only for `ssh_group_manage`: to change who belongs to it, edit the servers' `group` in your `.env`/TOML. Creating a group of the same name with `ssh_group_manage` is still allowed and simply adds stored members and settings on top.
945
+
871
946
  ### Documentation
872
947
  - [DEPLOYMENT_GUIDE.md](docs/DEPLOYMENT_GUIDE.md) - Deployment strategies and permission handling
873
948
  - [ALIASES_AND_HOOKS.md](docs/ALIASES_AND_HOOKS.md) - Command aliases and automation hooks
@@ -1036,6 +1111,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
1036
1111
  ### SSH Sync (rsync)
1037
1112
  - Password authentication requires `sshpass` to be installed
1038
1113
  - SSH key authentication is recommended for better security and reliability
1114
+ - **Windows MCP hosts**: pass native local paths such as `local:C:\project` or `local:.\project`; `ssh_sync` converts drive-letter and UNC paths to MSYS2 format before launching rsync. Prefer native paths, since Node checks them on disk using Windows path semantics — a path already written as `/c/...` or `//server/share` is passed through to rsync untouched rather than converted twice.
1039
1115
  - Large file transfers may take time and appear to hang - be patient
1040
1116
 
1041
1117
  ### Connection Management
package/cli/install.sh CHANGED
@@ -69,6 +69,12 @@ echo "Copying CLI files to $CLI_HOME..."
69
69
  rm -rf "$CLI_HOME"
70
70
  cp -r "$SCRIPT_DIR" "$CLI_HOME"
71
71
 
72
+ # Bundle package.json next to the CLI so it can report the real build version
73
+ # (the CLI derives its version from package.json instead of a hardcoded string).
74
+ if [ -f "$SCRIPT_DIR/../package.json" ]; then
75
+ cp "$SCRIPT_DIR/../package.json" "$CLI_HOME/package.json"
76
+ fi
77
+
72
78
  # Create executable symlink
73
79
  $SUDO ln -sf "$CLI_HOME/ssh-manager" "$INSTALL_DIR/ssh-manager"
74
80
 
package/cli/lib/menu.sh CHANGED
@@ -177,7 +177,24 @@ wizard_add_server() {
177
177
  echo "Set a default directory for this server (optional)."
178
178
  echo "Example: /var/www/html, /home/user/app, /opt/services"
179
179
  prompt_input "Default directory" "" "default_dir"
180
-
180
+
181
+ local group
182
+ echo
183
+ echo "Assign this server to a group (optional)."
184
+ echo "Servers sharing a group can be targeted together with ssh_execute_group."
185
+ echo "Example: production, staging, customer-acme"
186
+ prompt_input "Group" "" "group"
187
+
188
+ local forward_agent="n"
189
+ echo
190
+ echo "Forward your local ssh-agent to this server (optional)."
191
+ echo "Lets remote processes use your local keys — e.g. git over SSH."
192
+ print_warning "Security: anyone with root on this host can use your loaded keys"
193
+ print_warning "for the life of the connection. Only enable for servers you trust."
194
+ if prompt_yes_no "Enable SSH agent forwarding?" "n"; then
195
+ forward_agent="y"
196
+ fi
197
+
181
198
  # Step 5: Review
182
199
  echo
183
200
  print_subheader "Step 5: Review Configuration"
@@ -198,18 +215,35 @@ wizard_add_server() {
198
215
  if [ -n "$default_dir" ]; then
199
216
  print_table_row "Default Dir:" "$default_dir"
200
217
  fi
201
-
218
+ if [ -n "$group" ]; then
219
+ print_table_row "Group:" "$group"
220
+ fi
221
+ if [ "$forward_agent" = "y" ]; then
222
+ print_table_row "Agent Forwarding:" "enabled"
223
+ fi
224
+
202
225
  echo
203
226
  if prompt_yes_no "Save this configuration?" "y"; then
204
227
  # Save to .env
205
228
  add_server_to_env "$server_name" "$host" "$user" "$auth_type" "$auth_value" "$port" "$description"
206
-
229
+
230
+ local name_upper="$(echo "$server_name" | tr '[:lower:]' '[:upper:]')"
231
+
207
232
  # Add default directory if specified
208
233
  if [ -n "$default_dir" ]; then
209
- local name_upper="$(echo "$server_name" | tr '[:lower:]' '[:upper:]')"
210
234
  echo "SSH_SERVER_${name_upper}_DEFAULT_DIR=$default_dir" >> "$SSH_MANAGER_ENV"
211
235
  fi
212
-
236
+
237
+ # Add group if specified (quoted: free-form text, may contain spaces)
238
+ if [ -n "$group" ]; then
239
+ echo "SSH_SERVER_${name_upper}_GROUP=\"$group\"" >> "$SSH_MANAGER_ENV"
240
+ fi
241
+
242
+ # Enable agent forwarding if opted in
243
+ if [ "$forward_agent" = "y" ]; then
244
+ echo "SSH_SERVER_${name_upper}_FORWARD_AGENT=true" >> "$SSH_MANAGER_ENV"
245
+ fi
246
+
213
247
  echo
214
248
  print_success "Server '$server_name' added successfully!"
215
249
 
package/cli/ssh-manager CHANGED
@@ -21,8 +21,24 @@ source "$SCRIPT_DIR/lib/menu.sh"
21
21
  source "$SCRIPT_DIR/commands/server.sh"
22
22
  source "$SCRIPT_DIR/commands/tools.sh"
23
23
 
24
- # Version
25
- VERSION="3.1.0"
24
+ # Version — derived from package.json so it always reflects the real build,
25
+ # never a hardcoded literal that drifts across releases. Works both in-repo
26
+ # (cli/../package.json) and from an installed copy (package.json bundled next
27
+ # to this script by install.sh). Uses sed only, so no jq dependency.
28
+ get_cli_version() {
29
+ local pkg ver
30
+ for pkg in "$SCRIPT_DIR/../package.json" "$SCRIPT_DIR/package.json"; do
31
+ if [ -f "$pkg" ]; then
32
+ ver="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$pkg" | head -n1)"
33
+ if [ -n "$ver" ]; then
34
+ echo "$ver"
35
+ return
36
+ fi
37
+ fi
38
+ done
39
+ echo "unknown"
40
+ }
41
+ VERSION="$(get_cli_version)"
26
42
 
27
43
  # Show version
28
44
  show_version() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "3.6.7",
3
+ "version": "3.8.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": {
@@ -13,7 +13,7 @@
13
13
  "setup": "npm install && pip install -r tools/requirements.txt",
14
14
  "configure": "python tools/server-manager.py",
15
15
  "test-connection": "python tools/test-connection.py",
16
- "test": "npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:lifecycle && npm run test:sync && npm run test:dbquoting && npm run test:dbinjection && npm run test:dbrowcount",
16
+ "test": "npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && 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:dbrowcount",
17
17
  "test:profiles": "node tests/test-profiles.js",
18
18
  "test:aliases": "node tests/test-command-aliases.js",
19
19
  "test:hooks": "node tests/test-hooks.js",
@@ -22,13 +22,18 @@
22
22
  "test:ping": "node tests/test-ssh-ping.js",
23
23
  "test:config": "node tests/test-server-config-manager.js",
24
24
  "test:fieldnames": "node tests/test-config-field-names.js",
25
+ "test:groups": "node tests/test-server-groups.js",
26
+ "test:agentforward": "node tests/test-agent-forward.js",
25
27
  "test:lifecycle": "node tests/test-lifecycle.js",
28
+ "test:tunnel": "node tests/test-tunnel-listen.js",
26
29
  "test:sync": "node tests/test-sync-stats.js",
30
+ "test:sync-path": "node tests/test-rsync-path.js",
27
31
  "test:dbquoting": "node tests/test-database-query-quoting.js",
28
32
  "test:dbinjection": "node tests/test-database-injection.js",
29
33
  "test:dbrowcount": "node tests/test-database-row-count.js",
30
- "test:all": "npm test && ./scripts/validate.sh",
34
+ "test:all": "npm test && npm run typecheck && ./scripts/validate.sh",
31
35
  "validate": "./scripts/validate.sh",
36
+ "typecheck": "tsc -p tsconfig.json",
32
37
  "lint": "eslint src/*.js",
33
38
  "format": "prettier --write 'src/**/*.js' 'tests/**/*.js'"
34
39
  },
@@ -83,16 +88,16 @@
83
88
  "homepage": "https://github.com/bvisible/mcp-ssh-manager#readme",
84
89
  "dependencies": {
85
90
  "@iarna/toml": "^2.2.5",
86
- "@modelcontextprotocol/sdk": "^1.17.2",
91
+ "@modelcontextprotocol/sdk": "^1.30.0",
87
92
  "dotenv": "^16.4.5",
88
93
  "ssh2": "^1.17.0",
89
- "uuid": "^11.1.0",
90
94
  "zod": "^3.25.76"
91
95
  },
92
96
  "devDependencies": {
93
97
  "eslint": "^8.56.0",
94
98
  "knip": "^5.0.0",
95
- "prettier": "^3.2.4"
99
+ "prettier": "^3.2.4",
100
+ "typescript": "^6.0.3"
96
101
  },
97
102
  "engines": {
98
103
  "node": ">=18.0.0"
@@ -419,7 +419,7 @@ export function parseBackupsList(output) {
419
419
  }
420
420
 
421
421
  // Sort by created_at descending
422
- return backups.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
422
+ return backups.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
423
423
  }
424
424
 
425
425
  /**
@@ -6,6 +6,40 @@ import os from 'os';
6
6
  import { logger } from './logger.js';
7
7
  import { VALID_MODES } from './policy.js';
8
8
 
9
+ /**
10
+ * A resolved SSH server configuration, as produced by this loader and consumed
11
+ * by every handler. **Field names are camelCase, always** — the `.env` keys
12
+ * (`SUDO_PASSWORD`) and TOML keys (`sudo_password`) are source syntax and are
13
+ * mapped here; they never survive into a resolved config.
14
+ *
15
+ * This is the contract that broke in issue #49: handlers kept reading the
16
+ * pre-v3.0.0 snake_case names, which silently evaluated to `undefined`. Anything
17
+ * typed as a `ServerConfig` now makes that a type error rather than a runtime
18
+ * no-op. `tests/test-config-field-names.js` guards the same contract at runtime.
19
+ *
20
+ * @typedef {Object} ServerConfig
21
+ * @property {string} name Normalized (lowercased) server name.
22
+ * @property {string} host Hostname or IP address.
23
+ * @property {string} [user] SSH user.
24
+ * @property {string} [password] Password for password authentication.
25
+ * @property {string} [keyPath] Path to the private key (`KEYPATH` / `key_path`).
26
+ * @property {string} [passphrase] Passphrase for a protected private key.
27
+ * @property {number} [port] TCP port; defaults to 22.
28
+ * @property {string} [defaultDir] Working directory used when a tool omits `cwd`.
29
+ * @property {string} [sudoPassword] Password piped to `sudo -S`.
30
+ * @property {string} [description] Free-form description.
31
+ * @property {string} [group] Free-form group label; also feeds server groups.
32
+ * @property {string} [platform] `'linux'` (default) or `'windows'`.
33
+ * @property {string} [proxyJump] Name of another configured server to jump through.
34
+ * @property {string} [proxyCommand] Custom proxy command (`%h` / `%p` placeholders).
35
+ * @property {boolean} [forwardAgent] Forward the local ssh-agent to this server.
36
+ * @property {string} [mode] Security mode: `unrestricted`, `readonly` or `restricted`.
37
+ * @property {string[]} [allowPatterns] Regex sources allowed in `restricted` mode.
38
+ * @property {string[]} [denyPatterns] Regex sources always refused.
39
+ * @property {string} [auditLog] Path to a per-server audit log.
40
+ * @property {'env'|'toml'} [source] Which configuration source won for this server.
41
+ */
42
+
9
43
  // Parse a `;`-separated list of regex pattern strings. Empty entries are dropped.
10
44
  // We do NOT compile here — that happens lazily in policy.js so config-loader stays
11
45
  // free of regex error handling.
@@ -32,9 +66,21 @@ function normalizeMode(raw, serverName) {
32
66
  return normalized;
33
67
  }
34
68
 
69
+ // Parse a boolean-ish config value. Accepts native booleans (TOML) and the
70
+ // strings "true"/"1"/"yes"/"on" (case-insensitive) from .env, where every value
71
+ // is a string. Everything else — "false", "0", "", undefined — is false, so an
72
+ // opt-in flag never turns on by accident.
73
+ function parseBool(raw) {
74
+ if (raw === true) return true;
75
+ if (typeof raw !== 'string') return false;
76
+ return ['true', '1', 'yes', 'on'].includes(raw.trim().toLowerCase());
77
+ }
78
+
35
79
  export class ConfigLoader {
36
80
  constructor() {
81
+ /** @type {Map<string, ServerConfig>} */
37
82
  this.servers = new Map();
83
+ /** @type {string|null} */
38
84
  this.configSource = null;
39
85
  }
40
86
 
@@ -43,6 +89,8 @@ export class ConfigLoader {
43
89
  * 1. Environment variables (highest priority)
44
90
  * 2. .env file
45
91
  * 3. TOML config file (lowest priority)
92
+ *
93
+ * @returns {Promise<Map<string, ServerConfig>>}
46
94
  */
47
95
  async load(options = {}) {
48
96
  const {
@@ -135,9 +183,11 @@ export class ConfigLoader {
135
183
  defaultDir: serverConfig.default_dir || serverConfig.default_directory || serverConfig.cwd,
136
184
  sudoPassword: serverConfig.sudo_password,
137
185
  description: serverConfig.description,
186
+ group: serverConfig.group,
138
187
  platform: serverConfig.platform ? serverConfig.platform.toLowerCase() : undefined,
139
188
  proxyJump: serverConfig.proxy_jump,
140
189
  proxyCommand: serverConfig.proxy_command || serverConfig.proxycommand,
190
+ forwardAgent: parseBool(serverConfig.forward_agent),
141
191
  mode,
142
192
  allowPatterns: tomlAllow,
143
193
  denyPatterns: tomlDeny,
@@ -194,6 +244,7 @@ export class ConfigLoader {
194
244
  );
195
245
  }
196
246
 
247
+ /** @type {ServerConfig} */
197
248
  const server = {
198
249
  name: serverName,
199
250
  host: value,
@@ -205,9 +256,11 @@ export class ConfigLoader {
205
256
  defaultDir: env[`SSH_SERVER_${match[1]}_DEFAULT_DIR`],
206
257
  sudoPassword: env[`SSH_SERVER_${match[1]}_SUDO_PASSWORD`],
207
258
  description: env[`SSH_SERVER_${match[1]}_DESCRIPTION`],
259
+ group: env[`SSH_SERVER_${match[1]}_GROUP`],
208
260
  platform: (env[`SSH_SERVER_${match[1]}_PLATFORM`] || '').toLowerCase() || undefined,
209
261
  proxyJump: env[`SSH_SERVER_${match[1]}_PROXYJUMP`],
210
262
  proxyCommand: env[`SSH_SERVER_${match[1]}_PROXYCOMMAND`],
263
+ forwardAgent: parseBool(env[`SSH_SERVER_${match[1]}_FORWARD_AGENT`]),
211
264
  mode,
212
265
  allowPatterns: envAllow,
213
266
  denyPatterns: envDeny,
@@ -223,6 +276,9 @@ export class ConfigLoader {
223
276
 
224
277
  /**
225
278
  * Get server configuration by name
279
+ *
280
+ * @param {string} name
281
+ * @returns {ServerConfig|undefined}
226
282
  */
227
283
  getServer(name) {
228
284
  return this.servers.get(name.toLowerCase());
@@ -230,6 +286,8 @@ export class ConfigLoader {
230
286
 
231
287
  /**
232
288
  * Get all server configurations
289
+ *
290
+ * @returns {ServerConfig[]}
233
291
  */
234
292
  getAllServers() {
235
293
  return Array.from(this.servers.values());
@@ -263,9 +321,12 @@ export class ConfigLoader {
263
321
  if (server.defaultDir) serverConfig.default_dir = server.defaultDir;
264
322
  if (server.sudoPassword) serverConfig.sudo_password = server.sudoPassword;
265
323
  if (server.description) serverConfig.description = server.description;
324
+ if (server.group) serverConfig.group = server.group;
266
325
  if (server.platform) serverConfig.platform = server.platform;
267
326
  if (server.proxyJump) serverConfig.proxy_jump = server.proxyJump;
268
327
  if (server.proxyCommand) serverConfig.proxy_command = server.proxyCommand;
328
+ // Only emit when opted in, so generated TOML stays clean by default.
329
+ if (server.forwardAgent) serverConfig.forward_agent = true;
269
330
  // Only emit security fields if they diverge from defaults — keeps generated
270
331
  // TOML files clean for users who never opted in.
271
332
  if (server.mode && server.mode !== 'unrestricted') serverConfig.mode = server.mode;
@@ -303,6 +364,9 @@ export class ConfigLoader {
303
364
  if (server.defaultDir) lines.push(`SSH_SERVER_${upperName}_DEFAULT_DIR=${server.defaultDir}`);
304
365
  if (server.sudoPassword) lines.push(`SSH_SERVER_${upperName}_SUDO_PASSWORD="${server.sudoPassword}"`);
305
366
  if (server.description) lines.push(`SSH_SERVER_${upperName}_DESCRIPTION="${server.description}"`);
367
+ // Quoted like DESCRIPTION: free-form text, so an unquoted value would be
368
+ // truncated at the first ` #` when the generated file is read back.
369
+ if (server.group) lines.push(`SSH_SERVER_${upperName}_GROUP="${server.group}"`);
306
370
  if (server.platform) lines.push(`SSH_SERVER_${upperName}_PLATFORM=${server.platform}`);
307
371
  if (server.proxyJump) lines.push(`SSH_SERVER_${upperName}_PROXYJUMP=${server.proxyJump}`);
308
372
  if (server.proxyCommand) lines.push(`SSH_SERVER_${upperName}_PROXYCOMMAND=${server.proxyCommand}`);
@@ -328,6 +392,7 @@ export class ConfigLoader {
328
392
  * Save configuration to Codex TOML format
329
393
  */
330
394
  async saveToCodexConfig(codexConfigPath = path.join(os.homedir(), '.codex', 'config.toml')) {
395
+ /** @type {Record<string, any>} */
331
396
  let config = {};
332
397
 
333
398
  // Load existing config if it exists