@akms/mcp-ssh 0.1.5 → 0.1.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/lib/cli.js CHANGED
@@ -22,11 +22,12 @@ var DEFAULT_MAX_READ_FILE_BYTES = 2e5;
22
22
  var KEEPALIVE_INTERVAL_MS = 15e3;
23
23
  var SESSION_IDLE_TIMEOUT_MS = 15 * 60 * 1e3;
24
24
  var SESSION_SWEEP_INTERVAL_MS = 6e4;
25
+ var SHUTDOWN_DEADLINE_MS = 5e3;
25
26
  var CWD_MARKER = "__AKMS_SSH_CWD__";
26
27
  var MAX_DIRECTORY_ENTRIES = 1e3;
27
28
  var SERVER_NAME = "akms-mcp-ssh";
28
29
  var PACKAGE_NAME = "@akms/mcp-ssh";
29
- var SERVER_VERSION = "0.1.5";
30
+ var SERVER_VERSION = "0.1.6";
30
31
 
31
32
  // src/_defs/command-rules.ts
32
33
  var CRITICAL_PATH_PATTERN = new RegExp(
@@ -489,6 +490,10 @@ var LEVEL_WEIGHTS = {
489
490
  error: 4
490
491
  };
491
492
  var SECRET_META_KEYS = ["password", "passphrase", "privatekey", "privatekeypath", "secret", "token"];
493
+ var stderrBroken = false;
494
+ process.stderr.on("error", () => {
495
+ stderrBroken = true;
496
+ });
492
497
  function resolveThreshold() {
493
498
  const configured = process.env[LOG_LEVEL_ENV];
494
499
  if (configured == null) {
@@ -512,6 +517,9 @@ function maskMeta(meta) {
512
517
  return masked;
513
518
  }
514
519
  function write(level, message, meta) {
520
+ if (stderrBroken == true) {
521
+ return;
522
+ }
515
523
  const threshold = resolveThreshold();
516
524
  if (threshold === "silent") {
517
525
  return;
@@ -525,8 +533,12 @@ function write(level, message, meta) {
525
533
  if (Object.keys(masked).length > 0) {
526
534
  line += ` ${JSON.stringify(masked)}`;
527
535
  }
528
- process.stderr.write(`${line}
536
+ try {
537
+ process.stderr.write(`${line}
529
538
  `);
539
+ } catch {
540
+ stderrBroken = true;
541
+ }
530
542
  }
531
543
  function createLogger(boundMeta) {
532
544
  return {
@@ -5765,6 +5777,12 @@ async function main() {
5765
5777
  instance.shutdown();
5766
5778
  process.exit(exitCode);
5767
5779
  }
5780
+ process.on("uncaughtException", (error) => {
5781
+ _logger.error(error, "uncaught exception; the server keeps running");
5782
+ });
5783
+ process.on("unhandledRejection", (reason) => {
5784
+ _logger.error(reason, "unhandled rejection; the server keeps running");
5785
+ });
5768
5786
  let shuttingDown = false;
5769
5787
  const shutdown = (signal) => {
5770
5788
  if (shuttingDown == true) {
@@ -5772,6 +5790,10 @@ async function main() {
5772
5790
  }
5773
5791
  shuttingDown = true;
5774
5792
  _logger.info("shutting down", { signal });
5793
+ setTimeout(() => {
5794
+ _logger.warn("shutdown did not finish in time; exiting anyway", { deadline_ms: SHUTDOWN_DEADLINE_MS });
5795
+ process.exit(0);
5796
+ }, SHUTDOWN_DEADLINE_MS).unref();
5775
5797
  instance.shutdown();
5776
5798
  void instance.server.close().finally(() => {
5777
5799
  process.exit(0);
@@ -5791,7 +5813,8 @@ async function main() {
5791
5813
  _logger.info("mcp server ready on stdio", {
5792
5814
  server: SERVER_NAME,
5793
5815
  version: SERVER_VERSION,
5794
- profile: instance.profile?.name ?? null
5816
+ profile: instance.profile?.name ?? null,
5817
+ pid: process.pid
5795
5818
  });
5796
5819
  }
5797
5820
  main().catch((error) => {