@jadchene/mcp-gateway-service 0.11.3 → 0.12.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.md +71 -76
- package/README_zh.md +71 -76
- package/config.example.json +30 -17
- package/dist/config.js +9 -0
- package/dist/http-server.js +8 -1
- package/dist/index.js +41 -13
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/sdk-client.js +16 -1
- package/dist/service-registry.js +91 -4
- package/dist/version.js +0 -1
- package/dist/web-config/options.js +71 -0
- package/dist/web-config/schema.js +231 -0
- package/dist/web-config/server.js +232 -0
- package/dist/web-ui/assets/favicon-nJb-mWsM.svg +1 -0
- package/dist/web-ui/assets/index-DNU4JgNG.js +9 -0
- package/dist/web-ui/assets/index-DprXY6PS.css +1 -0
- package/dist/web-ui/index.html +14 -0
- package/package.json +74 -67
- package/scripts/verify-web-package.mjs +16 -0
package/README.md
CHANGED
|
@@ -4,65 +4,40 @@ English | [简体中文](./README_zh.md)
|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
7
|
-
MCP Gateway puts multiple MCP services behind one endpoint. An agent connects to the gateway and sees six routing tools; downstream services, tools, and schemas are looked up only when they are needed.
|
|
7
|
+
MCP Gateway puts multiple MCP services behind one endpoint. An agent connects to the gateway and sees up to six routing tools; downstream services, tools, and schemas are looked up only when they are needed.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
> [!IMPORTANT]
|
|
12
|
-
> MCP Gateway v0.6.2 and later accept only MCP `2026-07-28`, `2025-11-25`, and `2025-06-18`. Supported transports are newline-delimited stdio and single-endpoint Streamable HTTP. Standalone HTTP+SSE (`/sse`), `Content-Length` framing, and other protocol revisions are not supported.
|
|
13
|
-
|
|
14
|
-
## Why Use It
|
|
15
|
-
|
|
16
|
-
- Keep the agent context small even when many MCP services are configured.
|
|
17
|
-
- Connect the agent once, then add or remove downstream services in the gateway config.
|
|
18
|
-
- Find tools by name or description and load schemas only when required.
|
|
19
|
-
- Use stdio and Streamable HTTP services through the same interface.
|
|
20
|
-
- Require user confirmation for selected tool-name patterns, or hide and block matching tools entirely.
|
|
21
|
-
- Reload config changes without restarting the gateway.
|
|
9
|
+
Supports stdio and Streamable HTTP with MCP `2026-07-28`, `2025-11-25`, and `2025-06-18`. Legacy `/sse` endpoints are unsupported.
|
|
22
10
|
|
|
23
11
|
## Quick Start
|
|
24
12
|
|
|
25
13
|
### Install
|
|
26
14
|
|
|
15
|
+
Requires Node.js 24 or later.
|
|
16
|
+
|
|
27
17
|
```bash
|
|
28
18
|
npm install -g @jadchene/mcp-gateway-service
|
|
29
19
|
```
|
|
30
20
|
|
|
31
|
-
Create `config.json
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"services": [
|
|
36
|
-
{
|
|
37
|
-
"serviceId": "tools",
|
|
38
|
-
"name": "Tools",
|
|
39
|
-
"transport": {
|
|
40
|
-
"type": "stdio",
|
|
41
|
-
"command": "your-mcp-service"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
```
|
|
21
|
+
Create `config.json` using the [configuration example](#config-file). Replace the downstream command, arguments, and paths with those of an installed MCP server.
|
|
47
22
|
|
|
48
23
|
### Stdio
|
|
49
24
|
|
|
50
25
|
The agent starts the gateway process, so no separate startup command is needed.
|
|
51
26
|
|
|
52
|
-
Codex
|
|
27
|
+
Codex:
|
|
53
28
|
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
command = "mcp-gateway-service"
|
|
57
|
-
args = ["--config", "./config.json"]
|
|
29
|
+
```bash
|
|
30
|
+
codex mcp add gateway -- mcp-gateway-service --config /absolute/path/config.json
|
|
58
31
|
```
|
|
59
32
|
|
|
60
33
|
Claude Code:
|
|
61
34
|
|
|
62
35
|
```bash
|
|
63
|
-
claude mcp add gateway -- mcp-gateway-service --config
|
|
36
|
+
claude mcp add gateway -- mcp-gateway-service --config /absolute/path/config.json
|
|
64
37
|
```
|
|
65
38
|
|
|
39
|
+
Replace `/absolute/path/config.json` with the file you created. On Windows, a path such as `C:/mcp/gateway/config.json` works. Absolute paths avoid depending on the client's working directory.
|
|
40
|
+
|
|
66
41
|
### Streamable HTTP
|
|
67
42
|
|
|
68
43
|
Start the gateway:
|
|
@@ -74,11 +49,10 @@ mcp-gateway-service --http --config ./config.json
|
|
|
74
49
|
The default endpoint is `http://127.0.0.1:3000/mcp`.
|
|
75
50
|
HTTP hides `gateway_manage_service` by default. Non-loopback binds require a bearer token in `MCP_GATEWAY_AUTH_TOKEN`.
|
|
76
51
|
|
|
77
|
-
Codex
|
|
52
|
+
Codex:
|
|
78
53
|
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
url = "http://127.0.0.1:3000/mcp"
|
|
54
|
+
```bash
|
|
55
|
+
codex mcp add gateway --url http://127.0.0.1:3000/mcp
|
|
82
56
|
```
|
|
83
57
|
|
|
84
58
|
Claude Code:
|
|
@@ -113,58 +87,62 @@ Stdio remains available when `--http` is enabled.
|
|
|
113
87
|
{
|
|
114
88
|
"logging": {
|
|
115
89
|
"enable": false,
|
|
116
|
-
"path": "./logs/mcp-gateway.log"
|
|
90
|
+
"path": "./logs/mcp-gateway.log",
|
|
91
|
+
"maxBytes": 10485760
|
|
117
92
|
},
|
|
118
93
|
"services": [
|
|
119
94
|
{
|
|
120
95
|
"serviceId": "local-tools",
|
|
96
|
+
"enable": true,
|
|
121
97
|
"name": "Local Tools",
|
|
98
|
+
"description": "Local MCP service",
|
|
99
|
+
"callTimeoutMs": 120000,
|
|
122
100
|
"confirmationRequiredTools": ["delete_*", "deploy_?"],
|
|
123
101
|
"codexAutoReview": false,
|
|
124
102
|
"disabledTools": ["internal_*", "legacy_tool"],
|
|
125
103
|
"transport": {
|
|
126
104
|
"type": "stdio",
|
|
127
105
|
"command": "your-mcp-service",
|
|
128
|
-
"args": []
|
|
106
|
+
"args": ["--config", "/absolute/path/service/config.json"],
|
|
107
|
+
"cwd": "/absolute/path/service",
|
|
108
|
+
"env": {},
|
|
109
|
+
"inheritEnv": false,
|
|
110
|
+
"envAllowlist": []
|
|
129
111
|
}
|
|
130
112
|
},
|
|
131
113
|
{
|
|
132
114
|
"serviceId": "remote-tools",
|
|
115
|
+
"enable": false,
|
|
133
116
|
"name": "Remote Tools",
|
|
117
|
+
"description": "Remote MCP service",
|
|
118
|
+
"callTimeoutMs": 120000,
|
|
119
|
+
"confirmationRequiredTools": [],
|
|
120
|
+
"codexAutoReview": false,
|
|
121
|
+
"disabledTools": [],
|
|
134
122
|
"transport": {
|
|
135
123
|
"type": "http",
|
|
136
|
-
"url": "http://127.0.0.1:3200/mcp"
|
|
124
|
+
"url": "http://127.0.0.1:3200/mcp",
|
|
125
|
+
"headers": {
|
|
126
|
+
"Authorization": "Bearer replace-with-token"
|
|
127
|
+
}
|
|
137
128
|
}
|
|
138
129
|
}
|
|
139
130
|
]
|
|
140
131
|
}
|
|
141
132
|
```
|
|
142
133
|
|
|
143
|
-
|
|
134
|
+
Configure and enable the services you use. Remove `Authorization` for an HTTP service without token authentication.
|
|
135
|
+
|
|
136
|
+
| Setting | Usage |
|
|
144
137
|
| --- | --- |
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
| `disabledTools` | Optional unique array using the same glob syntax. Matching tools are hidden from tool listing and schema lookup, and calls are rejected before reaching the downstream service. |
|
|
154
|
-
| `transport.type` | `stdio` or `http`. |
|
|
155
|
-
| `transport.command` | Required command for a stdio service. |
|
|
156
|
-
| `transport.args` | Optional command arguments for a stdio service. |
|
|
157
|
-
| `transport.cwd` | Optional working directory for a stdio service. |
|
|
158
|
-
| `transport.env` | Optional environment variables for a stdio service. |
|
|
159
|
-
| `transport.inheritEnv` | Opts into inheriting the complete gateway environment; defaults to `false`. |
|
|
160
|
-
| `transport.envAllowlist` | Additional process environment names passed to stdio services. |
|
|
161
|
-
| `transport.url` | Required Streamable HTTP URL for an HTTP service. |
|
|
162
|
-
| `transport.headers` | Optional static headers for an HTTP service. |
|
|
163
|
-
| `logging.enable` | Enables file logging; defaults to `false`. |
|
|
164
|
-
| `logging.path` | Log file path. Relative paths use the config file directory. |
|
|
165
|
-
| `logging.maxBytes` | Active log size before rotation; defaults to 10 MiB. |
|
|
166
|
-
|
|
167
|
-
The config file is watched for changes. Invalid updates are rejected and the last valid config stays active. See [config.example.json](./config.example.json) for another example.
|
|
138
|
+
| `serviceId` | Unique identifier for each service. |
|
|
139
|
+
| `confirmationRequiredTools` | Case-sensitive full tool-name patterns: `*` matches any number of characters, `?` matches one. Matching calls require confirmation. |
|
|
140
|
+
| `disabledTools` | Uses the same patterns to hide and block tools; takes precedence over confirmation rules. |
|
|
141
|
+
| `transport.cwd`, `transport.args` | Prefer absolute paths. Relative working directories resolve from the gateway process directory. |
|
|
142
|
+
| `transport.env`, `transport.envAllowlist` | Supply variable values or allow named variables through. Custom variables are not inherited unless allowed; `inheritEnv: true` inherits the full environment. Config strings do not expand `${VAR}`. |
|
|
143
|
+
| `logging.path`, `logging.maxBytes` | Log paths resolve from the config directory; logs rotate at the configured size. |
|
|
144
|
+
|
|
145
|
+
Configuration reloads automatically; invalid updates keep the last valid configuration. The complete example is also available in [config.example.json](config.example.json).
|
|
168
146
|
|
|
169
147
|
### Gateway Tools
|
|
170
148
|
|
|
@@ -179,11 +157,9 @@ The config file is watched for changes. Invalid updates are rejected and the las
|
|
|
179
157
|
|
|
180
158
|
The usual flow is `gateway_list_services` → `gateway_list_tools` → `gateway_get_tool_schema` when needed → `gateway_call_tool`. Pass `{}` to `gateway_call_tool` when the downstream tool has no arguments.
|
|
181
159
|
|
|
182
|
-
|
|
160
|
+
Confirmations show the service, tool, and arguments and require a client with interactive confirmation support. Calls with uncertain outcomes are not retried automatically.
|
|
183
161
|
|
|
184
|
-
Codex automatic
|
|
185
|
-
|
|
186
|
-
`disabledTools` takes precedence over `confirmationRequiredTools` when both match. A disabled tool is hidden and rejected immediately without asking for confirmation.
|
|
162
|
+
For Codex automatic review, set `"codexAutoReview": true` in the selected `services[]` block and start Codex with `codex -c approvals_reviewer=auto_review`. This applies to gateway confirmations; configure downstream services' own approvals separately. Otherwise, use Accept / Decline / Cancel. Codex policy determines whether an operation is approved.
|
|
187
163
|
|
|
188
164
|
Agents with Skills support can use the included [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) for the discovery and calling workflow.
|
|
189
165
|
|
|
@@ -194,16 +170,35 @@ git clone https://github.com/jadchene/mcp-gateway.git
|
|
|
194
170
|
cd mcp-gateway
|
|
195
171
|
npm install
|
|
196
172
|
npm run verify
|
|
197
|
-
npm run dev -- --config ./config.json
|
|
198
173
|
```
|
|
199
174
|
|
|
200
|
-
|
|
175
|
+
Create `config.json` as shown above, then start the development service:
|
|
201
176
|
|
|
202
177
|
```bash
|
|
203
|
-
npm run
|
|
204
|
-
npm start -- --config ./config.json
|
|
178
|
+
npm run dev -- --config ./config.json
|
|
205
179
|
```
|
|
206
180
|
|
|
181
|
+
`npm run verify` builds the service. Run the compiled output with `npm start -- --config ./config.json`.
|
|
182
|
+
|
|
183
|
+
## Web configuration
|
|
184
|
+
|
|
185
|
+
Disabled by default. Web binds only to `127.0.0.1`, needs no token, and uses a separate port from MCP communication.
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
mcp-gateway-service --config ./config.json --web --web-port 3100
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Open the printed URL. Alternatively, add `"web": { "enabled": true, "port": 3100 }` to your existing configuration.
|
|
192
|
+
|
|
193
|
+
- CLI overrides the file: `--web` enables, `--no-web` disables; with neither, `web.enabled` applies and defaults to false. A port alone does not enable Web.
|
|
194
|
+
- Click Save configuration to write the original file and reload it. External edits trigger a conflict; reload failures are reported separately.
|
|
195
|
+
- Runtime information shows listener settings and the configuration file location. Web enablement and port are read-only in the UI; change the file or startup arguments and restart.
|
|
196
|
+
- Web stops with the process. If Web fails to start, a warning is logged and MCP continues running. Change the port and restart to resolve a port conflict.
|
|
197
|
+
|
|
198
|
+
Set a downstream service’s `webUrl` to open its configuration page in a new tab after saving. Gateway does not start or proxy that page.
|
|
199
|
+
|
|
200
|
+
The **Service status** page shows connection state and starts, stops, or restarts stdio services without changing their enabled setting. HTTP services support connect, disconnect, and reconnect only. Stopped services stay stopped through configuration reloads; restarting Gateway loads enabled services again.
|
|
201
|
+
|
|
207
202
|
## License
|
|
208
203
|
|
|
209
|
-
[MIT](./LICENSE)
|
|
204
|
+
[MIT](./LICENSE)
|
package/README_zh.md
CHANGED
|
@@ -4,65 +4,40 @@
|
|
|
4
4
|
|
|
5
5
|
## 简介
|
|
6
6
|
|
|
7
|
-
MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent
|
|
7
|
+
MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent 连接网关后最多只会看到 6 个路由工具,具体的下游服务、工具和 schema 在需要时再查询。
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
- 修改配置文件后自动重载,不必重启网关。
|
|
9
|
+
支持 stdio 和 Streamable HTTP,兼容 MCP `2026-07-28`、`2025-11-25` 和 `2025-06-18`;不支持旧式 `/sse` 入口。
|
|
22
10
|
|
|
23
11
|
## 快速开始
|
|
24
12
|
|
|
25
13
|
### 安装
|
|
26
14
|
|
|
15
|
+
需要 Node.js 24 或更高版本。
|
|
16
|
+
|
|
27
17
|
```bash
|
|
28
18
|
npm install -g @jadchene/mcp-gateway-service
|
|
29
19
|
```
|
|
30
20
|
|
|
31
|
-
创建 `config.json
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"services": [
|
|
36
|
-
{
|
|
37
|
-
"serviceId": "tools",
|
|
38
|
-
"name": "Tools",
|
|
39
|
-
"transport": {
|
|
40
|
-
"type": "stdio",
|
|
41
|
-
"command": "your-mcp-service"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
```
|
|
21
|
+
按照[配置文件示例](#配置文件)创建 `config.json`,将下游命令、参数和路径替换为已经安装的 MCP 服务配置。
|
|
47
22
|
|
|
48
23
|
### Stdio
|
|
49
24
|
|
|
50
25
|
网关进程由 Agent 启动,不需要单独运行启动命令。
|
|
51
26
|
|
|
52
|
-
Codex
|
|
27
|
+
Codex:
|
|
53
28
|
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
command = "mcp-gateway-service"
|
|
57
|
-
args = ["--config", "./config.json"]
|
|
29
|
+
```bash
|
|
30
|
+
codex mcp add gateway -- mcp-gateway-service --config /absolute/path/config.json
|
|
58
31
|
```
|
|
59
32
|
|
|
60
33
|
Claude Code:
|
|
61
34
|
|
|
62
35
|
```bash
|
|
63
|
-
claude mcp add gateway -- mcp-gateway-service --config
|
|
36
|
+
claude mcp add gateway -- mcp-gateway-service --config /absolute/path/config.json
|
|
64
37
|
```
|
|
65
38
|
|
|
39
|
+
请将 `/absolute/path/config.json` 替换为刚创建的配置文件路径。Windows 可使用 `C:/mcp/gateway/config.json` 这样的写法。使用绝对路径可避免依赖客户端的工作目录。
|
|
40
|
+
|
|
66
41
|
### Streamable HTTP
|
|
67
42
|
|
|
68
43
|
启动网关:
|
|
@@ -74,11 +49,10 @@ mcp-gateway-service --http --config ./config.json
|
|
|
74
49
|
默认地址为 `http://127.0.0.1:3000/mcp`。
|
|
75
50
|
HTTP 默认隐藏 `gateway_manage_service`。监听非回环地址时,必须通过 `MCP_GATEWAY_AUTH_TOKEN` 配置 Bearer Token。
|
|
76
51
|
|
|
77
|
-
Codex
|
|
52
|
+
Codex:
|
|
78
53
|
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
url = "http://127.0.0.1:3000/mcp"
|
|
54
|
+
```bash
|
|
55
|
+
codex mcp add gateway --url http://127.0.0.1:3000/mcp
|
|
82
56
|
```
|
|
83
57
|
|
|
84
58
|
Claude Code:
|
|
@@ -113,58 +87,62 @@ claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
|
|
|
113
87
|
{
|
|
114
88
|
"logging": {
|
|
115
89
|
"enable": false,
|
|
116
|
-
"path": "./logs/mcp-gateway.log"
|
|
90
|
+
"path": "./logs/mcp-gateway.log",
|
|
91
|
+
"maxBytes": 10485760
|
|
117
92
|
},
|
|
118
93
|
"services": [
|
|
119
94
|
{
|
|
120
95
|
"serviceId": "local-tools",
|
|
96
|
+
"enable": true,
|
|
121
97
|
"name": "Local Tools",
|
|
98
|
+
"description": "Local MCP service",
|
|
99
|
+
"callTimeoutMs": 120000,
|
|
122
100
|
"confirmationRequiredTools": ["delete_*", "deploy_?"],
|
|
123
101
|
"codexAutoReview": false,
|
|
124
102
|
"disabledTools": ["internal_*", "legacy_tool"],
|
|
125
103
|
"transport": {
|
|
126
104
|
"type": "stdio",
|
|
127
105
|
"command": "your-mcp-service",
|
|
128
|
-
"args": []
|
|
106
|
+
"args": ["--config", "/absolute/path/service/config.json"],
|
|
107
|
+
"cwd": "/absolute/path/service",
|
|
108
|
+
"env": {},
|
|
109
|
+
"inheritEnv": false,
|
|
110
|
+
"envAllowlist": []
|
|
129
111
|
}
|
|
130
112
|
},
|
|
131
113
|
{
|
|
132
114
|
"serviceId": "remote-tools",
|
|
115
|
+
"enable": false,
|
|
133
116
|
"name": "Remote Tools",
|
|
117
|
+
"description": "Remote MCP service",
|
|
118
|
+
"callTimeoutMs": 120000,
|
|
119
|
+
"confirmationRequiredTools": [],
|
|
120
|
+
"codexAutoReview": false,
|
|
121
|
+
"disabledTools": [],
|
|
134
122
|
"transport": {
|
|
135
123
|
"type": "http",
|
|
136
|
-
"url": "http://127.0.0.1:3200/mcp"
|
|
124
|
+
"url": "http://127.0.0.1:3200/mcp",
|
|
125
|
+
"headers": {
|
|
126
|
+
"Authorization": "Bearer replace-with-token"
|
|
127
|
+
}
|
|
137
128
|
}
|
|
138
129
|
}
|
|
139
130
|
]
|
|
140
131
|
}
|
|
141
132
|
```
|
|
142
133
|
|
|
143
|
-
|
|
134
|
+
按需配置并启用使用的服务;HTTP 服务无需 Token 认证时,删除 `Authorization`。
|
|
135
|
+
|
|
136
|
+
| 配置 | 使用说明 |
|
|
144
137
|
| --- | --- |
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
| `disabledTools` | 可选,使用相同 glob 语法。匹配的工具不会出现在工具列表和 schema 查询中,调用也会在到达下游服务前被拒绝。 |
|
|
154
|
-
| `transport.type` | `stdio` 或 `http`。 |
|
|
155
|
-
| `transport.command` | stdio 服务必填,启动命令。 |
|
|
156
|
-
| `transport.args` | stdio 服务的可选命令参数。 |
|
|
157
|
-
| `transport.cwd` | stdio 服务的可选工作目录。 |
|
|
158
|
-
| `transport.env` | stdio 服务的可选环境变量。 |
|
|
159
|
-
| `transport.inheritEnv` | 是否继承网关完整环境;默认为 `false`。 |
|
|
160
|
-
| `transport.envAllowlist` | 额外传递给 stdio 服务的进程环境变量名。 |
|
|
161
|
-
| `transport.url` | HTTP 服务必填,Streamable HTTP 地址。 |
|
|
162
|
-
| `transport.headers` | HTTP 服务的可选静态请求头。 |
|
|
163
|
-
| `logging.enable` | 是否写入文件日志,默认为 `false`。 |
|
|
164
|
-
| `logging.path` | 日志文件路径;相对路径按配置文件目录解析。 |
|
|
165
|
-
| `logging.maxBytes` | 当前日志轮转前的大小上限;默认 10 MiB。 |
|
|
166
|
-
|
|
167
|
-
网关会监听配置文件变化。配置有误时不会替换当前配置,服务继续按最后一次有效配置运行。其他示例见 [config.example.json](./config.example.json)。
|
|
138
|
+
| `serviceId` | 每个服务的唯一标识。 |
|
|
139
|
+
| `confirmationRequiredTools` | 完整工具名的匹配规则,区分大小写;`*` 匹配任意数量字符,`?` 匹配一个字符。匹配的调用须确认后执行。 |
|
|
140
|
+
| `disabledTools` | 使用相同匹配规则,隐藏并禁止调用匹配工具,优先于确认规则。 |
|
|
141
|
+
| `transport.cwd`、`transport.args` | 建议使用绝对路径;相对工作目录以网关进程目录为基准。 |
|
|
142
|
+
| `transport.env`、`transport.envAllowlist` | 分别提供环境变量值或允许传递的变量名。默认不继承自定义变量;`inheritEnv: true` 才继承完整环境。配置字符串不展开 `${VAR}`。 |
|
|
143
|
+
| `logging.path`、`logging.maxBytes` | 日志路径以配置目录为基准,达到大小上限时轮转。 |
|
|
144
|
+
|
|
145
|
+
配置会自动重载,无效更新保留上一份有效配置。完整示例也可直接复制 [config.example.json](config.example.json)。
|
|
168
146
|
|
|
169
147
|
### 网关工具
|
|
170
148
|
|
|
@@ -179,11 +157,9 @@ claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
|
|
|
179
157
|
|
|
180
158
|
通常按 `gateway_list_services` → `gateway_list_tools` → 按需调用 `gateway_get_tool_schema` → `gateway_call_tool` 的顺序使用。下游工具没有参数时,`gateway_call_tool` 的 `arguments` 传 `{}`。
|
|
181
159
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Codex 自动审批扩展默认禁用;在指定服务的 `services[]` 配置块中显式设置 `"codexAutoReview": true`,仅为 `confirmationRequiredTools` 触发的网关自定义确认添加审批元数据。下游确认表单及其 `_meta` 原样透传,下游自动审批配置独立生效。Codex 开启 `approvals_reviewer = "auto_review"` 时自动审查,否则使用正常的 Accept / Decline / Cancel 确认;审批结果仍由 Codex 策略决定。
|
|
160
|
+
确认界面会展示服务、工具和参数,客户端须支持交互确认。执行结果不确定时不会自动重试。
|
|
185
161
|
|
|
186
|
-
|
|
162
|
+
需要 Codex 自动审查时,在指定服务的 `services[]` 配置块中设置 `"codexAutoReview": true`,并通过 `codex -c approvals_reviewer=auto_review` 启动 Codex。该设置作用于网关确认,下游服务自己的审批需独立配置。其他情况使用 Accept / Decline / Cancel 确认,是否批准仍由 Codex 策略决定。
|
|
187
163
|
|
|
188
164
|
支持 Skills 的 Agent 可以使用仓库内置的 [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) 完成工具发现和调用。
|
|
189
165
|
|
|
@@ -194,16 +170,35 @@ git clone https://github.com/jadchene/mcp-gateway.git
|
|
|
194
170
|
cd mcp-gateway
|
|
195
171
|
npm install
|
|
196
172
|
npm run verify
|
|
197
|
-
npm run dev -- --config ./config.json
|
|
198
173
|
```
|
|
199
174
|
|
|
200
|
-
|
|
175
|
+
按上文创建 `config.json` 后,启动开发服务:
|
|
201
176
|
|
|
202
177
|
```bash
|
|
203
|
-
npm run
|
|
204
|
-
npm start -- --config ./config.json
|
|
178
|
+
npm run dev -- --config ./config.json
|
|
205
179
|
```
|
|
206
180
|
|
|
181
|
+
`npm run verify` 会构建服务;之后可用 `npm start -- --config ./config.json` 运行编译产物。
|
|
182
|
+
|
|
207
183
|
## 版权声明
|
|
208
184
|
|
|
209
|
-
[MIT](./LICENSE)
|
|
185
|
+
[MIT](./LICENSE)
|
|
186
|
+
|
|
187
|
+
## Web 配置页面
|
|
188
|
+
|
|
189
|
+
默认关闭,固定监听本机 `127.0.0.1`,无需令牌。使用独立端口,不影响 MCP 通信。
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
mcp-gateway-service --config ./config.json --web --web-port 3100
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
打开终端显示的地址即可配置。也可在现有配置文件中添加 `"web": { "enabled": true, "port": 3100 }`。
|
|
196
|
+
|
|
197
|
+
- 命令行优先于文件。`--web` 开启、`--no-web` 关闭;都不传时读取 `web.enabled`,未配置则关闭。仅指定端口不会开启 Web。
|
|
198
|
+
- 表单修改点击“保存配置”后写入原文件并热加载;检测到外部修改时提示冲突。加载失败会单独提示。
|
|
199
|
+
- “运行信息”可查看监听配置和文件位置。Web 开关、端口需修改文件或启动参数并重启,页面内只读。
|
|
200
|
+
- Web 随进程退出。Web 启动失败会输出警告,MCP 继续运行;端口冲突时可修改端口后重启。
|
|
201
|
+
|
|
202
|
+
“服务状态”页可查看下游状态,并启动、停止、重启 stdio 服务,不修改启用配置。HTTP 服务仅支持连接、断开和重连。手动停止后,配置刷新不会拉起服务;重启 Gateway 后按启用配置加载。
|
|
203
|
+
|
|
204
|
+
下游服务可填写 `webUrl`,保存后点击“打开配置页面”在新标签页访问。Gateway 不启动或代理下游页面。
|
package/config.example.json
CHANGED
|
@@ -6,42 +6,55 @@
|
|
|
6
6
|
},
|
|
7
7
|
"services": [
|
|
8
8
|
{
|
|
9
|
-
"serviceId": "
|
|
10
|
-
"enable":
|
|
11
|
-
"name": "
|
|
12
|
-
"description": "
|
|
9
|
+
"serviceId": "local-tools",
|
|
10
|
+
"enable": true,
|
|
11
|
+
"name": "Local Tools",
|
|
12
|
+
"description": "Local MCP service",
|
|
13
13
|
"callTimeoutMs": 120000,
|
|
14
14
|
"confirmationRequiredTools": [
|
|
15
|
-
"
|
|
15
|
+
"delete_*",
|
|
16
|
+
"deploy_?"
|
|
16
17
|
],
|
|
18
|
+
"codexAutoReview": false,
|
|
17
19
|
"disabledTools": [
|
|
18
|
-
"
|
|
20
|
+
"internal_*",
|
|
21
|
+
"legacy_tool"
|
|
19
22
|
],
|
|
20
23
|
"transport": {
|
|
21
24
|
"type": "stdio",
|
|
22
|
-
"command": "
|
|
25
|
+
"command": "your-mcp-service",
|
|
23
26
|
"args": [
|
|
24
|
-
"--
|
|
25
|
-
"
|
|
27
|
+
"--config",
|
|
28
|
+
"/absolute/path/service/config.json"
|
|
26
29
|
],
|
|
30
|
+
"cwd": "/absolute/path/service",
|
|
31
|
+
"env": {},
|
|
27
32
|
"inheritEnv": false,
|
|
28
33
|
"envAllowlist": []
|
|
29
34
|
},
|
|
30
|
-
"
|
|
35
|
+
"webUrl": "http://127.0.0.1:3101"
|
|
31
36
|
},
|
|
32
37
|
{
|
|
33
|
-
"serviceId": "remote-
|
|
38
|
+
"serviceId": "remote-tools",
|
|
34
39
|
"enable": false,
|
|
35
|
-
"name": "Remote
|
|
36
|
-
"description": "
|
|
40
|
+
"name": "Remote Tools",
|
|
41
|
+
"description": "Remote MCP service",
|
|
42
|
+
"callTimeoutMs": 120000,
|
|
43
|
+
"confirmationRequiredTools": [],
|
|
44
|
+
"codexAutoReview": false,
|
|
45
|
+
"disabledTools": [],
|
|
37
46
|
"transport": {
|
|
38
47
|
"type": "http",
|
|
39
48
|
"url": "http://127.0.0.1:3200/mcp",
|
|
40
49
|
"headers": {
|
|
41
|
-
"Authorization": "Bearer
|
|
50
|
+
"Authorization": "Bearer replace-with-token"
|
|
42
51
|
}
|
|
43
|
-
}
|
|
44
|
-
"codexAutoReview": false
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
|
-
]
|
|
54
|
+
],
|
|
55
|
+
"web": {
|
|
56
|
+
"enabled": false,
|
|
57
|
+
"host": "127.0.0.1",
|
|
58
|
+
"port": 3100
|
|
59
|
+
}
|
|
47
60
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateWebConfig } from "./web-config/options.js";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { dirname, resolve } from "node:path";
|
|
3
4
|
const DEFAULT_LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
@@ -29,6 +30,7 @@ export function validateGatewayConfig(input, baseDir = process.cwd()) {
|
|
|
29
30
|
if (input.services.length > MAX_SERVICES) {
|
|
30
31
|
throw new Error(`The 'services' field cannot contain more than ${MAX_SERVICES} entries.`);
|
|
31
32
|
}
|
|
33
|
+
validateWebConfig(input.web);
|
|
32
34
|
const services = input.services.map(validateServiceConfig);
|
|
33
35
|
const seenServiceIds = new Set();
|
|
34
36
|
for (const service of services) {
|
|
@@ -87,12 +89,19 @@ function validateServiceConfig(input) {
|
|
|
87
89
|
const enable = optionalBoolean(input.enable, `service '${serviceId}' enable`) ?? true;
|
|
88
90
|
const codexAutoReview = optionalBoolean(input.codexAutoReview, `service '${serviceId}' codexAutoReview`) ?? false;
|
|
89
91
|
const name = requireNonEmptyString(input.name, `service '${serviceId}' name`);
|
|
92
|
+
const webUrl = optionalString(input.webUrl, `service ${serviceId} webUrl`);
|
|
93
|
+
if (webUrl) {
|
|
94
|
+
const parsed = new URL(webUrl);
|
|
95
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
96
|
+
throw new Error("webUrl must be an HTTP(S) URL without credentials");
|
|
97
|
+
}
|
|
90
98
|
const description = optionalString(input.description, `service '${serviceId}' description`);
|
|
91
99
|
const callTimeoutMs = optionalInteger(input.callTimeoutMs, `service '${serviceId}' callTimeoutMs`, 1, 24 * 60 * 60 * 1000);
|
|
92
100
|
const confirmationRequiredTools = optionalUniqueStringArray(input.confirmationRequiredTools, `service '${serviceId}' confirmationRequiredTools`);
|
|
93
101
|
const disabledTools = optionalUniqueStringArray(input.disabledTools, `service '${serviceId}' disabledTools`);
|
|
94
102
|
return {
|
|
95
103
|
serviceId,
|
|
104
|
+
...(webUrl === undefined ? {} : { webUrl }),
|
|
96
105
|
enable,
|
|
97
106
|
codexAutoReview,
|
|
98
107
|
name,
|
package/dist/http-server.js
CHANGED
|
@@ -70,7 +70,14 @@ export class StreamableHttpGatewayServer {
|
|
|
70
70
|
const maxRequestBodyBytes = this.config.maxRequestBodyBytes ?? DEFAULT_MAX_REQUEST_BODY_BYTES;
|
|
71
71
|
let activeRequests = 0;
|
|
72
72
|
this.server = http.createServer((request, response) => {
|
|
73
|
-
|
|
73
|
+
let pathname;
|
|
74
|
+
try {
|
|
75
|
+
pathname = new URL(request.url ?? "/", "http://localhost").pathname;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
response.writeHead(400).end();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
74
81
|
if (pathname !== this.config.path) {
|
|
75
82
|
response.writeHead(404).end();
|
|
76
83
|
return;
|