@jadchene/mcp-gateway-service 0.6.5 → 0.7.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/README_zh.md CHANGED
@@ -1,188 +1,196 @@
1
- [English](./README.md) | 简体中文
2
-
3
- # MCP Gateway
4
-
5
- ## 简介
6
-
7
- MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent 连接网关后只会看到 6 个路由工具,具体的下游服务、工具和 schema 在需要时再查询。
8
-
9
- 项目使用官方 TypeScript SDK v2,需要 Node.js 24 或更高版本。
10
-
11
- > [!IMPORTANT]
12
- > MCP Gateway v0.6.2 及后续版本仅接受 MCP `2026-07-28`、`2025-11-25` 和 `2025-06-18`。传输方式仅支持换行分隔 stdio 和单端点 Streamable HTTP。不支持独立 HTTP+SSE(`/sse`)、`Content-Length` framing 和其他协议版本。
13
-
14
- ## 为什么使用
15
-
16
- - 即使配置了很多 MCP 服务,也不会一次性占用大量 Agent 上下文。
17
- - Agent 只需接入一次,后续增减下游服务只改网关配置。
18
- - 可以按名称或描述查找工具,需要时再读取 schema。
19
- - Stdio 和 Streamable HTTP 服务使用同一套调用方式。
20
- - 修改配置文件后自动重载,不必重启网关。
21
-
22
- ## 快速开始
23
-
24
- ### 安装
25
-
26
- ```bash
27
- npm install -g @jadchene/mcp-gateway-service
28
- ```
29
-
30
- 创建 `config.json`,将 `your-mcp-service` 替换为已经安装的 MCP 服务命令:
31
-
32
- ```json
33
- {
34
- "services": [
35
- {
36
- "serviceId": "tools",
37
- "name": "Tools",
38
- "transport": {
39
- "type": "stdio",
40
- "command": "your-mcp-service"
41
- }
42
- }
43
- ]
44
- }
45
- ```
46
-
47
- ### Stdio
48
-
49
- 网关进程由 Agent 启动,不需要单独运行启动命令。
50
-
51
- Codex `config.toml`:
52
-
53
- ```toml
54
- [mcp_servers.gateway]
55
- command = "mcp-gateway-service"
56
- args = ["--config", "./config.json"]
57
- ```
58
-
59
- Claude Code:
60
-
61
- ```bash
62
- claude mcp add gateway -- mcp-gateway-service --config ./config.json
63
- ```
64
-
65
- ### Streamable HTTP
66
-
67
- 启动网关:
68
-
69
- ```bash
70
- mcp-gateway-service --http --config ./config.json
71
- ```
72
-
73
- 默认地址为 `http://127.0.0.1:3000/mcp`。
74
-
75
- Codex `config.toml`:
76
-
77
- ```toml
78
- [mcp_servers.gateway]
79
- url = "http://127.0.0.1:3000/mcp"
80
- ```
81
-
82
- Claude Code:
83
-
84
- ```bash
85
- claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
86
- ```
87
-
88
- ## 配置与工具
89
-
90
- ### 启动参数
91
-
92
- | 参数 | 说明 | 默认值 |
93
- | --- | --- | --- |
94
- | `--config <path>` | 配置文件路径。 | `MCP_GATEWAY_CONFIG`,其次为 `./config.json` |
95
- | `--http` | 启用 Streamable HTTP。 | 不启用 |
96
- | `--host <host>` | HTTP 监听地址。 | `127.0.0.1` |
97
- | `--port <port>` | HTTP 监听端口。 | `3000` |
98
- | `--path <path>` | HTTP endpoint 路径。 | `/mcp` |
99
- | `--version`、`-v` | 输出已安装版本。 | — |
100
-
101
- 启用 `--http` 后,stdio 入口仍然可用。
102
-
103
- ### 配置文件
104
-
105
- ```json
106
- {
107
- "logging": {
108
- "enable": false,
109
- "path": "./logs/mcp-gateway.log"
110
- },
111
- "services": [
112
- {
113
- "serviceId": "local-tools",
114
- "name": "Local Tools",
115
- "transport": {
116
- "type": "stdio",
117
- "command": "your-mcp-service",
118
- "args": []
119
- }
120
- },
121
- {
122
- "serviceId": "remote-tools",
123
- "name": "Remote Tools",
124
- "transport": {
125
- "type": "http",
126
- "url": "http://127.0.0.1:3200/mcp"
127
- }
128
- }
129
- ]
130
- }
131
- ```
132
-
133
- | 字段 | 说明 |
134
- | --- | --- |
135
- | `services` | 下游 MCP 服务列表。 |
136
- | `serviceId` | 必填,网关工具使用的唯一服务标识。 |
137
- | `name` | 必填,服务名称。 |
138
- | `description` | 可选,服务说明。 |
139
- | `enable` | 可选,默认为 `true`。 |
140
- | `transport.type` | `stdio` 或 `http`。 |
141
- | `transport.command` | stdio 服务必填,启动命令。 |
142
- | `transport.args` | stdio 服务的可选命令参数。 |
143
- | `transport.cwd` | stdio 服务的可选工作目录。 |
144
- | `transport.env` | stdio 服务的可选环境变量。 |
145
- | `transport.url` | HTTP 服务必填,Streamable HTTP 地址。 |
146
- | `transport.headers` | HTTP 服务的可选静态请求头。 |
147
- | `logging.enable` | 是否写入文件日志,默认为 `false`。 |
148
- | `logging.path` | 日志文件路径;相对路径按配置文件目录解析。 |
149
-
150
- 网关会监听配置文件变化。配置有误时不会替换当前配置,服务继续按最后一次有效配置运行。其他示例见 [config.example.json](./config.example.json)。
151
-
152
- ### 网关工具
153
-
154
- | 工具 | 说明 |
155
- | --- | --- |
156
- | `gateway_list_services` | 列出已配置的服务及其可用状态。 |
157
- | `gateway_get_service` | 查看服务连接状态、协议版本、服务端信息和最近一次错误。 |
158
- | `gateway_list_tools` | 按名称或描述搜索服务中的工具,可同时返回 schema。 |
159
- | `gateway_get_tool_schema` | 获取准确工具名称对应的 schema。 |
160
- | `gateway_manage_service` | 重连服务,或在配置文件中启用、禁用服务。 |
161
- | `gateway_call_tool` | 调用一个下游工具并返回 MCP 结果。 |
162
-
163
- 通常按 `gateway_list_services` → `gateway_list_tools` → 按需调用 `gateway_get_tool_schema` → `gateway_call_tool` 的顺序使用。下游工具没有参数时,`gateway_call_tool` 的 `arguments` 传 `{}`。
164
-
165
- 工具调用会保留下游工具原有的副作用和确认规则。通过 `gateway_manage_service` 启用或禁用服务会修改配置文件。
166
-
167
- 支持 Skills 的 Agent 可以使用仓库内置的 [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) 完成工具发现和调用。
168
-
169
- ## 开发
170
-
171
- ```bash
172
- git clone https://github.com/jadchene/mcp-gateway.git
173
- cd mcp-gateway
174
- npm install
175
- npm run verify
176
- npm run dev -- --config ./config.json
177
- ```
178
-
179
- 构建并运行编译产物:
180
-
181
- ```bash
182
- npm run build
183
- npm start -- --config ./config.json
184
- ```
185
-
186
- ## 版权声明
187
-
188
- [MIT](./LICENSE)
1
+ [English](./README.md) | 简体中文
2
+
3
+ # MCP Gateway
4
+
5
+ ## 简介
6
+
7
+ MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent 连接网关后只会看到 6 个路由工具,具体的下游服务、工具和 schema 在需要时再查询。
8
+
9
+ 项目使用官方 TypeScript SDK v2,需要 Node.js 24 或更高版本。
10
+
11
+ > [!IMPORTANT]
12
+ > MCP Gateway v0.6.2 及后续版本仅接受 MCP `2026-07-28`、`2025-11-25` 和 `2025-06-18`。传输方式仅支持换行分隔 stdio 和单端点 Streamable HTTP。不支持独立 HTTP+SSE(`/sse`)、`Content-Length` framing 和其他协议版本。
13
+
14
+ ## 为什么使用
15
+
16
+ - 即使配置了很多 MCP 服务,也不会一次性占用大量 Agent 上下文。
17
+ - Agent 只需接入一次,后续增减下游服务只改网关配置。
18
+ - 可以按名称或描述查找工具,需要时再读取 schema。
19
+ - Stdio 和 Streamable HTTP 服务使用同一套调用方式。
20
+ - 修改配置文件后自动重载,不必重启网关。
21
+
22
+ ## 快速开始
23
+
24
+ ### 安装
25
+
26
+ ```bash
27
+ npm install -g @jadchene/mcp-gateway-service
28
+ ```
29
+
30
+ 创建 `config.json`,将 `your-mcp-service` 替换为已经安装的 MCP 服务命令:
31
+
32
+ ```json
33
+ {
34
+ "services": [
35
+ {
36
+ "serviceId": "tools",
37
+ "name": "Tools",
38
+ "transport": {
39
+ "type": "stdio",
40
+ "command": "your-mcp-service"
41
+ }
42
+ }
43
+ ]
44
+ }
45
+ ```
46
+
47
+ ### Stdio
48
+
49
+ 网关进程由 Agent 启动,不需要单独运行启动命令。
50
+
51
+ Codex `config.toml`:
52
+
53
+ ```toml
54
+ [mcp_servers.gateway]
55
+ command = "mcp-gateway-service"
56
+ args = ["--config", "./config.json"]
57
+ ```
58
+
59
+ Claude Code:
60
+
61
+ ```bash
62
+ claude mcp add gateway -- mcp-gateway-service --config ./config.json
63
+ ```
64
+
65
+ ### Streamable HTTP
66
+
67
+ 启动网关:
68
+
69
+ ```bash
70
+ mcp-gateway-service --http --config ./config.json
71
+ ```
72
+
73
+ 默认地址为 `http://127.0.0.1:3000/mcp`。
74
+ HTTP 默认隐藏 `gateway_manage_service`。监听非回环地址时,必须通过 `MCP_GATEWAY_AUTH_TOKEN` 配置 Bearer Token。
75
+
76
+ Codex `config.toml`:
77
+
78
+ ```toml
79
+ [mcp_servers.gateway]
80
+ url = "http://127.0.0.1:3000/mcp"
81
+ ```
82
+
83
+ Claude Code:
84
+
85
+ ```bash
86
+ claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
87
+ ```
88
+
89
+ ## 配置与工具
90
+
91
+ ### 启动参数
92
+
93
+ | 参数 | 说明 | 默认值 |
94
+ | --- | --- | --- |
95
+ | `--config <path>` | 配置文件路径。 | `MCP_GATEWAY_CONFIG`,其次为 `./config.json` |
96
+ | `--http` | 启用 Streamable HTTP。 | 不启用 |
97
+ | `--host <host>` | HTTP 监听地址。 | `127.0.0.1` |
98
+ | `--port <port>` | HTTP 监听端口。 | `3000` |
99
+ | `--path <path>` | HTTP endpoint 路径。 | `/mcp` |
100
+ | `--auth-token-env <名称>` | 保存 HTTP Bearer Token 的环境变量名。 | `MCP_GATEWAY_AUTH_TOKEN` |
101
+ | `--http-admin-tools` | 在已认证 HTTP 入口暴露 `gateway_manage_service`。 | 不启用 |
102
+ | `--max-concurrent-requests <数量>` | HTTP 并发请求上限。 | `64` |
103
+ | `--version`、`-v` | 输出已安装版本。 | — |
104
+
105
+ 启用 `--http` 后,stdio 入口仍然可用。
106
+
107
+ ### 配置文件
108
+
109
+ ```json
110
+ {
111
+ "logging": {
112
+ "enable": false,
113
+ "path": "./logs/mcp-gateway.log"
114
+ },
115
+ "services": [
116
+ {
117
+ "serviceId": "local-tools",
118
+ "name": "Local Tools",
119
+ "transport": {
120
+ "type": "stdio",
121
+ "command": "your-mcp-service",
122
+ "args": []
123
+ }
124
+ },
125
+ {
126
+ "serviceId": "remote-tools",
127
+ "name": "Remote Tools",
128
+ "transport": {
129
+ "type": "http",
130
+ "url": "http://127.0.0.1:3200/mcp"
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ ```
136
+
137
+ | 字段 | 说明 |
138
+ | --- | --- |
139
+ | `services` | 下游 MCP 服务列表。 |
140
+ | `serviceId` | 必填,网关工具使用的唯一服务标识。 |
141
+ | `name` | 必填,服务名称。 |
142
+ | `description` | 可选,服务说明。 |
143
+ | `enable` | 可选,默认为 `true`。 |
144
+ | `callTimeoutMs` | 可选,下游工具调用超时;默认 120 秒。 |
145
+ | `transport.type` | `stdio` 或 `http`。 |
146
+ | `transport.command` | stdio 服务必填,启动命令。 |
147
+ | `transport.args` | stdio 服务的可选命令参数。 |
148
+ | `transport.cwd` | stdio 服务的可选工作目录。 |
149
+ | `transport.env` | stdio 服务的可选环境变量。 |
150
+ | `transport.inheritEnv` | 是否继承网关完整环境;默认为 `false`。 |
151
+ | `transport.envAllowlist` | 额外传递给 stdio 服务的进程环境变量名。 |
152
+ | `transport.url` | HTTP 服务必填,Streamable HTTP 地址。 |
153
+ | `transport.headers` | HTTP 服务的可选静态请求头。 |
154
+ | `logging.enable` | 是否写入文件日志,默认为 `false`。 |
155
+ | `logging.path` | 日志文件路径;相对路径按配置文件目录解析。 |
156
+ | `logging.maxBytes` | 当前日志轮转前的大小上限;默认 10 MiB。 |
157
+
158
+ 网关会监听配置文件变化。配置有误时不会替换当前配置,服务继续按最后一次有效配置运行。其他示例见 [config.example.json](./config.example.json)。
159
+
160
+ ### 网关工具
161
+
162
+ | 工具 | 说明 |
163
+ | --- | --- |
164
+ | `gateway_list_services` | 列出已配置的服务及其可用状态。 |
165
+ | `gateway_get_service` | 查看服务连接状态、协议版本、服务端信息和最近一次错误。 |
166
+ | `gateway_list_tools` | 按名称或描述搜索服务中的工具,可同时返回 schema。 |
167
+ | `gateway_get_tool_schema` | 获取准确工具名称对应的 schema。 |
168
+ | `gateway_manage_service` | 重连服务,或在配置文件中启用、禁用服务。 |
169
+ | `gateway_call_tool` | 调用一个下游工具并返回 MCP 结果。 |
170
+
171
+ 通常按 `gateway_list_services` → `gateway_list_tools` → 按需调用 `gateway_get_tool_schema` → `gateway_call_tool` 的顺序使用。下游工具没有参数时,`gateway_call_tool` 的 `arguments` 传 `{}`。
172
+
173
+ 工具调用会保留下游工具原有的副作用和确认规则。状态不确定的 `gateway_call_tool` 失败不会自动重放。通过 `gateway_manage_service` 启用或禁用服务会原子更新配置文件。
174
+
175
+ 支持 Skills 的 Agent 可以使用仓库内置的 [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) 完成工具发现和调用。
176
+
177
+ ## 开发
178
+
179
+ ```bash
180
+ git clone https://github.com/jadchene/mcp-gateway.git
181
+ cd mcp-gateway
182
+ npm install
183
+ npm run verify
184
+ npm run dev -- --config ./config.json
185
+ ```
186
+
187
+ 构建并运行编译产物:
188
+
189
+ ```bash
190
+ npm run build
191
+ npm start -- --config ./config.json
192
+ ```
193
+
194
+ ## 版权声明
195
+
196
+ [MIT](./LICENSE)
@@ -1,35 +1,39 @@
1
- {
2
- "logging": {
3
- "enable": false,
4
- "path": "./logs/mcp-gateway.log"
5
- },
6
- "services": [
7
- {
8
- "serviceId": "demo-echo",
9
- "enable": false,
1
+ {
2
+ "logging": {
3
+ "enable": false,
4
+ "path": "./logs/mcp-gateway.log",
5
+ "maxBytes": 10485760
6
+ },
7
+ "services": [
8
+ {
9
+ "serviceId": "demo-echo",
10
+ "enable": false,
10
11
  "name": "Demo Echo Service",
11
12
  "description": "Sample echo MCP service.",
13
+ "callTimeoutMs": 120000,
12
14
  "transport": {
13
15
  "type": "stdio",
14
16
  "command": "node",
15
- "args": [
16
- "--experimental-strip-types",
17
- "examples/echo-service.ts"
18
- ]
19
- }
20
- },
21
- {
22
- "serviceId": "remote-http",
23
- "enable": false,
24
- "name": "Remote Streamable HTTP Service",
25
- "description": "Example downstream MCP service over Streamable HTTP.",
26
- "transport": {
27
- "type": "http",
28
- "url": "http://127.0.0.1:3200/mcp",
29
- "headers": {
30
- "Authorization": "Bearer example-token"
31
- }
32
- }
33
- }
34
- ]
35
- }
17
+ "args": [
18
+ "--experimental-strip-types",
19
+ "examples/echo-service.ts"
20
+ ],
21
+ "inheritEnv": false,
22
+ "envAllowlist": []
23
+ }
24
+ },
25
+ {
26
+ "serviceId": "remote-http",
27
+ "enable": false,
28
+ "name": "Remote Streamable HTTP Service",
29
+ "description": "Example downstream MCP service over Streamable HTTP.",
30
+ "transport": {
31
+ "type": "http",
32
+ "url": "http://127.0.0.1:3200/mcp",
33
+ "headers": {
34
+ "Authorization": "Bearer example-token"
35
+ }
36
+ }
37
+ }
38
+ ]
39
+ }
package/dist/config.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { dirname, resolve } from "node:path";
3
+ const DEFAULT_LOG_MAX_BYTES = 10 * 1024 * 1024;
4
+ const MAX_SERVICES = 128;
3
5
  /**
4
6
  * Provides config loading and validation for the gateway service pool definition.
5
7
  */
