@jadchene/mcp-gateway-service 0.4.3 → 0.5.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 +246 -300
- package/README_zh.md +251 -307
- package/config.example.json +1 -1
- package/dist/gateway-engine.js +185 -58
- package/dist/service-registry.js +13 -11
- package/package.json +1 -1
- package/skills/mcp-gateway/SKILL.md +36 -18
package/README_zh.md
CHANGED
|
@@ -1,170 +1,86 @@
|
|
|
1
|
-
[English](./README.md) | 简体中文
|
|
2
|
-
|
|
3
|
-
# MCP Gateway
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
这样模型只会在需要时看到最少量的 MCP 元数据,更适合“按需发现”的使用方式。
|
|
44
|
-
|
|
45
|
-
### 2. 给多个 Agent 提供统一的 MCP 接入入口
|
|
46
|
-
|
|
47
|
-
如果没有网关,每个 Agent 往往都要分别配置多个下游 MCP 服务。
|
|
48
|
-
|
|
49
|
-
这种方式很快会带来维护问题:
|
|
50
|
-
|
|
51
|
-
- 下游服务一变,每个 Agent 配置都要改
|
|
52
|
-
- 命令路径、环境变量、工作目录会重复出现
|
|
53
|
-
- 密钥和本地路径分散在多个客户端配置里
|
|
54
|
-
- 不同 Agent 的配置很容易逐渐不一致
|
|
55
|
-
|
|
56
|
-
用了这个网关之后,下游 MCP 服务池只需要在网关配置里维护一次,多个 Agent 只需要连接这一个网关即可。
|
|
57
|
-
|
|
58
|
-
这样带来的好处是:
|
|
59
|
-
|
|
60
|
-
- 多个 MCP 统一成一个入口
|
|
61
|
-
- 下游服务的增删改集中在一个地方处理
|
|
62
|
-
- 更容易控制哪些服务对 Agent 可见
|
|
63
|
-
- 减少本地重复配置
|
|
64
|
-
- 更方便在 Codex、Claude Code、Gemini CLI 等不同客户端之间复用
|
|
65
|
-
|
|
66
|
-
简单说,这个网关的价值不只是“转发调用”,而是把多个 MCP 统一成一个可管理的服务池,同时把模型看到的工具上下文压缩到最小。
|
|
67
|
-
|
|
68
|
-
## 核心特点
|
|
69
|
-
|
|
70
|
-
### 按需发现,节省 Token
|
|
71
|
-
- 对外只暴露少量固定网关工具。
|
|
72
|
-
- 只在真正需要时查询服务工具列表和工具 schema。
|
|
73
|
-
- 避免把数百个下游 tool 在初始化阶段全部发给模型。
|
|
74
|
-
|
|
75
|
-
### 稳定的网关接口
|
|
76
|
-
- 不动态展开所有下游工具。
|
|
77
|
-
- 服务列表和工具列表返回精简结构。
|
|
78
|
-
- `gateway_call_tool` 直接透传下游工具返回结果,减少额外包装。
|
|
79
|
-
|
|
80
|
-
### 实用运维能力
|
|
81
|
-
- 从 JSON 配置文件加载静态服务池。
|
|
82
|
-
- 监听配置文件变化并自动热刷新。
|
|
83
|
-
- 热刷新时会停掉已删除、已禁用或已被替换配置对应的下游进程。
|
|
84
|
-
- 下游进程异常时最多自动重启 3 次。
|
|
85
|
-
- 配置刷新失败时保留上一版有效快照。
|
|
86
|
-
|
|
87
|
-
## 快速开始
|
|
88
|
-
|
|
89
|
-
### 全局安装
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
npm install -g @jadchene/mcp-gateway-service
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
启动网关:
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
mcp-gateway-service
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
显式指定配置文件:
|
|
1
|
+
[English](./README.md) | 简体中文
|
|
2
|
+
|
|
3
|
+
# MCP Gateway
|
|
4
|
+
|
|
5
|
+
MCP Gateway 是一个轻量级 Model Context Protocol 网关,用一个小型 MCP 入口管理多个下游 MCP 服务。
|
|
6
|
+
|
|
7
|
+
它不会在客户端启动时把所有下游工具直接展开,而是提供固定的发现和转发 API。Agent 可以先列出服务,再查看某个服务的工具,按需获取单个工具 schema,最后转发真实工具调用。
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- 用一个 MCP 入口接入多个下游 MCP 服务。
|
|
12
|
+
- 通过固定的小型网关工具面实现按需发现,减少初始 token 消耗。
|
|
13
|
+
- 支持 stdio 和 Streamable HTTP 下游传输。
|
|
14
|
+
- 可通过 CLI 参数启用入站 Streamable HTTP。
|
|
15
|
+
- 支持服务池配置热刷新。
|
|
16
|
+
- 热刷新时会停止已删除、已禁用或配置被替换的下游服务。
|
|
17
|
+
- 下游进程失败后最多自动重启 3 次,然后标记为不可用。
|
|
18
|
+
- 配置刷新是原子的,新配置无效时保留上一份有效配置。
|
|
19
|
+
- 支持可选的换行 JSON 文件日志,不把运行日志写入 MCP stdout。
|
|
20
|
+
- 支持通过 `--version` 或 `-v` 查看版本。
|
|
21
|
+
|
|
22
|
+
## 为什么使用它
|
|
23
|
+
|
|
24
|
+
- 简化 Agent 侧 MCP 配置:每个 Agent 只连接网关,下游服务统一在一个配置文件中管理。
|
|
25
|
+
- 减少初始工具上下文:Agent 只发现当前任务需要的服务、工具和 schema。
|
|
26
|
+
- 集中管理服务生命周期,避免在多个客户端中重复维护命令路径、环境变量和密钥。
|
|
27
|
+
|
|
28
|
+
## 快速开始
|
|
29
|
+
|
|
30
|
+
全局安装:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install -g @jadchene/mcp-gateway-service
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
创建本地配置:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cp config.example.json config.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
启动 stdio 网关:
|
|
102
43
|
|
|
103
44
|
```bash
|
|
104
45
|
mcp-gateway-service --config ./config.json
|
|
105
46
|
```
|
|
106
47
|
|
|
107
|
-
|
|
48
|
+
启动入站 Streamable HTTP:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
mcp-gateway-service --config ./config.json --http --host 127.0.0.1 --port 3100 --path /mcp
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
如果 HTTP 客户端希望 `POST` 直接返回 JSON-RPC 响应,可启用无状态 JSON 直返:
|
|
108
55
|
|
|
109
56
|
```bash
|
|
110
|
-
mcp-gateway-service --config ./config.json --http --port 3100 --path /mcp
|
|
57
|
+
mcp-gateway-service --config ./config.json --http --port 3100 --path /mcp --json-response
|
|
111
58
|
```
|
|
112
59
|
|
|
113
|
-
|
|
60
|
+
查看安装版本:
|
|
114
61
|
|
|
115
62
|
```bash
|
|
116
|
-
mcp-gateway-service --
|
|
63
|
+
mcp-gateway-service --version
|
|
64
|
+
mcp-gateway-service -v
|
|
117
65
|
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### 查看版本号
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
mcp-gateway-service --version
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
短参数:
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
mcp-gateway-service -v
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## 配置格式
|
|
151
|
-
|
|
152
|
-
当前支持 `stdio` 和 Streamable HTTP 类型的下游传输。网关自身的入站 Streamable HTTP 只通过 CLI 参数启用,不通过 `config.json` 启用,这样 stdio agent 可以安全共用同一份服务池配置,不会意外启动 HTTP 监听。
|
|
153
|
-
|
|
154
|
-
只有当 `enable` 未填写或显式为 `true` 时,服务才会被加载;如果 `enable` 为 `false`,网关会跳过该服务。热刷新时,如果某个服务被禁用或从配置中删除,网关也会停掉它当前已启动的下游进程。
|
|
155
|
-
|
|
156
|
-
- `logging.enable` 可选,默认是 `false`
|
|
157
|
-
- 只有当 `logging.enable` 为 `true` 时,`logging.path` 才是必填
|
|
158
|
-
- 启用后,网关会把换行分隔的 JSON 日志写入指定文件,不再把运行日志写到 MCP 的 `stdout` 或 `stderr`
|
|
159
|
-
- 相对 `logging.path` 会按配置文件所在目录解析
|
|
160
|
-
- 日志配置支持热更新,直接修改 `logging.enable` 或 `logging.path` 并保存即可生效,无需重启网关
|
|
161
|
-
- `enable` 可选,不填时默认按启用处理
|
|
162
|
-
- `cwd` 可选,不填时使用当前工作目录
|
|
163
|
-
- `env` 可选
|
|
164
|
-
- `framing` 可选,不填时先尝试 `line`,再尝试 `content-length`
|
|
165
|
-
- HTTP 下游使用 `transport.type: "http"` 和一个 `transport.url`
|
|
166
|
-
- `transport.headers` 可为 HTTP 下游提供静态请求头
|
|
167
|
-
- `transport.enableJsonResponse` 可为 HTTP 下游启用无状态 JSON 直返模式
|
|
66
|
+
|
|
67
|
+
## 配置
|
|
68
|
+
|
|
69
|
+
通过 CLI 参数指定配置文件:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
mcp-gateway-service --config ./config.json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
或通过环境变量指定:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
MCP_GATEWAY_CONFIG=./config.json mcp-gateway-service
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
如果两者都没有提供,服务会尝试读取当前工作目录下的 `config.json`。
|
|
82
|
+
|
|
83
|
+
配置示例:
|
|
168
84
|
|
|
169
85
|
```json
|
|
170
86
|
{
|
|
@@ -175,15 +91,15 @@ mcp-gateway-service -v
|
|
|
175
91
|
"services": [
|
|
176
92
|
{
|
|
177
93
|
"serviceId": "demo-echo",
|
|
178
|
-
"enable": true,
|
|
179
|
-
"name": "Demo Echo Service",
|
|
180
|
-
"description": "Sample echo MCP service.",
|
|
181
|
-
"transport": {
|
|
182
|
-
"type": "stdio",
|
|
183
|
-
"command": "node",
|
|
184
|
-
"args": [
|
|
185
|
-
"--experimental-strip-types",
|
|
186
|
-
"examples/echo-service.ts"
|
|
94
|
+
"enable": true,
|
|
95
|
+
"name": "Demo Echo Service",
|
|
96
|
+
"description": "Sample echo MCP service.",
|
|
97
|
+
"transport": {
|
|
98
|
+
"type": "stdio",
|
|
99
|
+
"command": "node",
|
|
100
|
+
"args": [
|
|
101
|
+
"--experimental-strip-types",
|
|
102
|
+
"examples/echo-service.ts"
|
|
187
103
|
]
|
|
188
104
|
}
|
|
189
105
|
},
|
|
@@ -196,7 +112,7 @@ mcp-gateway-service -v
|
|
|
196
112
|
"type": "http",
|
|
197
113
|
"url": "http://127.0.0.1:3200/mcp",
|
|
198
114
|
"headers": {
|
|
199
|
-
"Authorization": "Bearer
|
|
115
|
+
"Authorization": "Bearer ${MCP_TOKEN}"
|
|
200
116
|
},
|
|
201
117
|
"enableJsonResponse": false
|
|
202
118
|
}
|
|
@@ -205,145 +121,173 @@ mcp-gateway-service -v
|
|
|
205
121
|
}
|
|
206
122
|
```
|
|
207
123
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
- `
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
##
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
124
|
+
配置说明:
|
|
125
|
+
|
|
126
|
+
- `logging.enable` 默认为 `false`。
|
|
127
|
+
- 只有 `logging.enable` 为 `true` 时,`logging.path` 才必填。
|
|
128
|
+
- 相对 `logging.path` 会按配置文件所在目录解析。
|
|
129
|
+
- 服务 `enable` 默认为 `true`;设为 `false` 时跳过该服务。
|
|
130
|
+
- stdio 服务的 `cwd` 和 `env` 可选。
|
|
131
|
+
- stdio `transport.framing` 可为 `line` 或 `content-length`。不填写时网关先尝试 `line`,再尝试 `content-length`。
|
|
132
|
+
- HTTP 下游服务使用 `transport.type: "http"` 和 `transport.url`。
|
|
133
|
+
- HTTP `transport.headers` 用于提供静态请求头。
|
|
134
|
+
- HTTP `transport.enableJsonResponse` 为该下游服务启用无状态 JSON 直返模式。
|
|
135
|
+
|
|
136
|
+
## 入站 Streamable HTTP
|
|
137
|
+
|
|
138
|
+
入站 HTTP 只有传入 `--http` 时才会启用。只传 `--host`、`--port`、`--path` 或 `--json-response`,但不传 `--http`,不会启动 HTTP 监听。
|
|
139
|
+
|
|
140
|
+
HTTP endpoint 使用同一路径处理 `GET` 和 `POST`:
|
|
141
|
+
|
|
142
|
+
- `GET /mcp` 打开 SSE 读取通道,并通过 `Mcp-Session-Id` 响应头返回 session。
|
|
143
|
+
- `POST /mcp` 发送 JSON-RPC 消息。新客户端应通过 `Mcp-Session-Id` 请求头绑定 session。
|
|
144
|
+
- 为兼容旧客户端,仍接受 query string 中的 `sessionId`。
|
|
145
|
+
- `endpoint` SSE 事件只返回统一路径,例如 `/mcp`。
|
|
146
|
+
|
|
147
|
+
## 网关工具
|
|
148
|
+
|
|
149
|
+
网关暴露 6 个公开工具:
|
|
150
|
+
|
|
151
|
+
| 工具 | 用途 |
|
|
152
|
+
| --- | --- |
|
|
153
|
+
| `gateway_list_services` | 列出下游服务及其逻辑 `serviceId`、描述和当前可用状态。 |
|
|
154
|
+
| `gateway_get_service` | 返回服务标识、可用状态、最近错误和连接时间、协议版本及服务端信息,主要用于诊断。 |
|
|
155
|
+
| `gateway_list_tools` | 按不区分大小写的字面子串搜索工具名称或描述。可选的唯一非空 `toolName` 和 `desc` 数组使用 OR;`includeSchema: true` 会附带 schema。 |
|
|
156
|
+
| `gateway_get_tool_schema` | 按唯一、准确、区分大小写的工具名返回 schema,并以名称为 key;任一名称未知时整批失败。 |
|
|
157
|
+
| `gateway_manage_service` | 不修改配置地重连服务,或持久化启用/禁用配置并重载注册表。 |
|
|
158
|
+
| `gateway_call_tool` | 调用一个准确的下游工具并原样转发结果;下游工具可能包含读写副作用。 |
|
|
159
|
+
|
|
160
|
+
默认的节省 token 流程:
|
|
161
|
+
|
|
162
|
+
1. 调用一次 `gateway_list_services`。
|
|
163
|
+
2. 真正需要某个服务时,再调用 `gateway_list_tools(serviceId)`。用 `toolName` 数组按名称关键词筛选,或用 `desc` 数组按描述关键词筛选。
|
|
164
|
+
3. 所有筛选结果都需要 schema 时,传入 `includeSchema: true`;已知准确工具名时,调用 `gateway_get_tool_schema` 并传入非空名称数组。
|
|
165
|
+
4. 调用 `gateway_call_tool` 执行下游工具。
|
|
166
|
+
5. 只有诊断时才使用 `gateway_get_service`。
|
|
167
|
+
6. 只有需要重连、启用或禁用服务时才使用 `gateway_manage_service`。
|
|
168
|
+
|
|
169
|
+
`gateway_get_tool_schema.toolName` 必须是唯一非空字符串数组,返回的 `schemas` 对象以每个准确工具名为 key。只查询一个 schema 时使用单元素数组。
|
|
170
|
+
|
|
171
|
+
`gateway_list_tools.toolName` 和 `gateway_list_tools.desc` 都是可选的唯一非空字符串数组,按字面子串进行不区分大小写的匹配。同时传入时,只要工具名称或描述匹配任一关键词就会返回。描述匹配也可能命中 “when not to use” 等负向说明,因此选择工具前应检查完整描述。
|
|
172
|
+
|
|
173
|
+
所有具有稳定结构化结果的网关工具都声明了 `outputSchema`。`gateway_call_tool` 会转发任意下游结果,因此不声明固定输出 schema;其 `arguments` 对象始终必填,下游工具无参数时传 `{}`。
|
|
174
|
+
|
|
175
|
+
`gateway_manage_service` 动作:
|
|
176
|
+
|
|
177
|
+
- `reconnect`:不修改配置,只重试当前下游服务生命周期。
|
|
178
|
+
- `enable`:把该服务的 `enable: true` 持久化到配置文件,然后刷新配置。
|
|
179
|
+
- `disable`:把该服务的 `enable: false` 持久化到配置文件,然后刷新配置。
|
|
180
|
+
|
|
181
|
+
## Skill 集成
|
|
182
|
+
|
|
183
|
+
仓库内包含一个公开网关 skill:
|
|
184
|
+
|
|
185
|
+
- Skill 路径:`skills/mcp-gateway/SKILL.md`
|
|
186
|
+
|
|
187
|
+
当你的 Agent 支持 skills 时建议加载它。它会保持按需发现、节省 token,并通过最小网关契约转发下游调用。
|
|
188
|
+
|
|
189
|
+
## MCP 客户端配置
|
|
190
|
+
|
|
191
|
+
Codex:
|
|
192
|
+
|
|
193
|
+
```toml
|
|
194
|
+
[mcp_servers.gateway]
|
|
195
|
+
command = "mcp-gateway-service"
|
|
196
|
+
args = ["--config", "./config.json"]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Gemini CLI:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"mcpServers": {
|
|
204
|
+
"gateway": {
|
|
205
|
+
"type": "stdio",
|
|
206
|
+
"command": "mcp-gateway-service",
|
|
207
|
+
"args": ["--config", "./config.json"]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Claude Code:
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"mcpServers": {
|
|
218
|
+
"gateway": {
|
|
219
|
+
"type": "stdio",
|
|
220
|
+
"command": "mcp-gateway-service",
|
|
221
|
+
"args": ["--config", "./config.json"]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Streamable HTTP 模式:
|
|
228
|
+
|
|
229
|
+
先启动一个共享 HTTP 网关进程:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
mcp-gateway-service --config ./config.json --http --host 127.0.0.1 --port 3100 --path /mcp
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
然后让 MCP 客户端连接这个 HTTP endpoint。
|
|
236
|
+
|
|
237
|
+
Codex:
|
|
238
|
+
|
|
239
|
+
```toml
|
|
240
|
+
[mcp_servers.gateway]
|
|
241
|
+
url = "http://127.0.0.1:3100/mcp"
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Gemini CLI:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"mcpServers": {
|
|
249
|
+
"gateway": {
|
|
250
|
+
"httpUrl": "http://127.0.0.1:3100/mcp"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Claude Code:
|
|
257
|
+
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"mcpServers": {
|
|
261
|
+
"gateway": {
|
|
262
|
+
"type": "http",
|
|
263
|
+
"url": "http://127.0.0.1:3100/mcp"
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
需要共享同一个网关服务池的客户端都使用同一个 URL。只有当 HTTP 客户端希望 `POST` 直接返回无状态 JSON-RPC 响应时,才需要在启动网关时加 `--json-response`。
|
|
270
|
+
|
|
271
|
+
## 开发
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
npm install
|
|
275
|
+
npm run dev
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
构建和测试:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
npm run build
|
|
282
|
+
npm test
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
运行构建后的服务:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
node dist/index.js --config ./config.json
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## License
|
|
292
|
+
|
|
293
|
+
MIT. See [LICENSE](LICENSE).
|