@jadchene/mcp-gateway-service 0.1.1 → 0.1.2

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
@@ -140,8 +140,11 @@ mcp-gateway-service -v
140
140
 
141
141
  The gateway currently supports `stdio` downstream transports only.
142
142
 
143
+ A gateway log file is written to `mcp-gateway.log` under `logDirectory`. If `logDirectory` is omitted, the gateway writes logs to the current working directory.
144
+
143
145
  A service is loaded only when `enable` is missing or set to `true`. If `enable` is set to `false`, the gateway skips that service entirely. During hot reload, disabling or removing a service also stops its existing downstream process if one is running.
144
146
 
147
+ - `logDirectory` is optional. When omitted, the gateway writes `mcp-gateway.log` to the current working directory.
145
148
  - `enable` is optional. When omitted, the gateway treats the service as enabled.
146
149
  - `cwd` is optional. When omitted, the gateway uses its current working directory.
147
150
  - `env` is optional.
@@ -151,6 +154,7 @@ A service is loaded only when `enable` is missing or set to `true`. If `enable`
151
154
 
152
155
  ```json
153
156
  {
157
+ "logDirectory": "./logs",
154
158
  "services": [
155
159
  {
156
160
  "serviceId": "demo-echo",
@@ -271,4 +275,4 @@ args = ["--config", "./config.json"]
271
275
 
272
276
  ## License
273
277
 
274
- Released under the [MIT License](./LICENSE).
278
+ Released under the [MIT License](./LICENSE).
package/README_zh.md CHANGED
@@ -146,8 +146,11 @@ mcp-gateway-service -v
146
146
 
147
147
  当前只支持 `stdio` 类型的下游传输。
148
148
 
149
+ 网关会把日志写到 `logDirectory` 目录下的 `mcp-gateway.log`。如果没有配置 `logDirectory`,默认写到当前工作目录。
150
+
149
151
  只有当 `enable` 未填写或显式为 `true` 时,服务才会被加载;如果 `enable` 为 `false`,网关会跳过该服务。热刷新时,如果某个服务被禁用或从配置中删除,网关也会停掉它当前已启动的下游进程。
150
152
 
153
+ - `logDirectory` 可选,不填时会把 `mcp-gateway.log` 写到当前工作目录
151
154
  - `enable` 可选,不填时默认按启用处理
152
155
  - `cwd` 可选,不填时使用当前工作目录
153
156
  - `env` 可选
@@ -155,6 +158,7 @@ mcp-gateway-service -v
155
158
 
156
159
  ```json
157
160
  {
161
+ "logDirectory": "./logs",
158
162
  "services": [
159
163
  {
160
164
  "serviceId": "demo-echo",
@@ -273,4 +277,4 @@ args = ["--config", "./config.json"]
273
277
 
274
278
  ## License
275
279
 
276
- 项目采用 [MIT License](./LICENSE) 开源。
280
+ 项目采用 [MIT License](./LICENSE) 开源。
@@ -1,4 +1,5 @@
1
1
  {
2
+ "logDirectory": "./logs",
2
3
  "services": [
3
4
  {
4
5
  "serviceId": "demo-echo",
@@ -15,4 +16,4 @@
15
16
  }
16
17
  }
17
18
  ]
18
- }
19
+ }
package/dist/config.js CHANGED
@@ -21,6 +21,7 @@ export function validateGatewayConfig(input) {
21
21
  if (!isRecord(input)) {
22
22
  throw new Error("The gateway config must be a JSON object.");
23
23
  }
24
+ const logDirectory = optionalString(input.logDirectory, "logDirectory");
24
25
  if (!Array.isArray(input.services)) {
25
26
  throw new Error("The 'services' field must be an array.");
26
27
  }
@@ -33,6 +34,7 @@ export function validateGatewayConfig(input) {
33
34
  seenServiceIds.add(service.serviceId);
34
35
  }
35
36
  return {
37
+ logDirectory,
36
38
  services: services.filter((service) => service.enable)
37
39
  };
38
40
  }
@@ -187,7 +187,7 @@ export class GatewayServer {
187
187
  },
188
188
  serverInfo: {
189
189
  name: "mcp-gateway",
190
- version: "0.1.1"
190
+ version: "0.1.2"
191
191
  }
192
192
  };
193
193
  }
package/dist/index.js CHANGED
@@ -15,6 +15,10 @@ 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();
18
22
  /**
19
23
  * Stores the config file path in use for the current process.
20
24
  */
@@ -22,7 +26,7 @@ class Application {
22
26
  /**
23
27
  * Stores the runtime service registry.
24
28
  */
25
- registry = new ServiceRegistry(this.configPath, new ConfigLoader(), this.logger);
29
+ registry = new ServiceRegistry(this.configPath, this.configLoader, this.logger);
26
30
  /**
27
31
  * Stores the gateway server bound to stdin/stdout.
28
32
  */
@@ -31,6 +35,8 @@ class Application {
31
35
  * Stores the file watcher used for config hot reload.
32
36
  */
33
37
  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());
34
40
  await this.registry.reload();
35
41
  });
36
42
  /**
@@ -40,6 +46,8 @@ class Application {
40
46
  if (!existsSync(this.configPath)) {
41
47
  throw new Error(`Config file was not found: ${this.configPath}`);
42
48
  }
49
+ const initialConfig = await this.configLoader.load(this.configPath);
50
+ this.logger.setLogDirectory(initialConfig.logDirectory ?? process.cwd());
43
51
  const startup = this.registry.initialize();
44
52
  this.server.setStartupBarrier(startup);
45
53
  this.server.start();
package/dist/logger.js CHANGED
@@ -1,7 +1,26 @@
1
+ import { appendFileSync, mkdirSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
1
3
  /**
2
4
  * Provides a minimal structured logger that writes newline-delimited JSON to stderr.
3
5
  */
4
6
  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
+ }
5
24
  /**
6
25
  * Logs one structured event.
7
26
  */
@@ -30,6 +49,33 @@ export class Logger {
30
49
  event,
31
50
  ...details
32
51
  };
33
- process.stderr.write(`${JSON.stringify(payload)}\n`);
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
+ }
34
80
  }
35
81
  }
@@ -317,7 +317,7 @@ export class StdioMcpClient {
317
317
  },
318
318
  clientInfo: {
319
319
  name: "mcp-gateway",
320
- version: "0.1.1"
320
+ version: "0.1.2"
321
321
  }
322
322
  });
323
323
  if (isRecord(result)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jadchene/mcp-gateway-service",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A token-efficient MCP gateway that provides one unified entry point for multiple downstream MCP services.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",