@jadchene/mcp-gateway-service 0.2.0 → 0.2.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 +8 -14
- package/README_zh.md +8 -14
- package/dist/gateway-server.js +1 -1
- package/dist/index.js +10 -0
- package/dist/mcp/client.js +69 -12
- package/package.json +1 -1
- package/scripts/install-global.ps1 +4 -4
- package/skills/mcp-gateway/SKILL.md +7 -1
package/README.md
CHANGED
|
@@ -38,14 +38,7 @@ That means the model only sees the minimum amount of MCP metadata needed for the
|
|
|
38
38
|
|
|
39
39
|
### 2. Provide one unified MCP entry point for multiple agents
|
|
40
40
|
|
|
41
|
-
Without a gateway, each agent usually needs its own MCP client configuration for
|
|
42
|
-
|
|
43
|
-
- database MCP
|
|
44
|
-
- SSH MCP
|
|
45
|
-
- IDE MCP
|
|
46
|
-
- Playwright MCP
|
|
47
|
-
- Gitea MCP
|
|
48
|
-
- and more
|
|
41
|
+
Without a gateway, each agent usually needs its own MCP client configuration for multiple downstream services.
|
|
49
42
|
|
|
50
43
|
That quickly becomes hard to maintain:
|
|
51
44
|
|
|
@@ -263,12 +256,13 @@ args = ["--config", "./config.json"]
|
|
|
263
256
|
|
|
264
257
|
## Development Notes
|
|
265
258
|
|
|
266
|
-
- Repository-managed `config.json` and `config.example.json` are examples only.
|
|
267
|
-
- Copy `config.example.json` to your own local `config.json` before running the gateway.
|
|
268
|
-
- Keep real local configs and logs outside the repository.
|
|
269
|
-
- Downstream output schema is returned only when the downstream service exposes it.
|
|
270
|
-
- Windows command resolution supports PowerShell shims such as `.ps1`-backed command aliases.
|
|
259
|
+
- Repository-managed `config.json` and `config.example.json` are examples only.
|
|
260
|
+
- Copy `config.example.json` to your own local `config.json` before running the gateway.
|
|
261
|
+
- Keep real local configs and logs outside the repository.
|
|
262
|
+
- Downstream output schema is returned only when the downstream service exposes it.
|
|
263
|
+
- Windows command resolution supports PowerShell shims such as `.ps1`-backed command aliases.
|
|
264
|
+
- On Windows, the gateway prefers `pwsh` for `.ps1` shim resolution and execution, and automatically falls back to `powershell.exe` when `pwsh` is unavailable.
|
|
271
265
|
|
|
272
266
|
## License
|
|
273
267
|
|
|
274
|
-
Released under the [MIT License](./LICENSE).
|
|
268
|
+
Released under the [MIT License](./LICENSE).
|
package/README_zh.md
CHANGED
|
@@ -44,14 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
### 2. 给多个 Agent 提供统一的 MCP 接入入口
|
|
46
46
|
|
|
47
|
-
如果没有网关,每个 Agent
|
|
48
|
-
|
|
49
|
-
- database MCP
|
|
50
|
-
- SSH MCP
|
|
51
|
-
- IDE MCP
|
|
52
|
-
- Playwright MCP
|
|
53
|
-
- Gitea MCP
|
|
54
|
-
- 以及其他服务
|
|
47
|
+
如果没有网关,每个 Agent 往往都要分别配置多个下游 MCP 服务。
|
|
55
48
|
|
|
56
49
|
这种方式很快会带来维护问题:
|
|
57
50
|
|
|
@@ -265,12 +258,13 @@ args = ["--config", "./config.json"]
|
|
|
265
258
|
|
|
266
259
|
## 开发说明
|
|
267
260
|
|
|
268
|
-
- 仓库只保留 `config.example.json` 作为示例
|
|
269
|
-
- 运行前请自行复制一份本地 `config.json`
|
|
270
|
-
- 真实本地配置和日志建议放在仓库外
|
|
271
|
-
- 只有下游服务自己暴露了 `outputSchema` 时,网关才会返回它
|
|
272
|
-
- Windows 下支持解析 PowerShell shim 命令,例如实际落到 `.ps1` 的全局命令
|
|
261
|
+
- 仓库只保留 `config.example.json` 作为示例
|
|
262
|
+
- 运行前请自行复制一份本地 `config.json`
|
|
263
|
+
- 真实本地配置和日志建议放在仓库外
|
|
264
|
+
- 只有下游服务自己暴露了 `outputSchema` 时,网关才会返回它
|
|
265
|
+
- Windows 下支持解析 PowerShell shim 命令,例如实际落到 `.ps1` 的全局命令
|
|
266
|
+
- 在 Windows 上,网关会优先使用 `pwsh` 解析和执行 `.ps1` shim;如果机器上没有 `pwsh`,会自动回退到 `powershell.exe`
|
|
273
267
|
|
|
274
268
|
## License
|
|
275
269
|
|
|
276
|
-
项目采用 [MIT License](./LICENSE) 开源。
|
|
270
|
+
项目采用 [MIT License](./LICENSE) 开源。
|
package/dist/gateway-server.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -33,6 +33,10 @@ class Application {
|
|
|
33
33
|
watcher = new ConfigFileWatcher(this.configPath, this.logger, async () => {
|
|
34
34
|
await this.registry.reload();
|
|
35
35
|
});
|
|
36
|
+
/**
|
|
37
|
+
* Prevents duplicate shutdown execution when multiple exit signals arrive.
|
|
38
|
+
*/
|
|
39
|
+
shuttingDown = false;
|
|
36
40
|
/**
|
|
37
41
|
* Starts the application and registers shutdown hooks.
|
|
38
42
|
*/
|
|
@@ -55,6 +59,10 @@ class Application {
|
|
|
55
59
|
*/
|
|
56
60
|
registerSignals() {
|
|
57
61
|
const shutdown = async (signal) => {
|
|
62
|
+
if (this.shuttingDown) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.shuttingDown = true;
|
|
58
66
|
this.logger.info("gateway.stopping", { signal });
|
|
59
67
|
this.watcher.stop();
|
|
60
68
|
await this.registry.dispose();
|
|
@@ -62,6 +70,8 @@ class Application {
|
|
|
62
70
|
};
|
|
63
71
|
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
64
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"));
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
const application = new Application();
|
package/dist/mcp/client.js
CHANGED
|
@@ -295,14 +295,7 @@ export class StdioMcpClient {
|
|
|
295
295
|
const child = this.child;
|
|
296
296
|
this.child = null;
|
|
297
297
|
this.writer = null;
|
|
298
|
-
|
|
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.2.
|
|
313
|
+
version: "0.2.2"
|
|
321
314
|
}
|
|
322
315
|
});
|
|
323
316
|
if (isRecord(result)) {
|
|
@@ -448,8 +441,12 @@ function resolveCommandSpec(command, args) {
|
|
|
448
441
|
const powershellResolved = resolveViaPowerShell(command);
|
|
449
442
|
if (powershellResolved) {
|
|
450
443
|
if (powershellResolved.toLowerCase().endsWith(".ps1")) {
|
|
444
|
+
const powerShellHost = resolvePowerShellHost();
|
|
445
|
+
if (!powerShellHost) {
|
|
446
|
+
return { command, args };
|
|
447
|
+
}
|
|
451
448
|
return {
|
|
452
|
-
command:
|
|
449
|
+
command: powerShellHost,
|
|
453
450
|
args: ["-File", powershellResolved, ...args]
|
|
454
451
|
};
|
|
455
452
|
}
|
|
@@ -472,8 +469,12 @@ function resolveCommandSpec(command, args) {
|
|
|
472
469
|
return { command, args };
|
|
473
470
|
}
|
|
474
471
|
if (preferred.toLowerCase().endsWith(".ps1")) {
|
|
472
|
+
const powerShellHost = resolvePowerShellHost();
|
|
473
|
+
if (!powerShellHost) {
|
|
474
|
+
return { command, args };
|
|
475
|
+
}
|
|
475
476
|
return {
|
|
476
|
-
command:
|
|
477
|
+
command: powerShellHost,
|
|
477
478
|
args: ["-File", preferred, ...args]
|
|
478
479
|
};
|
|
479
480
|
}
|
|
@@ -490,8 +491,12 @@ function resolveCommandSpec(command, args) {
|
|
|
490
491
|
* Resolves a command name through PowerShell so script shims map to their real targets.
|
|
491
492
|
*/
|
|
492
493
|
function resolveViaPowerShell(command) {
|
|
494
|
+
const powerShellHost = resolvePowerShellHost();
|
|
495
|
+
if (!powerShellHost) {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
493
498
|
try {
|
|
494
|
-
const output = execFileSync(
|
|
499
|
+
const output = execFileSync(powerShellHost, [
|
|
495
500
|
"-NoProfile",
|
|
496
501
|
"-Command",
|
|
497
502
|
`(Get-Command '${escapePowerShellSingleQuotedString(command)}' -ErrorAction Stop).Source`
|
|
@@ -506,12 +511,64 @@ function resolveViaPowerShell(command) {
|
|
|
506
511
|
return null;
|
|
507
512
|
}
|
|
508
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Resolves the preferred PowerShell host on Windows.
|
|
516
|
+
*/
|
|
517
|
+
export function resolvePowerShellHost(probe = commandExists) {
|
|
518
|
+
if (probe("pwsh")) {
|
|
519
|
+
return "pwsh";
|
|
520
|
+
}
|
|
521
|
+
if (probe("powershell.exe")) {
|
|
522
|
+
return "powershell.exe";
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
509
526
|
/**
|
|
510
527
|
* Escapes a string for use inside a single-quoted PowerShell literal.
|
|
511
528
|
*/
|
|
512
529
|
function escapePowerShellSingleQuotedString(value) {
|
|
513
530
|
return value.replace(/'/g, "''");
|
|
514
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Checks whether a command exists in the current PATH.
|
|
534
|
+
*/
|
|
535
|
+
function commandExists(command) {
|
|
536
|
+
try {
|
|
537
|
+
execFileSync("where.exe", [command], {
|
|
538
|
+
stdio: ["ignore", "ignore", "ignore"]
|
|
539
|
+
});
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
catch {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Terminates one child process, using process-tree shutdown on Windows when possible.
|
|
548
|
+
*/
|
|
549
|
+
function terminateChildProcess(child) {
|
|
550
|
+
if (process.platform === "win32" && child.pid) {
|
|
551
|
+
try {
|
|
552
|
+
execFileSync("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], {
|
|
553
|
+
stdio: ["ignore", "ignore", "ignore"]
|
|
554
|
+
});
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
/**
|
|
559
|
+
* Falls back to normal child termination when taskkill fails.
|
|
560
|
+
*/
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
child.kill();
|
|
565
|
+
}
|
|
566
|
+
catch {
|
|
567
|
+
/**
|
|
568
|
+
* Ignores kill failures because the process may have already exited.
|
|
569
|
+
*/
|
|
570
|
+
}
|
|
571
|
+
}
|
|
515
572
|
/**
|
|
516
573
|
* Waits for one child process to exit and force-kills it if graceful shutdown stalls.
|
|
517
574
|
*/
|
package/package.json
CHANGED
|
@@ -100,10 +100,10 @@ $example = @{
|
|
|
100
100
|
mcpServers = @{
|
|
101
101
|
gateway = @{
|
|
102
102
|
command = "mcp-gateway-service"
|
|
103
|
-
args = @(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
args = @(
|
|
104
|
+
"--config",
|
|
105
|
+
$resolvedConfigPath
|
|
106
|
+
)
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
} | ConvertTo-Json -Depth 6
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: mcp-gateway
|
|
3
|
-
description: Use the MCP gateway for token-efficient discovery of downstream MCP services, tool lists, tool schemas, and forwarded tool calls. Prefer
|
|
3
|
+
description: Use the MCP gateway for token-efficient discovery of downstream MCP services, tool lists, tool schemas, and forwarded tool calls. Prefer the default four-tool workflow and use detailed service inspection only for explicit diagnosis.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# MCP Gateway
|
|
@@ -23,6 +23,12 @@ Operate downstream MCP services through the gateway's fixed, token-efficient dis
|
|
|
23
23
|
4. Call `gateway.callTool(serviceId, toolName, arguments)` for execution.
|
|
24
24
|
5. Re-discover only when a call fails, service availability changes, or the task clearly requires fresh metadata.
|
|
25
25
|
|
|
26
|
+
## Diagnostic Exception
|
|
27
|
+
|
|
28
|
+
- Treat `gateway.getService` as a diagnostic tool, not part of the default workflow.
|
|
29
|
+
- Use it only when the user explicitly asks to inspect service health, connection state, protocol details, or recent service errors.
|
|
30
|
+
- Do not call it during normal task execution when the four-tool flow is sufficient.
|
|
31
|
+
|
|
26
32
|
## Response Shape Expectations
|
|
27
33
|
|
|
28
34
|
- `gateway.listServices` returns compact service entries with `serviceId`, `description`, and `available`.
|