mcp-ssh-manager 3.6.4 → 3.6.6
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 +36 -0
- package/README.md +16 -6
- package/docs/images/social-preview.png +0 -0
- package/docs/images/social-preview@2x.png +0 -0
- package/package.json +5 -2
- package/src/database-manager.js +109 -5
- package/src/index.js +18 -15
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ 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.6.6] - 2026-07-11
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Handlers read stale snake_case config fields that `ConfigLoader` no longer produces** ([#49](https://github.com/bvisible/mcp-ssh-manager/issues/49) — thanks [@egoan82](https://github.com/egoan82) for the excellent root-cause report; fixed in [#50](https://github.com/bvisible/mcp-ssh-manager/pull/50))
|
|
13
|
+
- Since the v3.0.0 ConfigLoader refactor, resolved server configs expose **camelCase** fields (`sudoPassword`, `defaultDir`, `keyPath`), but several handlers still read the pre-3.0 snake_case/lowercase names — always `undefined`, so their fallback branches silently never ran:
|
|
14
|
+
- `ssh_execute_sudo` ignored the configured `SUDO_PASSWORD` → `sudo: a terminal is required to authenticate` on hosts without a TTY on the exec channel
|
|
15
|
+
- `ssh_execute` / `ssh_group_execute` / `ssh_execute_sudo` ignored `DEFAULT_DIR` — commands silently ran in `$HOME`
|
|
16
|
+
- `ssh_list_servers` always reported an empty `defaultDir`
|
|
17
|
+
- `ssh_sync` never passed the configured SSH key to rsync (`-i` / `BatchMode=yes`), falling back to whatever default key the agent offered
|
|
18
|
+
- No configuration change required: `.env`/TOML source keys (`SUDO_PASSWORD`, `default_dir`, `key_path`, …) are unchanged — existing configs simply start working again.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- Regression test `tests/test-config-field-names.js` (`npm run test:fieldnames`, part of `npm test`): locks the ConfigLoader's output field names from both `.env` and TOML sources, and statically forbids stale `.sudo_password` / `.default_dir` / `.keypath` access in `src/`.
|
|
23
|
+
|
|
24
|
+
## [3.6.5] - 2026-06-30
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
|
|
28
|
+
- **`ssh_db_query` could execute arbitrary shell commands on the remote host** ([#44](https://github.com/bvisible/mcp-ssh-manager/pull/44) — thanks [@technophile77](https://github.com/technophile77))
|
|
29
|
+
- The query builders interpolated the raw query into a **double-quoted** shell string (`mysql -e "${query}"`, `psql -c "${query}"`, `mongo --eval "${query}"`), so the remote shell evaluated backticks `` `…` `` and `$(…)`/`$VAR` **before** the database engine ever saw the query. The "SELECT-only" tool could therefore run shell commands on the target server (e.g. `` SELECT `id` `` / `SELECT '$(id)'`).
|
|
30
|
+
- The query is now delivered to `mysql`/`psql`/`mongo` on **stdin via a single-quoted heredoc** (`<<'__MCP_SQL_EOF__'`), so the remote shell never parses it — only the database engine interprets the SQL/JS. A shared `buildHeredoc()` helper keeps the existing `awk` JSON-wrapper pipe on the heredoc opening line (MySQL JSON output is byte-for-byte unchanged) and defensively rejects a delimiter collision. `isSafeQuery()` is intentionally left as-is, since the heredoc — not keyword filtering — closes the injection path.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- **`ssh_db_query` (MySQL) silently corrupted backtick-quoted identifiers** ([#44](https://github.com/bvisible/mcp-ssh-manager/pull/44) — thanks [@technophile77](https://github.com/technophile77))
|
|
35
|
+
- The same shell-evaluation bug meant any query using backtick identifiers — hyphenated database names, cross-database joins, reserved-word columns — was rewritten by the shell and returned empty/incorrect results **with no error**. The stdin heredoc fix above restores these queries verbatim.
|
|
36
|
+
- **`ssh_db_query` reported `row_count` off by one** ([#45](https://github.com/bvisible/mcp-ssh-manager/pull/45) — thanks [@technophile77](https://github.com/technophile77))
|
|
37
|
+
- The handler reported `output.split('\n').length`, which counted cosmetic lines (the leading `[` of the MySQL JSON wrapper, psql header/separator lines) rather than result rows: 1 row → `2`, 13 rows → `14`, 0 rows → `2`. A new `countQueryRows()` derives the count from each engine's actual output structure — MySQL JSON `{"row":N,…}` entries, MySQL `--batch` lines, psql's authoritative `(N rows)` footer (with a header/separator fallback), and MongoDB `printjson` documents — so empty output is `0` and the count tracks real rows.
|
|
38
|
+
|
|
39
|
+
### Tests
|
|
40
|
+
|
|
41
|
+
- **New `tests/test-database-query-quoting.js`** (`test:dbquoting`) — verifies the SQL/JS query text is carried verbatim on stdin for all three builders (never via `-e "`/`-c "`/`--eval "`), that the `awk` pipe stays on the heredoc opening line with the terminator alone, that `buildHeredoc` rejects a delimiter collision, and a stochastic round-trip of 500 random shell-metacharacter queries.
|
|
42
|
+
- **New `tests/test-database-row-count.js`** (`test:dbrowcount`) — covers the exact issue cases (MySQL 0/1/13 rows), a look-alike `{"row":` value inside a cell, MySQL text format, psql `(N rows)`/`(1 row)`/`(0 rows)` footers and the no-footer fallback, MongoDB single/multi-document counting, and empty/whitespace → `0`.
|
|
43
|
+
|
|
8
44
|
## [3.6.4] - 2026-06-18
|
|
9
45
|
|
|
10
46
|
### Changed
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
|
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/mcp-ssh-manager)
|
|
8
8
|
[](https://www.npmjs.com/package/mcp-ssh-manager)
|
|
9
|
-
[](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.6.6)
|
|
10
10
|
[](https://claude.ai/code)
|
|
11
11
|
[](https://openai.com/codex)
|
|
12
12
|
[](https://modelcontextprotocol.io)
|
|
@@ -20,19 +20,29 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
## 🎉 What's New in v3.6.
|
|
23
|
+
## 🎉 What's New in v3.6.6
|
|
24
24
|
|
|
25
|
-
**
|
|
25
|
+
**Bugfix: per-server `SUDO_PASSWORD`, `DEFAULT_DIR` and `ssh_sync` key auth work again** (Released: July 11, 2026)
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- **🔑 `ssh_execute_sudo` respects the configured `SSH_SERVER_<NAME>_SUDO_PASSWORD` again** ([#49](https://github.com/bvisible/mcp-ssh-manager/issues/49) — thanks [@egoan82](https://github.com/egoan82) for the excellent root-cause report) — since the v3.0.0 ConfigLoader refactor, resolved server configs expose **camelCase** fields (`sudoPassword`), but the handler still read the pre-3.0 snake_case name (`sudo_password`), which is always `undefined`. Non-interactive sudo therefore failed with `sudo: a terminal is required to authenticate` unless the password was passed explicitly on every call.
|
|
28
|
+
- **📁 Same mismatch, same fix for `DEFAULT_DIR` and `ssh_sync` key auth** ([#50](https://github.com/bvisible/mcp-ssh-manager/pull/50)) — `ssh_execute`, `ssh_group_execute` and `ssh_execute_sudo` silently ignored the configured default directory (commands ran in `$HOME`), `ssh_list_servers` always reported an empty `defaultDir`, and `ssh_sync` never passed the configured SSH key to rsync (`-i` / `BatchMode=yes`).
|
|
29
|
+
- **🧪 Regression-proofed** — a new test locks the ConfigLoader's output field names (from both `.env` and TOML) and statically forbids stale snake_case field access in `src/`.
|
|
30
|
+
- **No configuration change required** — your `.env`/TOML keys are unchanged; existing configs simply start working again.
|
|
29
31
|
|
|
30
|
-
[Read full changelog →](CHANGELOG.md#
|
|
32
|
+
[Read full changelog →](CHANGELOG.md#366---2026-07-11)
|
|
31
33
|
|
|
32
34
|
---
|
|
33
35
|
|
|
34
36
|
## Previous Releases
|
|
35
37
|
|
|
38
|
+
### v3.6.5 - `ssh_db_query` shell-injection security fix + real row_count (June 30, 2026)
|
|
39
|
+
|
|
40
|
+
- **🔒 Queries are delivered on stdin via a single-quoted heredoc** ([#44](https://github.com/bvisible/mcp-ssh-manager/pull/44), [#45](https://github.com/bvisible/mcp-ssh-manager/pull/45) — thanks [@technophile77](https://github.com/technophile77)) — the remote shell no longer parses backticks/`$(…)` inside queries (which corrupted backtick identifiers **and** let the "SELECT-only" tool run arbitrary shell commands), and `row_count` now reflects each engine's real output instead of counting wrapper lines. [Full changelog →](CHANGELOG.md#365---2026-06-30)
|
|
41
|
+
|
|
42
|
+
### v3.6.4 - Internal cleanup + a dead-code quality gate (June 18, 2026)
|
|
43
|
+
|
|
44
|
+
- **🧹 Dead-code removal (−343 lines), zero behavioral change** — removed 27 unused exports and 2 duplicate exports; the MCP server and CLI behave identically (command builders/parsers byte-identical, all 37 tools verified end-to-end). A calibrated `knip.json` plus a **blocking** `knip` CI step keep unused code from creeping back. [Full changelog →](CHANGELOG.md#364---2026-06-18)
|
|
45
|
+
|
|
36
46
|
### v3.6.3 - `ssh_sync` reports the real transfer count (June 18, 2026)
|
|
37
47
|
|
|
38
48
|
- **📊 No more false "No files needed to be transferred"** ([#42](https://github.com/bvisible/mcp-ssh-manager/pull/42) — thanks [@MakksSh](https://github.com/MakksSh)) — fixed rsync `--stats` parsing: `--stats` is always passed now, and rsync 2.x/3.x wording, openrsync's `B` suffix, and locale separators are all handled. [Full changelog →](CHANGELOG.md#363---2026-06-18)
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-ssh-manager",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.6",
|
|
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:lifecycle && npm run test:sync",
|
|
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: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",
|
|
@@ -21,8 +21,11 @@
|
|
|
21
21
|
"test:policy": "node tests/test-policy.js",
|
|
22
22
|
"test:ping": "node tests/test-ssh-ping.js",
|
|
23
23
|
"test:config": "node tests/test-server-config-manager.js",
|
|
24
|
+
"test:fieldnames": "node tests/test-config-field-names.js",
|
|
24
25
|
"test:lifecycle": "node tests/test-lifecycle.js",
|
|
25
26
|
"test:sync": "node tests/test-sync-stats.js",
|
|
27
|
+
"test:dbquoting": "node tests/test-database-query-quoting.js",
|
|
28
|
+
"test:dbrowcount": "node tests/test-database-row-count.js",
|
|
26
29
|
"test:all": "npm test && ./scripts/validate.sh",
|
|
27
30
|
"validate": "./scripts/validate.sh",
|
|
28
31
|
"lint": "eslint src/*.js",
|
package/src/database-manager.js
CHANGED
|
@@ -339,6 +339,41 @@ export function buildMongoDBListCollectionsCommand(options) {
|
|
|
339
339
|
return command;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Build a single-quoted shell heredoc that carries `body` to a command's stdin.
|
|
344
|
+
*
|
|
345
|
+
* The delimiter is single-quoted (`<<'DELIM'`) so the remote shell takes the body
|
|
346
|
+
* literally — backticks, `$VAR`, and `$(...)` inside `body` are never expanded by the
|
|
347
|
+
* shell. This is how SQL/JS query text is delivered to mysql/psql/mongo without the
|
|
348
|
+
* shell parsing it first (the cause of issue #44: corruption of backtick-quoted
|
|
349
|
+
* identifiers and remote command injection).
|
|
350
|
+
*
|
|
351
|
+
* When the command pipes its stdout onward (e.g. `mysql ... | awk ...`), the pipe must
|
|
352
|
+
* stay on the heredoc's opening line — the terminator has to be alone on its own line —
|
|
353
|
+
* so the pipeline is passed via `options.pipeline` and emitted as `<<'DELIM' | awk ...`.
|
|
354
|
+
*
|
|
355
|
+
* @param body Text fed to the command's stdin (e.g. a SQL statement). Passed verbatim.
|
|
356
|
+
* @param options.delimiter Heredoc terminator. Must not appear as a standalone line in
|
|
357
|
+
* `body`, otherwise the heredoc would end early; this is rejected defensively.
|
|
358
|
+
* @param options.pipeline Shell pipeline appended after the heredoc marker on the
|
|
359
|
+
* opening line (e.g. `"| awk '...'"`). Omit for a plain stdin redirect.
|
|
360
|
+
* @returns The redirection fragment to append after a command, ending with the
|
|
361
|
+
* terminator on its own line.
|
|
362
|
+
* @throws {Error} If a line of `body` equals `delimiter`.
|
|
363
|
+
* @example
|
|
364
|
+
* `mysql app${buildHeredoc('SELECT 1')}`
|
|
365
|
+
* // mysql app <<'__MCP_SQL_EOF__'\nSELECT 1\n__MCP_SQL_EOF__
|
|
366
|
+
* @see buildMySQLQueryCommand
|
|
367
|
+
*/
|
|
368
|
+
export function buildHeredoc(body, { delimiter = '__MCP_SQL_EOF__', pipeline = '' } = {}) {
|
|
369
|
+
const text = body == null ? '' : String(body);
|
|
370
|
+
if (text.split('\n').some(line => line === delimiter)) {
|
|
371
|
+
throw new Error(`Query contains the heredoc delimiter "${delimiter}" on its own line`);
|
|
372
|
+
}
|
|
373
|
+
const suffix = pipeline ? ` ${pipeline}` : '';
|
|
374
|
+
return ` <<'${delimiter}'${suffix}\n${text}\n${delimiter}`;
|
|
375
|
+
}
|
|
376
|
+
|
|
342
377
|
/**
|
|
343
378
|
* Build MySQL query command (SELECT only)
|
|
344
379
|
*/
|
|
@@ -357,11 +392,16 @@ export function buildMySQLQueryCommand(options) {
|
|
|
357
392
|
if (port) command += ` -P ${port}`;
|
|
358
393
|
command += ` ${database}`;
|
|
359
394
|
|
|
395
|
+
// Feed the SQL via stdin (quoted heredoc) so the remote shell never parses it —
|
|
396
|
+
// backtick-quoted identifiers and `$` survive intact, and query text cannot inject
|
|
397
|
+
// shell commands. See buildHeredoc and issue #44.
|
|
360
398
|
if (format === 'json') {
|
|
361
|
-
// Use JSON output if MySQL 5.7.8
|
|
362
|
-
|
|
399
|
+
// Use JSON output if MySQL 5.7.8+. The awk pipe stays on the heredoc opening line so
|
|
400
|
+
// the terminator remains alone on its own line.
|
|
401
|
+
const awk = 'awk \'BEGIN{print "["} {if(NR>1)print ","; printf "{\\"row\\":%d,\\"data\\":\\"%s\\"}", NR, $0} END{print "]"}\'';
|
|
402
|
+
command += ` --batch --skip-column-names${buildHeredoc(query, { pipeline: `| ${awk}` })}`;
|
|
363
403
|
} else {
|
|
364
|
-
command +=
|
|
404
|
+
command += buildHeredoc(query);
|
|
365
405
|
}
|
|
366
406
|
|
|
367
407
|
return command;
|
|
@@ -387,7 +427,9 @@ export function buildPostgreSQLQueryCommand(options) {
|
|
|
387
427
|
if (host) command += ` -h ${host}`;
|
|
388
428
|
if (port) command += ` -p ${port}`;
|
|
389
429
|
command += ` -d ${database}`;
|
|
390
|
-
|
|
430
|
+
// Feed SQL via stdin (quoted heredoc) instead of `-c "${query}"` so the remote shell
|
|
431
|
+
// never parses it. See buildHeredoc and issue #44.
|
|
432
|
+
command += buildHeredoc(query);
|
|
391
433
|
|
|
392
434
|
return command;
|
|
393
435
|
}
|
|
@@ -404,7 +446,11 @@ export function buildMongoDBQueryCommand(options) {
|
|
|
404
446
|
if (user) command += ` --username ${user}`;
|
|
405
447
|
if (password) command += ` --password '${password}'`;
|
|
406
448
|
command += ` ${database}`;
|
|
407
|
-
|
|
449
|
+
// Feed the JS script via stdin (quoted heredoc) instead of `--eval "..."` so the
|
|
450
|
+
// remote shell never expands backticks/`$` in the query. mongo still evaluates the
|
|
451
|
+
// script as JavaScript (expected). See buildHeredoc and issue #44.
|
|
452
|
+
const script = `db.${collection}.find(${query || '{}'}).forEach(printjson)`;
|
|
453
|
+
command += ` --quiet${buildHeredoc(script)}`;
|
|
408
454
|
|
|
409
455
|
return command;
|
|
410
456
|
}
|
|
@@ -435,6 +481,64 @@ export function isSafeQuery(query) {
|
|
|
435
481
|
return true;
|
|
436
482
|
}
|
|
437
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Count the actual result rows in the raw output of an `ssh_db_query` command.
|
|
486
|
+
*
|
|
487
|
+
* The handler previously reported `output.split('\n').length`, which counts cosmetic
|
|
488
|
+
* lines (the leading `[` of the MySQL JSON wrapper, psql headers/separators) rather than
|
|
489
|
+
* data rows — so it was off by one for MySQL and over-counted for psql (issue #45). This
|
|
490
|
+
* derives the count from the structure each engine actually produces.
|
|
491
|
+
*
|
|
492
|
+
* @param output Raw, already-trimmed stdout of the query command.
|
|
493
|
+
* @param type One of {@link DB_TYPES} (`'mysql' | 'postgresql' | 'mongodb'`).
|
|
494
|
+
* @param format Output format used to build the command; only `'json'` MySQL is wrapped
|
|
495
|
+
* by the `awk` JSON formatter, which is what this counts. Defaults to `'json'`.
|
|
496
|
+
* @returns The number of result rows (documents for MongoDB). `0` for empty output.
|
|
497
|
+
* @example
|
|
498
|
+
* countQueryRows('[\n{"row":1,"data":"a"},\n{"row":2,"data":"b"}]', 'mysql') // => 2
|
|
499
|
+
* countQueryRows(' id \n----\n 1\n(1 row)', 'postgresql') // => 1
|
|
500
|
+
* @see buildMySQLQueryCommand
|
|
501
|
+
*/
|
|
502
|
+
export function countQueryRows(output, type, format = 'json') {
|
|
503
|
+
if (!output || !output.trim()) {
|
|
504
|
+
return 0;
|
|
505
|
+
}
|
|
506
|
+
const lines = output.split('\n');
|
|
507
|
+
|
|
508
|
+
if (type === DB_TYPES.MYSQL) {
|
|
509
|
+
if (format === 'json') {
|
|
510
|
+
// The awk wrapper emits exactly one `{"row":N,...}` entry per result row, anchored
|
|
511
|
+
// at the start of its own line, bracketed by cosmetic `[` / `]` lines.
|
|
512
|
+
return lines.filter(line => /^\{"row":\d+,/.test(line)).length;
|
|
513
|
+
}
|
|
514
|
+
// Tabular `--batch` output: one row per non-empty line (column names are suppressed).
|
|
515
|
+
return lines.filter(line => line.trim() !== '').length;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (type === DB_TYPES.POSTGRESQL) {
|
|
519
|
+
// psql prints an authoritative footer like `(13 rows)` — trust it when present.
|
|
520
|
+
const footer = output.match(/\((\d+)\s+rows?\)/);
|
|
521
|
+
if (footer) {
|
|
522
|
+
return Number(footer[1]);
|
|
523
|
+
}
|
|
524
|
+
// Otherwise fall back to the data lines, dropping the column-header line, the
|
|
525
|
+
// `---+---` separator, and any `(N rows)` footer line.
|
|
526
|
+
const dataLines = lines.filter(line => {
|
|
527
|
+
const trimmed = line.trim();
|
|
528
|
+
return trimmed !== '' && !/^[-+\s]+$/.test(trimmed) && !/^\(\d+\s+rows?\)$/.test(trimmed);
|
|
529
|
+
});
|
|
530
|
+
return Math.max(0, dataLines.length - 1); // first remaining line is the header
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (type === DB_TYPES.MONGODB) {
|
|
534
|
+
// `printjson` closes each document with a `}` at column 0 — one per document.
|
|
535
|
+
return lines.filter(line => line === '}').length;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Unknown type: best-effort non-empty line count.
|
|
539
|
+
return lines.filter(line => line.trim() !== '').length;
|
|
540
|
+
}
|
|
541
|
+
|
|
438
542
|
/**
|
|
439
543
|
* Parse database list output
|
|
440
544
|
*/
|
package/src/index.js
CHANGED
|
@@ -132,6 +132,7 @@ import {
|
|
|
132
132
|
buildPostgreSQLQueryCommand,
|
|
133
133
|
buildMongoDBQueryCommand,
|
|
134
134
|
isSafeQuery,
|
|
135
|
+
countQueryRows,
|
|
135
136
|
parseDatabaseList,
|
|
136
137
|
parseTableList,
|
|
137
138
|
parseSize,
|
|
@@ -671,10 +672,10 @@ registerToolConditional(
|
|
|
671
672
|
});
|
|
672
673
|
}
|
|
673
674
|
|
|
674
|
-
// Use provided cwd, or
|
|
675
|
+
// Use provided cwd, or the server's configured defaultDir, or no cwd
|
|
675
676
|
const servers = await loadServerConfig();
|
|
676
677
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
677
|
-
const workingDir = cwd || serverConfig?.
|
|
678
|
+
const workingDir = cwd || serverConfig?.defaultDir;
|
|
678
679
|
const platform = serverConfig?.platform || 'linux';
|
|
679
680
|
|
|
680
681
|
// Build cwd-prefixed command using platform-appropriate syntax
|
|
@@ -897,7 +898,7 @@ registerToolConditional(
|
|
|
897
898
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
898
899
|
|
|
899
900
|
// Check if sshpass is available for password authentication
|
|
900
|
-
if (!serverConfig.
|
|
901
|
+
if (!serverConfig.keyPath && serverConfig.password) {
|
|
901
902
|
// Check if sshpass is installed
|
|
902
903
|
try {
|
|
903
904
|
const { execSync } = await import('child_process');
|
|
@@ -979,12 +980,12 @@ registerToolConditional(
|
|
|
979
980
|
const sshOptions = [];
|
|
980
981
|
|
|
981
982
|
// Different options based on authentication method
|
|
982
|
-
if (serverConfig.
|
|
983
|
+
if (serverConfig.keyPath) {
|
|
983
984
|
sshOptions.push('-o BatchMode=yes'); // No password prompts
|
|
984
985
|
sshOptions.push('-o StrictHostKeyChecking=accept-new'); // Accept new keys, reject changed ones
|
|
985
986
|
sshOptions.push('-o ConnectTimeout=10'); // Connection timeout
|
|
986
987
|
|
|
987
|
-
const keyPath = serverConfig.
|
|
988
|
+
const keyPath = serverConfig.keyPath.replace('~', os.homedir());
|
|
988
989
|
sshOptions.push(`-i ${keyPath}`);
|
|
989
990
|
} else {
|
|
990
991
|
// With sshpass, we don't use BatchMode
|
|
@@ -1892,7 +1893,7 @@ registerToolConditional(
|
|
|
1892
1893
|
// does not support `cd && `) vs cd && for Linux/macOS.
|
|
1893
1894
|
const servers = await loadServerConfig();
|
|
1894
1895
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
1895
|
-
const workingDir = cwd || serverConfig?.
|
|
1896
|
+
const workingDir = cwd || serverConfig?.defaultDir;
|
|
1896
1897
|
const platform = serverConfig?.platform || 'linux';
|
|
1897
1898
|
let fullCommand;
|
|
1898
1899
|
if (workingDir) {
|
|
@@ -2132,7 +2133,7 @@ registerToolConditional(
|
|
|
2132
2133
|
user: config.user,
|
|
2133
2134
|
port: config.port || '22',
|
|
2134
2135
|
auth: config.password ? 'password' : 'key',
|
|
2135
|
-
defaultDir: config.
|
|
2136
|
+
defaultDir: config.defaultDir || '',
|
|
2136
2137
|
description: config.description || ''
|
|
2137
2138
|
}));
|
|
2138
2139
|
|
|
@@ -2293,9 +2294,9 @@ registerToolConditional(
|
|
|
2293
2294
|
// Add password if provided
|
|
2294
2295
|
if (password) {
|
|
2295
2296
|
fullCommand = `echo "${password}" | sudo -S ${command.replace(/^sudo /, '')}`;
|
|
2296
|
-
} else if (serverConfig?.
|
|
2297
|
+
} else if (serverConfig?.sudoPassword) {
|
|
2297
2298
|
// Use configured sudo password if available
|
|
2298
|
-
fullCommand = `echo "${serverConfig.
|
|
2299
|
+
fullCommand = `echo "${serverConfig.sudoPassword}" | sudo -S ${command.replace(/^sudo /, '')}`;
|
|
2299
2300
|
}
|
|
2300
2301
|
|
|
2301
2302
|
// Add working directory if specified
|
|
@@ -2307,12 +2308,12 @@ registerToolConditional(
|
|
|
2307
2308
|
} else {
|
|
2308
2309
|
fullCommand = `cd ${cwd} && ${fullCommand}`;
|
|
2309
2310
|
}
|
|
2310
|
-
} else if (serverConfig?.
|
|
2311
|
+
} else if (serverConfig?.defaultDir) {
|
|
2311
2312
|
if (platform === 'windows') {
|
|
2312
|
-
const escapedDir = serverConfig.
|
|
2313
|
+
const escapedDir = serverConfig.defaultDir.replace(/'/g, '\'\'');
|
|
2313
2314
|
fullCommand = `Set-Location '${escapedDir}'; ${fullCommand}`;
|
|
2314
2315
|
} else {
|
|
2315
|
-
fullCommand = `cd ${serverConfig.
|
|
2316
|
+
fullCommand = `cd ${serverConfig.defaultDir} && ${fullCommand}`;
|
|
2316
2317
|
}
|
|
2317
2318
|
}
|
|
2318
2319
|
|
|
@@ -4783,12 +4784,14 @@ registerToolConditional(
|
|
|
4783
4784
|
|
|
4784
4785
|
// Parse output (basic parsing, output depends on database type)
|
|
4785
4786
|
const output = result.stdout.trim();
|
|
4786
|
-
|
|
4787
|
+
// Derive the real row count from each engine's output structure rather than the
|
|
4788
|
+
// raw line count, which counts cosmetic wrapper/header lines (issue #45).
|
|
4789
|
+
const rowCount = countQueryRows(output, type);
|
|
4787
4790
|
|
|
4788
4791
|
logger.info('Query executed successfully', {
|
|
4789
4792
|
server: serverName,
|
|
4790
4793
|
database,
|
|
4791
|
-
rows:
|
|
4794
|
+
rows: rowCount
|
|
4792
4795
|
});
|
|
4793
4796
|
|
|
4794
4797
|
return {
|
|
@@ -4802,7 +4805,7 @@ registerToolConditional(
|
|
|
4802
4805
|
database,
|
|
4803
4806
|
collection: collection || null,
|
|
4804
4807
|
query,
|
|
4805
|
-
row_count:
|
|
4808
|
+
row_count: rowCount,
|
|
4806
4809
|
output: output,
|
|
4807
4810
|
timestamp: new Date().toISOString()
|
|
4808
4811
|
}, null, 2)
|