@jadchene/mcp-gateway-service 0.1.2 → 0.2.1

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/dist/index.js CHANGED
@@ -15,10 +15,6 @@ class Application {
15
15
  * Stores a shared logger instance.
16
16
  */
17
17
  logger = new Logger();
18
- /**
19
- * Stores the shared config loader instance.
20
- */
21
- configLoader = new ConfigLoader();
22
18
  /**
23
19
  * Stores the config file path in use for the current process.
24
20
  */
@@ -26,7 +22,7 @@ class Application {
26
22
  /**
27
23
  * Stores the runtime service registry.
28
24
  */
29
- registry = new ServiceRegistry(this.configPath, this.configLoader, this.logger);
25
+ registry = new ServiceRegistry(this.configPath, new ConfigLoader(), this.logger);
30
26
  /**
31
27
  * Stores the gateway server bound to stdin/stdout.
32
28
  */
@@ -35,10 +31,12 @@ class Application {
35
31
  * Stores the file watcher used for config hot reload.
36
32
  */
37
33
  watcher = new ConfigFileWatcher(this.configPath, this.logger, async () => {
38
- const config = await this.configLoader.load(this.configPath);
39
- this.logger.setLogDirectory(config.logDirectory ?? process.cwd());
40
34
  await this.registry.reload();
41
35
  });
36
+ /**
37
+ * Prevents duplicate shutdown execution when multiple exit signals arrive.
38
+ */
39
+ shuttingDown = false;
42
40
  /**
43
41
  * Starts the application and registers shutdown hooks.
44
42
  */
@@ -46,8 +44,6 @@ class Application {
46
44
  if (!existsSync(this.configPath)) {
47
45
  throw new Error(`Config file was not found: ${this.configPath}`);
48
46
  }
49
- const initialConfig = await this.configLoader.load(this.configPath);
50
- this.logger.setLogDirectory(initialConfig.logDirectory ?? process.cwd());
51
47
  const startup = this.registry.initialize();
52
48
  this.server.setStartupBarrier(startup);
53
49
  this.server.start();
@@ -63,6 +59,10 @@ class Application {
63
59
  */
64
60
  registerSignals() {
65
61
  const shutdown = async (signal) => {
62
+ if (this.shuttingDown) {
63
+ return;
64
+ }
65
+ this.shuttingDown = true;
66
66
  this.logger.info("gateway.stopping", { signal });
67
67
  this.watcher.stop();
68
68
  await this.registry.dispose();
@@ -70,6 +70,8 @@ class Application {
70
70
  };
71
71
  process.on("SIGINT", () => void shutdown("SIGINT"));
72
72
  process.on("SIGTERM", () => void shutdown("SIGTERM"));
73
+ process.stdin.on("end", () => void shutdown("stdin-end"));
74
+ process.stdin.on("close", () => void shutdown("stdin-close"));
73
75
  }
74
76
  }
75
77
  const application = new Application();
package/dist/logger.js CHANGED
@@ -1,26 +1,7 @@
1
- import { appendFileSync, mkdirSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
1
  /**
4
2
  * Provides a minimal structured logger that writes newline-delimited JSON to stderr.
5
3
  */
6
4
  export class Logger {
7
- /**
8
- * Stores the optional log file path used in addition to stderr.
9
- */
10
- logFilePath = null;
11
- /**
12
- * Tracks whether file logging already failed to avoid repeated fallback noise.
13
- */
14
- fileLoggingErrorReported = false;
15
- /**
16
- * Updates the directory used for the gateway log file.
17
- */
18
- setLogDirectory(directory) {
19
- const absoluteDirectory = resolve(directory);
20
- mkdirSync(absoluteDirectory, { recursive: true });
21
- this.logFilePath = join(absoluteDirectory, "mcp-gateway.log");
22
- this.fileLoggingErrorReported = false;
23
- }
24
5
  /**
25
6
  * Logs one structured event.
26
7
  */
@@ -49,33 +30,6 @@ export class Logger {
49
30
  event,
50
31
  ...details
51
32
  };
52
- const line = `${JSON.stringify(payload)}\n`;
53
- process.stderr.write(line);
54
- this.writeToFile(line);
55
- }
56
- /**
57
- * Appends one log line to the configured log file when file logging is enabled.
58
- */
59
- writeToFile(line) {
60
- if (!this.logFilePath) {
61
- return;
62
- }
63
- try {
64
- appendFileSync(this.logFilePath, line, "utf8");
65
- }
66
- catch (error) {
67
- if (this.fileLoggingErrorReported) {
68
- return;
69
- }
70
- this.fileLoggingErrorReported = true;
71
- const message = error instanceof Error ? error.message : String(error);
72
- process.stderr.write(`${JSON.stringify({
73
- timestamp: new Date().toISOString(),
74
- level: "error",
75
- event: "logger.file_write_failed",
76
- message,
77
- logFilePath: this.logFilePath
78
- })}\n`);
79
- }
33
+ process.stderr.write(`${JSON.stringify(payload)}\n`);
80
34
  }
81
35
  }
@@ -295,14 +295,7 @@ export class StdioMcpClient {
295
295
  const child = this.child;
296
296
  this.child = null;
297
297
  this.writer = null;
298
- try {
299
- child.kill();
300
- }
301
- catch {
302
- /**
303
- * Ignores kill failures because the process may have already exited.
304
- */
305
- }
298
+ terminateChildProcess(child);
306
299
  await waitForChildExit(child);
307
300
  cleanupChildProcess(child);
308
301
  }
@@ -317,7 +310,7 @@ export class StdioMcpClient {
317
310
  },
318
311
  clientInfo: {
319
312
  name: "mcp-gateway",
320
- version: "0.1.2"
313
+ version: "0.2.1"
321
314
  }
322
315
  });
323
316
  if (isRecord(result)) {
@@ -512,6 +505,32 @@ function resolveViaPowerShell(command) {
512
505
  function escapePowerShellSingleQuotedString(value) {
513
506
  return value.replace(/'/g, "''");
514
507
  }
508
+ /**
509
+ * Terminates one child process, using process-tree shutdown on Windows when possible.
510
+ */
511
+ function terminateChildProcess(child) {
512
+ if (process.platform === "win32" && child.pid) {
513
+ try {
514
+ execFileSync("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], {
515
+ stdio: ["ignore", "ignore", "ignore"]
516
+ });
517
+ return;
518
+ }
519
+ catch {
520
+ /**
521
+ * Falls back to normal child termination when taskkill fails.
522
+ */
523
+ }
524
+ }
525
+ try {
526
+ child.kill();
527
+ }
528
+ catch {
529
+ /**
530
+ * Ignores kill failures because the process may have already exited.
531
+ */
532
+ }
533
+ }
515
534
  /**
516
535
  * Waits for one child process to exit and force-kills it if graceful shutdown stalls.
517
536
  */
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "@jadchene/mcp-gateway-service",
3
- "version": "0.1.2",
4
- "description": "A token-efficient MCP gateway that provides one unified entry point for multiple downstream MCP services.",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "bin": {
8
- "mcp-gateway-service": "dist/index.js"
9
- },
10
- "license": "MIT",
11
- "author": "jadchene",
12
- "scripts": {
13
- "build": "tsc -p tsconfig.build.json",
14
- "dev": "node --experimental-strip-types src/index.ts",
15
- "start": "node dist/index.js",
16
- "test": "node --test --experimental-strip-types test/**/*.test.ts",
17
- "version": "node dist/index.js --version",
18
- "prepare": "npm run build",
19
- "prepublishOnly": "npm run build"
20
- },
21
- "files": [
22
- "dist",
23
- "skills",
24
- "config.example.json",
25
- "README.md",
26
- "README_zh.md",
27
- "LICENSE",
28
- "scripts"
29
- ],
30
- "keywords": [
31
- "mcp",
32
- "gateway",
33
- "model context protocol",
34
- "agent",
35
- "token-efficient"
36
- ],
37
- "engines": {
38
- "node": ">=24.0.0"
39
- },
40
- "devDependencies": {
41
- "@types/node": "^24.0.0",
42
- "typescript": "^5.8.0"
43
- }
44
- }
1
+ {
2
+ "name": "@jadchene/mcp-gateway-service",
3
+ "version": "0.2.1",
4
+ "description": "A token-efficient MCP gateway that provides one unified entry point for multiple downstream MCP services.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "mcp-gateway-service": "dist/index.js"
9
+ },
10
+ "license": "MIT",
11
+ "author": "jadchene",
12
+ "scripts": {
13
+ "build": "tsc -p tsconfig.build.json",
14
+ "dev": "node --experimental-strip-types src/index.ts",
15
+ "start": "node dist/index.js",
16
+ "test": "node --test --experimental-strip-types test/**/*.test.ts",
17
+ "version": "node dist/index.js --version",
18
+ "prepare": "npm run build",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "skills",
24
+ "config.example.json",
25
+ "README.md",
26
+ "README_zh.md",
27
+ "LICENSE",
28
+ "scripts"
29
+ ],
30
+ "keywords": [
31
+ "mcp",
32
+ "gateway",
33
+ "model context protocol",
34
+ "agent",
35
+ "token-efficient"
36
+ ],
37
+ "engines": {
38
+ "node": ">=24.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^24.0.0",
42
+ "typescript": "^5.8.0"
43
+ }
44
+ }
@@ -100,10 +100,10 @@ $example = @{
100
100
  mcpServers = @{
101
101
  gateway = @{
102
102
  command = "mcp-gateway-service"
103
- args = @()
104
- env = @{
105
- MCP_GATEWAY_CONFIG = $resolvedConfigPath
106
- }
103
+ args = @(
104
+ "--config",
105
+ $resolvedConfigPath
106
+ )
107
107
  }
108
108
  }
109
109
  } | ConvertTo-Json -Depth 6