@@ -24,6 +26,9 @@ export function validateGatewayConfig(input, baseDir = process.cwd()) {
24
26
  if (!Array.isArray(input.services)) {
25
27
  throw new Error("The 'services' field must be an array.");
26
28
  }
29
+ if (input.services.length > MAX_SERVICES) {
30
+ throw new Error(`The 'services' field cannot contain more than ${MAX_SERVICES} entries.`);
31
+ }
27
32
  const services = input.services.map(validateServiceConfig);
28
33
  const seenServiceIds = new Set();
29
34
  for (const service of services) {
@@ -44,7 +49,8 @@ function validateLoggingConfig(input, baseDir) {
44
49
  if (input === undefined) {
45
50
  return {
46
51
  enable: false,
47
- path: null
52
+ path: null,
53
+ maxBytes: DEFAULT_LOG_MAX_BYTES
48
54
  };
49
55
  }
50
56
  if (!isRecord(input)) {
@@ -52,10 +58,13 @@ function validateLoggingConfig(input, baseDir) {
52
58
  }
53
59
  const enable = optionalBoolean(input.enable, "logging.enable") ?? false;
54
60
  const path = optionalString(input.path, "logging.path");
61
+ const maxBytes = optionalInteger(input.maxBytes, "logging.maxBytes", 1024, Number.MAX_SAFE_INTEGER)
62
+ ?? DEFAULT_LOG_MAX_BYTES;
55
63
  if (!enable) {
56
64
  return {
57
65
  enable: false,
58
- path: path ? resolve(baseDir, path) : null
66
+ path: path ? resolve(baseDir, path) : null,
67
+ maxBytes
59
68
  };
60
69
  }
61
70
  if (!path || path.trim() === "") {
@@ -63,7 +72,8 @@ function validateLoggingConfig(input, baseDir) {
63
72
  }
64
73
  return {
65
74
  enable: true,
66
- path: resolve(baseDir, path)
75
+ path: resolve(baseDir, path),
76
+ maxBytes
67
77
  };
68
78
  }
69
79
  /**
@@ -77,12 +87,14 @@ function validateServiceConfig(input) {
77
87
  const enable = optionalBoolean(input.enable, `service '${serviceId}' enable`) ?? true;
78
88
  const name = requireNonEmptyString(input.name, `service '${serviceId}' name`);
79
89
  const description = optionalString(input.description, `service '${serviceId}' description`);
90
+ const callTimeoutMs = optionalInteger(input.callTimeoutMs, `service '${serviceId}' callTimeoutMs`, 1, 24 * 60 * 60 * 1000);
80
91
  return {
81
92
  serviceId,
82
93
  enable,
83
94
  name,
84
95
  description,
85
- transport: validateTransportConfig(serviceId, input.transport)
96
+ transport: validateTransportConfig(serviceId, input.transport),
97
+ ...(callTimeoutMs === undefined ? {} : { callTimeoutMs })
86
98
  };
87
99
  }
88
100
  /**
@@ -103,6 +115,8 @@ function validateTransportConfig(serviceId, input) {
103
115
  const args = optionalStringArray(input.args, `service '${serviceId}' transport.args`);
104
116
  const cwd = optionalString(input.cwd, `service '${serviceId}' transport.cwd`);
105
117
  const env = optionalStringRecord(input.env, `service '${serviceId}' transport.env`);
118
+ const inheritEnv = optionalBoolean(input.inheritEnv, `service '${serviceId}' transport.inheritEnv`);
119
+ const envAllowlist = optionalUniqueStringArray(input.envAllowlist, `service '${serviceId}' transport.envAllowlist`);
106
120
  if (input.protocolMode !== undefined) {
107
121
  throw new Error(`Service '${serviceId}' transport.protocolMode is no longer supported; protocol negotiation is automatic.`);
108
122
  }
@@ -114,7 +128,9 @@ function validateTransportConfig(serviceId, input) {
114
128
  command,
115
129
  args,
116
130
  cwd,
117
- env
131
+ env,
132
+ ...(inheritEnv === undefined ? {} : { inheritEnv }),
133
+ ...(envAllowlist === undefined ? {} : { envAllowlist })
118
134
  };
119
135
  }
120
136
  /**
@@ -212,3 +228,29 @@ function optionalStringRecord(input, label) {
212
228
  }
213
229
  return Object.fromEntries(entries);
214
230
  }
231
+ /**
232
+ * Reads an optional bounded integer.
233
+ */
234
+ function optionalInteger(input, label, minimum, maximum) {
235
+ if (input === undefined) {
236
+ return undefined;
237
+ }
238
+ if (!Number.isInteger(input) || input < minimum || input > maximum) {
239
+ throw new Error(`The '${label}' field must be an integer from ${minimum} to ${maximum}.`);
240
+ }
241
+ return input;
242
+ }
243
+ /**
244
+ * Reads an optional unique array of non-empty strings.
245
+ */
246
+ function optionalUniqueStringArray(input, label) {
247
+ if (input === undefined) {
248
+ return undefined;
249
+ }
250
+ if (!Array.isArray(input)
251
+ || input.some((value) => typeof value !== "string" || value.trim() === "")
252
+ || new Set(input).size !== input.length) {
253
+ throw new Error(`The '${label}' field must be an array of unique non-empty strings.`);
254
+ }
255
+ return input;
256
+ }
@@ -1,5 +1,5 @@
1
1
  import { watch } from "node:fs";
2
- import { resolve } from "node:path";
2
+ import { basename, dirname, resolve } from "node:path";
3
3
  /**
4
4
  * Watches one config file and emits debounced reload callbacks.
5
5
  */
@@ -28,6 +28,7 @@ export class ConfigFileWatcher {
28
28
  * Stores the debouncing timer used to collapse rapid save bursts.
29
29
  */
30
30
  timer = null;
31
+ restartTimer = null;
31
32
  /**
32
33
  * Creates a watcher bound to one config file path.
33
34
  */
@@ -45,7 +46,10 @@ export class ConfigFileWatcher {
45
46
  return;
46
47
  }
47
48
  const absolutePath = resolve(this.configPath);
48
- this.watcher = watch(absolutePath, () => {
49
+ this.watcher = watch(dirname(absolutePath), (_event, filename) => {
50
+ if (filename && filename.toString() !== basename(absolutePath)) {
51
+ return;
52
+ }
49
53
  this.logger.info("config.file.changed", { configPath: absolutePath });
50
54
  this.scheduleReload();
51
55
  });
@@ -54,6 +58,12 @@ export class ConfigFileWatcher {
54
58
  configPath: absolutePath,
55
59
  message: error.message
56
60
  });
61
+ this.watcher?.close();
62
+ this.watcher = null;
63
+ this.restartTimer = setTimeout(() => {
64
+ this.restartTimer = null;
65
+ this.start();
66
+ }, 1_000);
57
67
  });
58
68
  }
59
69
  /**
@@ -64,6 +74,10 @@ export class ConfigFileWatcher {
64
74
  clearTimeout(this.timer);
65
75
  this.timer = null;
66
76
  }
77
+ if (this.restartTimer) {
78
+ clearTimeout(this.restartTimer);
79
+ this.restartTimer = null;
80
+ }
67
81
  this.watcher?.close();
68
82
  this.watcher = null;
69
83
  }
@@ -134,9 +134,9 @@ export class McpGatewayEngine {
134
134
  /**
135
135
  * Builds the fixed gateway tool definitions exposed to all MCP clients.
136
136
  */
137
- export function buildGatewayTools() {
137
+ export function buildGatewayTools(options = {}) {
138
138
  const outputSchemas = buildGatewayOutputSchemas();
139
- return [
139
+ const tools = [
140
140
  {
141
141
  name: "gateway_list_services",
142
142
  description: "Lists downstream MCP services with their logical identifiers, descriptions, and current availability.",
@@ -204,6 +204,9 @@ export function buildGatewayTools() {
204
204
  })
205
205
  }
206
206
  ];
207
+ return options.includeAdminTools === false
208
+ ? tools.filter((tool) => tool.name !== "gateway_manage_service")
209
+ : tools;
207
210
  }
208
211
  /**
209
212
  * Formats one service into the compact listServices result shape.